@@ -69,7 +69,6 @@ describe('mergeBaggageHeaders', () => {
6969 expect ( entries ) . toContain ( 'third=party' ) ;
7070 expect ( entries ) . toContain ( 'sentry-environment=myEnv' ) ;
7171 expect ( entries ) . toContain ( 'sentry-release=2.1.0' ) ;
72- expect ( entries ) . toContain ( 'sentry-sample_rate=0.54' ) ;
7372 expect ( entries ) . not . toContain ( 'sentry-environment=staging' ) ;
7473 expect ( entries ) . not . toContain ( 'sentry-release=9.9.9' ) ;
7574 } ) ;
@@ -133,8 +132,7 @@ describe('mergeBaggageHeaders', () => {
133132 const existing = 'custom-key=value' ;
134133 const newBaggage = 'sentry-environment=production' ;
135134 const result = mergeBaggageHeaders ( existing , newBaggage ) ;
136- expect ( result ) . toContain ( 'custom-key=value' ) ;
137- expect ( result ) . toContain ( 'sentry-environment=production' ) ;
135+ expect ( result ) . toBe ( 'custom-key=value,sentry-environment=production' ) ;
138136 } ) ;
139137
140138 it ( 'overwrites existing Sentry entries when keys conflict' , ( ) => {
@@ -153,4 +151,11 @@ describe('mergeBaggageHeaders', () => {
153151 expect ( result ) . toContain ( 'sentry-trace_id=123' ) ;
154152 expect ( result ) . not . toContain ( 'sentry-environment=staging' ) ;
155153 } ) ;
154+
155+ it ( 'removes all sentry- values from old baggage and only adds new ones (if at least one new sentry- value is present)' , ( ) => {
156+ const existing = 'sentry-trace_id=old,sentry-sampled=false,non-sentry=keep' ;
157+ const newBaggage = 'sentry-trace_id=new,sentry-environment=new' ;
158+ const result = mergeBaggageHeaders ( existing , newBaggage ) ;
159+ expect ( result ) . toBe ( 'non-sentry=keep,sentry-trace_id=new,sentry-environment=new' ) ;
160+ } ) ;
156161} ) ;
0 commit comments