@@ -82,7 +82,7 @@ private static async Task<string> StartSpan(HttpRequest request)
82
82
83
83
var creationSettings = new SpanCreationSettings
84
84
{
85
- Parent = FindSpanContext ( requestJson , "parent_id" , required : false ) ,
85
+ Parent = FindSpanContext ( requestJson , "parent_id" , required : false ) ?? SpanContext . None ,
86
86
FinishOnClose = false ,
87
87
} ;
88
88
@@ -341,33 +341,28 @@ private static ISpan FindSpan(JsonElement json, string key = "span_id")
341
341
342
342
private static ISpanContext ? FindSpanContext ( JsonElement json , string key = "span_id" , bool required = true )
343
343
{
344
- var spanIdString = json . GetPropertyAsString ( key ) ;
345
-
346
- if ( ! ulong . TryParse ( spanIdString , out var spanId ) )
344
+ if ( json . GetPropertyAsUInt64 ( key ) is { } spanId )
347
345
{
348
- if ( required )
346
+ if ( Spans . TryGetValue ( spanId , out var span ) )
349
347
{
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 ;
352
349
}
353
350
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
+ }
361
355
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
+ }
365
361
}
366
-
367
- if ( required )
362
+ else if ( required )
368
363
{
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. ") ;
371
366
}
372
367
373
368
return null ;
0 commit comments