11import { getCurrentHub , Hub } from '@sentry/hub' ;
22import { Options , TraceparentData , Transaction } from '@sentry/types' ;
3- import { SentryError , unicodeToBase64 } from '@sentry/utils' ;
3+ import { dropUndefinedKeys , SentryError , unicodeToBase64 } from '@sentry/utils' ;
44
55export const SENTRY_TRACE_REGEX = new RegExp (
66 '^[ \\t]*' + // whitespace
@@ -146,10 +146,10 @@ export { stripUrlQueryAndFragment } from '@sentry/utils';
146146
147147type SentryTracestateData = {
148148 trace_id : string ;
149- environment : string | undefined | null ;
150- release : string | undefined | null ;
149+ environment ? : string ;
150+ release ? : string ;
151151 public_key : string ;
152- user : { id : string | undefined | null ; segment : string | undefined | null } ;
152+ user ? : { id ? : string ; segment ? : string } ;
153153} ;
154154
155155/**
@@ -161,10 +161,6 @@ type SentryTracestateData = {
161161export function computeTracestateValue ( data : SentryTracestateData ) : string {
162162 // `JSON.stringify` will drop keys with undefined values, but not ones with null values, so this prevents
163163 // these values from being dropped if they haven't been set by `Sentry.init`
164- data . environment = data . environment || null ;
165- data . release = data . release || null ;
166- data . user . id = data . user . id || null ;
167- data . user . segment = data . user . segment || null ;
168164
169165 // See https://www.w3.org/TR/trace-context/#tracestate-header-field-values
170166 // The spec for tracestate header values calls for a string of the form
@@ -175,7 +171,7 @@ export function computeTracestateValue(data: SentryTracestateData): string {
175171 // used to pad the end of base64 values though, so to avoid confusion, we strip them off. (Most languages' base64
176172 // decoding functions (including those in JS) are able to function without the padding.)
177173 try {
178- return unicodeToBase64 ( JSON . stringify ( data ) ) . replace ( / = { 1 , 2 } $ / , '' ) ;
174+ return unicodeToBase64 ( JSON . stringify ( dropUndefinedKeys ( data ) ) ) . replace ( / = { 1 , 2 } $ / , '' ) ;
179175 } catch ( err ) {
180176 throw new SentryError ( `[Tracing] Error computing tracestate value from data: ${ err } \nData: ${ data } ` ) ;
181177 }
0 commit comments