@@ -112,53 +112,46 @@ public static Baggage fromHeader(
112112 @ Nullable Double sampleRand = null ;
113113
114114 if (headerValue != null ) {
115- try {
116- // see https://errorprone.info/bugpattern/StringSplitter for why limit is passed
117- final String [] keyValueStrings = headerValue .split ("," , -1 );
118- for (final String keyValueString : keyValueStrings ) {
119- if (keyValueString .trim ().startsWith (SENTRY_BAGGAGE_PREFIX )) {
120- try {
121- // As per spec (https://www.w3.org/TR/baggage/#value)
122- // a value may contain "=" signs, thus we split by the first occurrence
123- final int separatorIndex = keyValueString .indexOf ("=" );
124- final String key = keyValueString .substring (0 , separatorIndex ).trim ();
125- final String keyDecoded = decode (key );
126- final String value = keyValueString .substring (separatorIndex + 1 ).trim ();
127- final String valueDecoded = decode (value );
128-
129- if (DSCKeys .SAMPLE_RATE .equals (keyDecoded )) {
130- sampleRate = toDouble (valueDecoded );
131- } else if (DSCKeys .SAMPLE_RAND .equals (keyDecoded )) {
132- sampleRand = toDouble (valueDecoded );
133- } else {
134- keyValues .put (keyDecoded , valueDecoded );
135- }
136- // Without ignoring SAMPLE_RAND here, we'd be freezing baggage that we're transporting
137- // via OTel span attributes.
138- // This is done when a transaction is created via Sentry API.
139- // In that case Baggage is created before the OTel span is created and we put it on
140- // the span attributes.
141- // It does however only contain the sample random value as its only value.
142- // The OTel code then uses it to create a propagation context from it and ends up
143- // freezing it,
144- // preventing outgoing requests (to other systems or Sentry) from adding info to
145- // baggage and only then freeze it.
146- if (!DSCKeys .SAMPLE_RAND .equalsIgnoreCase (key )) {
147- shouldFreeze = true ;
148- }
149- } catch (Throwable e ) {
150- logger .log (
151- SentryLevel .ERROR ,
152- e ,
153- "Unable to decode baggage key value pair %s" ,
154- keyValueString );
115+ // see https://errorprone.info/bugpattern/StringSplitter for why limit is passed
116+ final String [] keyValueStrings = headerValue .split ("," , -1 );
117+ for (final String keyValueString : keyValueStrings ) {
118+ if (keyValueString .trim ().startsWith (SENTRY_BAGGAGE_PREFIX )) {
119+ try {
120+ // As per spec (https://www.w3.org/TR/baggage/#value)
121+ // a value may contain "=" signs, thus we split by the first occurrence
122+ final int separatorIndex = keyValueString .indexOf ("=" );
123+ final String key = keyValueString .substring (0 , separatorIndex ).trim ();
124+ final String keyDecoded = decode (key );
125+ final String value = keyValueString .substring (separatorIndex + 1 ).trim ();
126+ final String valueDecoded = decode (value );
127+
128+ if (DSCKeys .SAMPLE_RATE .equals (keyDecoded )) {
129+ sampleRate = toDouble (valueDecoded );
130+ } else if (DSCKeys .SAMPLE_RAND .equals (keyDecoded )) {
131+ sampleRand = toDouble (valueDecoded );
132+ } else {
133+ keyValues .put (keyDecoded , valueDecoded );
134+ }
135+ // Without ignoring SAMPLE_RAND here, we'd be freezing baggage that we're transporting
136+ // via OTel span attributes.
137+ // This is done when a transaction is created via Sentry API.
138+ // In that case Baggage is created before the OTel span is created and we put it on
139+ // the span attributes.
140+ // It does however only contain the sample random value as its only value.
141+ // The OTel code then uses it to create a propagation context from it and ends up
142+ // freezing it,
143+ // preventing outgoing requests (to other systems or Sentry) from adding info to
144+ // baggage and only then freeze it.
145+ if (!DSCKeys .SAMPLE_RAND .equalsIgnoreCase (key )) {
146+ shouldFreeze = true ;
155147 }
156- } else if (includeThirdPartyValues ) {
157- thirdPartyKeyValueStrings .add (keyValueString .trim ());
148+ } catch (Throwable e ) {
149+ logger .log (
150+ SentryLevel .ERROR , e , "Unable to decode baggage key value pair %s" , keyValueString );
158151 }
152+ } else if (includeThirdPartyValues ) {
153+ thirdPartyKeyValueStrings .add (keyValueString .trim ());
159154 }
160- } catch (Throwable e ) {
161- logger .log (SentryLevel .ERROR , e , "Unable to decode baggage header %s" , headerValue );
162155 }
163156 }
164157 final String thirdPartyHeader =
0 commit comments