@@ -36,7 +36,7 @@ public W3CTraceHeader(SentryTraceHeader source)
3636 /// </value>
3737 public SentryTraceHeader SentryTraceHeader { get ; }
3838
39- /// <summary>
39+ /// <summary>
4040 /// Parses a <see cref="SentryTraceHeader"/> from a string representation of the Sentry trace header.
4141 /// </summary>
4242 /// <param name="value">
@@ -57,7 +57,7 @@ public W3CTraceHeader(SentryTraceHeader source)
5757 }
5858
5959 var components = value . Split ( '-' , StringSplitOptions . RemoveEmptyEntries ) ;
60- if ( components . Length < 2 )
60+ if ( components . Length < 4 )
6161 {
6262 throw new FormatException ( $ "Invalid W3C trace header: { value } .") ;
6363 }
@@ -71,9 +71,7 @@ public W3CTraceHeader(SentryTraceHeader source)
7171 var traceId = SentryId . Parse ( components [ 1 ] ) ;
7272 var spanId = SpanId . Parse ( components [ 2 ] ) ;
7373
74- var isSampled = components . Length >= 4
75- ? string . Equals ( components [ 3 ] , "01" , StringComparison . OrdinalIgnoreCase )
76- : ( bool ? ) null ;
74+ var isSampled = string . Equals ( components [ 3 ] , "01" , StringComparison . OrdinalIgnoreCase ) ;
7775
7876 return new W3CTraceHeader ( new SentryTraceHeader ( traceId , spanId , isSampled ) ) ;
7977 }
@@ -82,11 +80,6 @@ public W3CTraceHeader(SentryTraceHeader source)
8280 public override string ToString ( )
8381 {
8482 var traceFlags = ConvertSampledToTraceFlags ( SentryTraceHeader . IsSampled ) ;
85- if ( traceFlags is null )
86- {
87- return $ "{ SupportedVersion } -{ SentryTraceHeader . TraceId } -{ SentryTraceHeader . SpanId } ";
88- }
89-
9083 return $ "{ SupportedVersion } -{ SentryTraceHeader . TraceId } -{ SentryTraceHeader . SpanId } -{ traceFlags } ";
9184 }
9285
@@ -104,13 +97,5 @@ public override bool Equals(object? obj)
10497 /// <inheritdoc/>
10598 public override int GetHashCode ( ) => SentryTraceHeader . GetHashCode ( ) ;
10699
107- private static string ? ConvertSampledToTraceFlags ( bool ? isSampled )
108- {
109- return isSampled switch
110- {
111- true => "01" ,
112- false => "00" ,
113- null => null
114- } ;
115- }
100+ private static string ? ConvertSampledToTraceFlags ( bool ? isSampled ) => isSampled ?? false ? "01" : "00" ;
116101}
0 commit comments