Skip to content

Commit f2d7de9

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

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
}

packages/tracing/test/browser/browsertracing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('BrowserTracing', () => {
234234
parentSpanId: 'b6e54397b12a2a0f',
235235
parentSampled: true,
236236
metadata: {
237-
baggage: [{ release: '2.1.14' }, 'foo=bar', true],
237+
baggage: [{ release: '2.1.14' }, 'foo=bar', false],
238238
},
239239
}),
240240
expect.any(Number),

packages/tracing/test/span.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ describe('Span', () => {
428428
const transaction = new Transaction(
429429
{
430430
name: 'tx',
431-
metadata: { baggage: createBaggage({}, '', false) },
431+
metadata: { baggage: createBaggage({}, '', true) },
432432
},
433433
hub,
434434
);

packages/types/src/baggage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type BaggageObj = Partial<Record<AllowedBaggageKeys, string> & Record<str
1313
* set/used by sentry, they will be stored in an object to be easily accessed.
1414
* If they are not, they are kept as a string to be only accessed when serialized
1515
* at baggage propagation time.
16-
* The third tuple member controls the mutability of the baggage. If it is `true`,
17-
* the baggage can not be modified any longer (i.e. is immutable).
16+
* The third tuple member controls the mutability of the baggage. If it is `false`,
17+
* the baggage can no longer longer be modified (i.e. is immutable).
1818
*/
1919
export type Baggage = [BaggageObj, string, boolean];

packages/utils/src/baggage.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const SENTRY_BAGGAGE_KEY_PREFIX_REGEX = /^sentry-/;
1616
export const MAX_BAGGAGE_STRING_LENGTH = 8192;
1717

1818
/** Create an instance of Baggage */
19-
export function createBaggage(initItems: BaggageObj, baggageString: string = '', frozen: boolean = false): Baggage {
20-
return [{ ...initItems }, baggageString, frozen];
19+
export function createBaggage(initItems: BaggageObj, baggageString: string = '', mutable: boolean = true): Baggage {
20+
return [{ ...initItems }, baggageString, mutable];
2121
}
2222

2323
/** Get a value from baggage */
@@ -27,7 +27,7 @@ export function getBaggageValue(baggage: Baggage, key: keyof BaggageObj): Baggag
2727

2828
/** Add a value to baggage */
2929
export function setBaggageValue(baggage: Baggage, key: keyof BaggageObj, value: BaggageObj[keyof BaggageObj]): void {
30-
if (!isBaggageFrozen(baggage)) {
30+
if (isBaggageMutable(baggage)) {
3131
baggage[0][key] = value;
3232
}
3333
}
@@ -57,20 +57,20 @@ export function getThirdPartyBaggage(baggage: Baggage): string {
5757
}
5858

5959
/**
60-
* Checks if baggage is frozen (i.e. immutable)
60+
* Checks if baggage is mutable
6161
* @param baggage
62-
* @returns true if baggage is frozen, else false
62+
* @returns true if baggage is mutable, else false
6363
*/
64-
export function isBaggageFrozen(baggage: Baggage): boolean {
64+
export function isBaggageMutable(baggage: Baggage): boolean {
6565
return baggage[2];
6666
}
6767

6868
/**
69-
* Freezes baggage (i.e. makes it immutable)
69+
* Sets the passed baggage immutable
7070
* @param baggage
7171
*/
72-
export function freezeBaggage(baggage: Baggage): void {
73-
baggage[2] = true;
72+
export function setBaggageImmutable(baggage: Baggage): void {
73+
baggage[2] = false;
7474
}
7575

7676
/** Serialize a baggage object */
@@ -102,13 +102,13 @@ export function parseBaggageString(inputBaggageString: string): Baggage {
102102
[baggageKey]: decodeURIComponent(val),
103103
},
104104
baggageString,
105-
false,
105+
true,
106106
];
107107
} else {
108-
return [baggageObj, baggageString === '' ? curr : `${baggageString},${curr}`, false];
108+
return [baggageObj, baggageString === '' ? curr : `${baggageString},${curr}`, true];
109109
}
110110
},
111-
[{}, '', false],
111+
[{}, '', true],
112112
);
113113
}
114114

@@ -145,21 +145,21 @@ export function mergeAndSerializeBaggage(incomingBaggage?: Baggage, headerBaggag
145145
* Helper function that takes a raw baggage string (if available) and the processed sentry-trace header
146146
* data (if available), parses the baggage string and creates a Baggage object
147147
* If there is no baggage string, it will create an empty Baggage object.
148-
* In a second step, this functions determines when the created Baggage object should be frozen to prevent mutation
149-
* of the Sentry data.
148+
* In a second step, this functions determines when the created Baggage object should be set immutable
149+
* to prevent mutation of the Sentry data.
150150
*
151151
* Extracted this logic to a function because it's duplicated in a lot of places.
152152
*
153153
* @param rawBaggageString
154154
* @param traceparentData
155155
*/
156-
export function parseAndFreezeBaggageIfNecessary(
156+
export function parseBaggageSetMutability(
157157
rawBaggageString: string | false | undefined | null,
158158
traceparentData: TraceparentData | string | false | undefined | null,
159159
): Baggage {
160160
const baggage = parseBaggageString(rawBaggageString || '');
161161
if (!isSentryBaggageEmpty(baggage) || (traceparentData && isSentryBaggageEmpty(baggage))) {
162-
freezeBaggage(baggage);
162+
setBaggageImmutable(baggage);
163163
}
164164
return baggage;
165165
}

0 commit comments

Comments
 (0)