Skip to content

Commit

Permalink
[json type] parent_id is a number in /trace/span/start
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Dec 19, 2024
1 parent 39141a9 commit 223303e
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static async Task<string> StartSpan(HttpRequest request)

var creationSettings = new SpanCreationSettings
{
Parent = FindSpanContext(requestJson, "parent_id", required: false),
Parent = FindSpanContext(requestJson, "parent_id", required: false) ?? SpanContext.None,
FinishOnClose = false,
};

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

private static ISpanContext? FindSpanContext(JsonElement json, string key = "span_id", bool required = true)
{
var spanIdString = json.GetPropertyAsString(key);

if (!ulong.TryParse(spanIdString, out var spanId))
if (json.GetPropertyAsUInt64(key) is { } spanId)
{
if (required)
if (Spans.TryGetValue(spanId, out var span))
{
_logger?.LogError("Required {key}:{value} not valid in request json.", key, spanIdString);
throw new InvalidOperationException($"Required {key}:{spanIdString} not valid in request json.");
return span.Context;
}

return null;
}

if (Spans.TryGetValue(spanId, out var span))
{
return span.Context;
}
if (SpanContexts.TryGetValue(spanId, out var spanContext))
{
return spanContext;
}

if (SpanContexts.TryGetValue(spanId, out var spanContext))
{
return spanContext;
if (required)
{
_logger?.LogError("Span or SpanContext not found with span id: {spanId}.", spanId);
throw new InvalidOperationException($"Span or SpanContext not found with span id: {spanId}");
}
}

if (required)
else if (required)
{
_logger?.LogError("Span or SpanContext not found with span id: {spanId}.", spanIdString);
throw new InvalidOperationException($"Span or SpanContext not found with span id: {spanId}");
_logger?.LogError("Required {key} not found or not a valid UInt64 in request json.", key);
throw new InvalidOperationException($"Required {key} not found or not a valid UInt64 in request json.");
}

return null;
Expand Down

0 comments on commit 223303e

Please sign in to comment.