Skip to content

Commit 223303e

Browse files
committed
[json type] parent_id is a number in /trace/span/start
1 parent 39141a9 commit 223303e

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs

+16-21
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private static async Task<string> StartSpan(HttpRequest request)
8282

8383
var creationSettings = new SpanCreationSettings
8484
{
85-
Parent = FindSpanContext(requestJson, "parent_id", required: false),
85+
Parent = FindSpanContext(requestJson, "parent_id", required: false) ?? SpanContext.None,
8686
FinishOnClose = false,
8787
};
8888

@@ -341,33 +341,28 @@ private static ISpan FindSpan(JsonElement json, string key = "span_id")
341341

342342
private static ISpanContext? FindSpanContext(JsonElement json, string key = "span_id", bool required = true)
343343
{
344-
var spanIdString = json.GetPropertyAsString(key);
345-
346-
if (!ulong.TryParse(spanIdString, out var spanId))
344+
if (json.GetPropertyAsUInt64(key) is { } spanId)
347345
{
348-
if (required)
346+
if (Spans.TryGetValue(spanId, out var span))
349347
{
350-
_logger?.LogError("Required {key}:{value} not valid in request json.", key, spanIdString);
351-
throw new InvalidOperationException($"Required {key}:{spanIdString} not valid in request json.");
348+
return span.Context;
352349
}
353350

354-
return null;
355-
}
356-
357-
if (Spans.TryGetValue(spanId, out var span))
358-
{
359-
return span.Context;
360-
}
351+
if (SpanContexts.TryGetValue(spanId, out var spanContext))
352+
{
353+
return spanContext;
354+
}
361355

362-
if (SpanContexts.TryGetValue(spanId, out var spanContext))
363-
{
364-
return spanContext;
356+
if (required)
357+
{
358+
_logger?.LogError("Span or SpanContext not found with span id: {spanId}.", spanId);
359+
throw new InvalidOperationException($"Span or SpanContext not found with span id: {spanId}");
360+
}
365361
}
366-
367-
if (required)
362+
else if (required)
368363
{
369-
_logger?.LogError("Span or SpanContext not found with span id: {spanId}.", spanIdString);
370-
throw new InvalidOperationException($"Span or SpanContext not found with span id: {spanId}");
364+
_logger?.LogError("Required {key} not found or not a valid UInt64 in request json.", key);
365+
throw new InvalidOperationException($"Required {key} not found or not a valid UInt64 in request json.");
371366
}
372367

373368
return null;

0 commit comments

Comments
 (0)