Skip to content

Commit df74f42

Browse files
committed
rename mutability helper functions
1 parent 3bb6554 commit df74f42

File tree

15 files changed

+81
-77
lines changed

15 files changed

+81
-77
lines changed

packages/nextjs/src/utils/instrumentServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
fill,
1414
isString,
1515
logger,
16-
parseAndFreezeBaggageIfNecessary,
16+
parseBaggageSetMutability,
1717
stripUrlQueryAndFragment,
1818
} from '@sentry/utils';
1919
import * as domain from 'domain';
@@ -256,7 +256,7 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
256256
}
257257

258258
const rawBaggageString = nextReq.headers && isString(nextReq.headers.baggage) && nextReq.headers.baggage;
259-
const baggage = parseAndFreezeBaggageIfNecessary(rawBaggageString, traceparentData);
259+
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
260260

261261
// pull off query string, if any
262262
const reqPath = stripUrlQueryAndFragment(nextReq.url);

packages/nextjs/src/utils/withSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
isString,
77
logger,
88
objectify,
9-
parseAndFreezeBaggageIfNecessary,
9+
parseBaggageSetMutability,
1010
stripUrlQueryAndFragment,
1111
} from '@sentry/utils';
1212
import * as domain from 'domain';
@@ -52,7 +52,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
5252
}
5353

5454
const rawBaggageString = req.headers && isString(req.headers.baggage) && req.headers.baggage;
55-
const baggage = parseAndFreezeBaggageIfNecessary(rawBaggageString, traceparentData);
55+
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
5656

5757
const url = `${req.url}`;
5858
// pull off query string, if any

packages/node/src/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
extractTraceparentData,
1212
isString,
1313
logger,
14-
parseAndFreezeBaggageIfNecessary,
14+
parseBaggageSetMutability,
1515
} from '@sentry/utils';
1616
import * as domain from 'domain';
1717
import * as http from 'http';
@@ -38,7 +38,7 @@ export function tracingHandler(): (
3838
req.headers && isString(req.headers['sentry-trace']) && extractTraceparentData(req.headers['sentry-trace']);
3939
const rawBaggageString = req.headers && isString(req.headers.baggage) && req.headers.baggage;
4040

41-
const baggage = parseAndFreezeBaggageIfNecessary(rawBaggageString, traceparentData);
41+
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
4242

4343
const transaction = startTransaction(
4444
{

packages/node/test/handlers.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as sentryHub from '@sentry/hub';
33
import { Hub } from '@sentry/hub';
44
import { Transaction } from '@sentry/tracing';
55
import { Baggage, Event } from '@sentry/types';
6-
import { isBaggageEmpty, isBaggageFrozen, SentryError } from '@sentry/utils';
6+
import { isBaggageEmpty, isBaggageMutable, SentryError } from '@sentry/utils';
77
import * as http from 'http';
88

99
import { NodeClient } from '../src/client';
@@ -194,7 +194,7 @@ describe('tracingHandler', () => {
194194
expect(transaction.sampled).toEqual(false);
195195
expect(transaction.metadata?.baggage).toBeDefined();
196196
expect(isBaggageEmpty(transaction.metadata?.baggage)).toBeTruthy();
197-
expect(isBaggageFrozen(transaction.metadata?.baggage)).toBeTruthy();
197+
expect(isBaggageMutable(transaction.metadata?.baggage)).toBeFalsy();
198198
});
199199

200200
it("pulls parent's data from tracing and baggage headers on the request", () => {
@@ -212,7 +212,11 @@ describe('tracingHandler', () => {
212212
expect(transaction.parentSpanId).toEqual('1121201211212012');
213213
expect(transaction.sampled).toEqual(false);
214214
expect(transaction.metadata?.baggage).toBeDefined();
215-
expect(transaction.metadata?.baggage).toEqual([{ version: '1.0', environment: 'production' }, '', true] as Baggage);
215+
expect(transaction.metadata?.baggage).toEqual([
216+
{ version: '1.0', environment: 'production' },
217+
'',
218+
false,
219+
] as Baggage);
216220
});
217221

218222
it("pulls parent's baggage (sentry + third party entries) headers on the request", () => {
@@ -228,7 +232,7 @@ describe('tracingHandler', () => {
228232
expect(transaction.metadata?.baggage).toEqual([
229233
{ version: '1.0', environment: 'production' },
230234
'dogs=great,cats=boring',
231-
true,
235+
false,
232236
] as Baggage);
233237
});
234238

packages/serverless/src/awslambda.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@sentry/node';
1212
import { extractTraceparentData } from '@sentry/tracing';
1313
import { Integration } from '@sentry/types';
14-
import { extensionRelayDSN, isString, logger, parseAndFreezeBaggageIfNecessary } from '@sentry/utils';
14+
import { extensionRelayDSN, isString, logger, parseBaggageSetMutability } from '@sentry/utils';
1515
// NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil
1616
// eslint-disable-next-line import/no-unresolved
1717
import { Context, Handler } from 'aws-lambda';
@@ -285,7 +285,7 @@ export function wrapHandler<TEvent, TResult>(
285285

286286
const rawBaggageString =
287287
eventWithHeaders.headers && isString(eventWithHeaders.headers.baggage) && eventWithHeaders.headers.baggage;
288-
const baggage = parseAndFreezeBaggageIfNecessary(rawBaggageString, traceparentData);
288+
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
289289

290290
const transaction = startTransaction({
291291
name: context.functionName,

packages/serverless/src/gcpfunction/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
startTransaction,
88
} from '@sentry/node';
99
import { extractTraceparentData } from '@sentry/tracing';
10-
import { isString, logger, parseAndFreezeBaggageIfNecessary, stripUrlQueryAndFragment } from '@sentry/utils';
10+
import { isString, logger, parseBaggageSetMutability, stripUrlQueryAndFragment } from '@sentry/utils';
1111

1212
import { domainify, getActiveDomain, proxyFunction } from './../utils';
1313
import { HttpFunction, WrapperOptions } from './general';
@@ -75,7 +75,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
7575
const rawBaggageString =
7676
reqWithHeaders.headers && isString(reqWithHeaders.headers.baggage) && reqWithHeaders.headers.baggage;
7777

78-
const baggage = parseAndFreezeBaggageIfNecessary(rawBaggageString, traceparentData);
78+
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
7979

8080
const transaction = startTransaction({
8181
name: `${reqMethod} ${reqUrl}`,

packages/serverless/test/awslambda.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('AWSLambda', () => {
190190
expect(Sentry.startTransaction).toBeCalledWith({
191191
name: 'functionName',
192192
op: 'awslambda.handler',
193-
metadata: { baggage: [{}, '', false] },
193+
metadata: { baggage: [{}, '', true] },
194194
});
195195
expectScopeSettings();
196196
// @ts-ignore see "Why @ts-ignore" note
@@ -213,7 +213,7 @@ describe('AWSLambda', () => {
213213
expect(Sentry.startTransaction).toBeCalledWith({
214214
name: 'functionName',
215215
op: 'awslambda.handler',
216-
metadata: { baggage: [{}, '', false] },
216+
metadata: { baggage: [{}, '', true] },
217217
});
218218
expectScopeSettings();
219219
expect(Sentry.captureException).toBeCalledWith(error);
@@ -257,7 +257,7 @@ describe('AWSLambda', () => {
257257
release: '2.12.1',
258258
},
259259
'maisey=silly,charlie=goofy',
260-
true,
260+
false,
261261
],
262262
},
263263
}),
@@ -289,7 +289,7 @@ describe('AWSLambda', () => {
289289
traceId: '12312012123120121231201212312012',
290290
parentSpanId: '1121201211212012',
291291
parentSampled: false,
292-
metadata: { baggage: [{}, '', true] },
292+
metadata: { baggage: [{}, '', false] },
293293
});
294294
expectScopeSettings();
295295
expect(Sentry.captureException).toBeCalledWith(e);
@@ -313,7 +313,7 @@ describe('AWSLambda', () => {
313313
expect(Sentry.startTransaction).toBeCalledWith({
314314
name: 'functionName',
315315
op: 'awslambda.handler',
316-
metadata: { baggage: [{}, '', false] },
316+
metadata: { baggage: [{}, '', true] },
317317
});
318318
expectScopeSettings();
319319
// @ts-ignore see "Why @ts-ignore" note
@@ -347,7 +347,7 @@ describe('AWSLambda', () => {
347347
expect(Sentry.startTransaction).toBeCalledWith({
348348
name: 'functionName',
349349
op: 'awslambda.handler',
350-
metadata: { baggage: [{}, '', false] },
350+
metadata: { baggage: [{}, '', true] },
351351
});
352352
expectScopeSettings();
353353
expect(Sentry.captureException).toBeCalledWith(error);
@@ -386,7 +386,7 @@ describe('AWSLambda', () => {
386386
expect(Sentry.startTransaction).toBeCalledWith({
387387
name: 'functionName',
388388
op: 'awslambda.handler',
389-
metadata: { baggage: [{}, '', false] },
389+
metadata: { baggage: [{}, '', true] },
390390
});
391391
expectScopeSettings();
392392
// @ts-ignore see "Why @ts-ignore" note
@@ -420,7 +420,7 @@ describe('AWSLambda', () => {
420420
expect(Sentry.startTransaction).toBeCalledWith({
421421
name: 'functionName',
422422
op: 'awslambda.handler',
423-
metadata: { baggage: [{}, '', false] },
423+
metadata: { baggage: [{}, '', true] },
424424
});
425425
expectScopeSettings();
426426
expect(Sentry.captureException).toBeCalledWith(error);

packages/serverless/test/gcpfunction.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('GCPFunction', () => {
113113
expect(Sentry.startTransaction).toBeCalledWith({
114114
name: 'POST /path',
115115
op: 'gcp.function.http',
116-
metadata: { baggage: [{}, '', false] },
116+
metadata: { baggage: [{}, '', true] },
117117
});
118118
// @ts-ignore see "Why @ts-ignore" note
119119
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
@@ -151,7 +151,7 @@ describe('GCPFunction', () => {
151151
release: '2.12.1',
152152
},
153153
'maisey=silly,charlie=goofy',
154-
true,
154+
false,
155155
],
156156
},
157157
}),
@@ -178,7 +178,7 @@ describe('GCPFunction', () => {
178178
traceId: '12312012123120121231201212312012',
179179
parentSpanId: '1121201211212012',
180180
parentSampled: false,
181-
metadata: { baggage: [{}, '', true] },
181+
metadata: { baggage: [{}, '', false] },
182182
});
183183
// @ts-ignore see "Why @ts-ignore" note
184184
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);

packages/tracing/src/browser/browsertracing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Hub } from '@sentry/hub';
22
import { EventProcessor, Integration, Transaction, TransactionContext } from '@sentry/types';
3-
import { getGlobalObject, logger, parseAndFreezeBaggageIfNecessary } from '@sentry/utils';
3+
import { getGlobalObject, logger, parseBaggageSetMutability } from '@sentry/utils';
44

55
import { startIdleTransaction } from '../hubextensions';
66
import { DEFAULT_FINAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT } from '../idletransaction';
@@ -255,7 +255,7 @@ export function extractTraceDataFromMetaTags(): Partial<TransactionContext> | un
255255
const baggageValue = getMetaContent('baggage');
256256

257257
const sentrytraceData = sentrytraceValue ? extractTraceparentData(sentrytraceValue) : undefined;
258-
const baggage = parseAndFreezeBaggageIfNecessary(baggageValue, sentrytraceValue);
258+
const baggage = parseBaggageSetMutability(baggageValue, sentrytraceValue);
259259

260260
// TODO more extensive checks for baggage validity/emptyness?
261261
if (sentrytraceData || baggage) {

packages/tracing/src/span.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { Baggage, Hub, Primitive, Span as SpanInterface, SpanContext, Transactio
44
import {
55
createBaggage,
66
dropUndefinedKeys,
7-
freezeBaggage,
87
isBaggageEmpty,
9-
isBaggageFrozen,
8+
isBaggageMutable,
109
isSentryBaggageEmpty,
10+
setBaggageImmutable,
1111
setBaggageValue,
1212
timestampWithMs,
1313
uuid4,
@@ -316,9 +316,9 @@ export class Span implements SpanInterface {
316316
const existingBaggage = this.transaction && this.transaction.metadata.baggage;
317317

318318
// Only add Sentry baggage items to baggage, if baggage does not exist yet or it is still
319-
// empty and not yet set immutable
319+
// empty and mutable
320320
const finalBaggage =
321-
!existingBaggage || (!isBaggageFrozen(existingBaggage) && isSentryBaggageEmpty(existingBaggage))
321+
!existingBaggage || (isBaggageMutable(existingBaggage) && isSentryBaggageEmpty(existingBaggage))
322322
? this._getBaggageWithSentryValues(existingBaggage)
323323
: existingBaggage;
324324

@@ -378,7 +378,7 @@ export class Span implements SpanInterface {
378378
environment && setBaggageValue(baggage, 'environment', environment);
379379
release && setBaggageValue(baggage, 'release', release);
380380

381-
freezeBaggage(baggage);
381+
setBaggageImmutable(baggage);
382382

383383
return baggage;
384384
}

0 commit comments

Comments
 (0)