Skip to content

Commit ac39685

Browse files
author
Luca Forstner
authored
ref: Migrate transaction source from metadata to attributes (#10674)
1 parent a8966d1 commit ac39685

File tree

46 files changed

+252
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+252
-228
lines changed

dev-packages/browser-integration-tests/suites/feedback/captureFeedback/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ sentryTest('should capture feedback (@sentry-internal/feedback import)', async (
4444
const feedbackEvent = envelopeRequestParser((await feedbackRequestPromise).request());
4545
expect(feedbackEvent).toEqual({
4646
type: 'feedback',
47+
breadcrumbs: expect.any(Array),
4748
contexts: {
4849
feedback: {
4950
contact_email: '[email protected]',

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ sentryTest('should capture feedback (@sentry-internal/feedback import)', async (
5050

5151
expect(breadcrumbs).toEqual(
5252
expect.arrayContaining([
53-
{
53+
expect.objectContaining({
5454
category: 'sentry.feedback',
5555
data: { feedbackId: expect.any(String) },
56-
},
56+
}),
5757
]),
5858
);
5959

6060
expect(feedbackEvent).toEqual({
6161
type: 'feedback',
62+
breadcrumbs: expect.any(Array),
6263
contexts: {
6364
feedback: {
6465
contact_email: '[email protected]',

dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Sentry from '@sentry/browser';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/browser';
23
import { Integrations } from '@sentry/tracing';
34

45
window.Sentry = Sentry;
@@ -17,4 +18,4 @@ scope.addEventProcessor(event => {
1718
event.transaction = 'testTransactionDSC';
1819
return event;
1920
});
20-
scope.getTransaction().setMetadata({ source: 'custom' });
21+
scope.getTransaction().setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom');

dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
6565
'http.response.status_code': 200,
6666
'sentry.op': 'http.server',
6767
'sentry.origin': 'auto.http.otel.http',
68+
'sentry.source': 'route',
6869
},
6970
op: 'http.server',
7071
span_id: expect.any(String),
@@ -89,6 +90,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
8990
'http.response.status_code': 200,
9091
'sentry.op': 'http.server',
9192
'sentry.origin': 'auto.http.otel.http',
93+
'sentry.source': 'route',
9294
},
9395
op: 'http.server',
9496
parent_span_id: outgoingHttpSpanId,
@@ -162,6 +164,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
162164
'http.response.status_code': 200,
163165
'sentry.op': 'http.server',
164166
'sentry.origin': 'auto.http.otel.http',
167+
'sentry.source': 'route',
165168
},
166169
op: 'http.server',
167170
span_id: expect.any(String),
@@ -186,6 +189,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
186189
'http.response.status_code': 200,
187190
'sentry.op': 'http.server',
188191
'sentry.origin': 'auto.http.otel.http',
192+
'sentry.source': 'route',
189193
},
190194
op: 'http.server',
191195
parent_span_id: outgoingHttpSpanId,

dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
3030
'http.response.status_code': 200,
3131
'sentry.op': 'http.server',
3232
'sentry.origin': 'auto.http.otel.http',
33+
'sentry.source': 'route',
3334
},
3435
op: 'http.server',
3536
span_id: expect.any(String),

dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
22
import * as Sentry from '@sentry/node';
3-
import * as Tracing from '@sentry/tracing';
43
import express from 'express';
54

65
const app = express();
@@ -9,7 +8,7 @@ Sentry.init({
98
dsn: 'https://[email protected]/1337',
109
release: '1.0',
1110
// eslint-disable-next-line deprecation/deprecation
12-
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
11+
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Sentry.Integrations.Express({ app })],
1312
tracesSampleRate: 1.0,
1413
transport: loggingTransport,
1514
});

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { dropUndefinedKeys } from '@sentry/utils';
33

44
import { DEFAULT_ENVIRONMENT } from '../constants';
55
import { getClient } from '../currentScopes';
6+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
67
import { getRootSpan } from '../utils/getRootSpan';
78
import { spanIsSampled, spanToJSON } from '../utils/spanUtils';
89

@@ -66,14 +67,16 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
6667
// TODO (v8): Replace txn.metadata with txn.attributes[]
6768
// We can't do this yet because attributes aren't always set yet.
6869
// eslint-disable-next-line deprecation/deprecation
69-
const { sampleRate: maybeSampleRate, source } = txn.metadata;
70+
const { sampleRate: maybeSampleRate } = txn.metadata;
7071
if (maybeSampleRate != null) {
7172
dsc.sample_rate = `${maybeSampleRate}`;
7273
}
7374

7475
// We don't want to have a transaction name in the DSC if the source is "url" because URLs might contain PII
7576
const jsonSpan = spanToJSON(txn);
7677

78+
const source = (jsonSpan.data || {})[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
79+
7780
// after JSON conversion, txn.name becomes jsonSpan.description
7881
if (source && source !== 'url') {
7982
dsc.transaction = jsonSpan.description;

packages/core/src/tracing/transaction.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
TransactionContext,
1111
TransactionEvent,
1212
TransactionMetadata,
13+
TransactionSource,
1314
} from '@sentry/types';
1415
import { dropUndefinedKeys, logger } from '@sentry/utils';
1516

@@ -68,6 +69,11 @@ export class Transaction extends SentrySpan implements TransactionInterface {
6869

6970
this._trimEnd = transactionContext.trimEnd;
7071

72+
this._attributes = {
73+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
74+
...this._attributes,
75+
};
76+
7177
// this is because transactions are also spans, and spans have a transaction pointer
7278
// TODO (v8): Replace this with another way to set the root span
7379
// eslint-disable-next-line deprecation/deprecation
@@ -110,17 +116,12 @@ export class Transaction extends SentrySpan implements TransactionInterface {
110116
// We merge attributes in for backwards compatibility
111117
return {
112118
// Defaults
113-
// eslint-disable-next-line deprecation/deprecation
114-
source: 'custom',
115119
spanMetadata: {},
116120

117121
// Legacy metadata
118122
...this._metadata,
119123

120124
// From attributes
121-
...(this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] && {
122-
source: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionMetadata['source'],
123-
}),
124125
...(this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] && {
125126
sampleRate: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as TransactionMetadata['sampleRate'],
126127
}),
@@ -142,7 +143,7 @@ export class Transaction extends SentrySpan implements TransactionInterface {
142143
*
143144
* @deprecated Use `.updateName()` and `.setAttribute()` instead.
144145
*/
145-
public setName(name: string, source: TransactionMetadata['source'] = 'custom'): void {
146+
public setName(name: string, source: TransactionSource = 'custom'): void {
146147
this._name = name;
147148
this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
148149
}
@@ -309,8 +310,8 @@ export class Transaction extends SentrySpan implements TransactionInterface {
309310

310311
// eslint-disable-next-line deprecation/deprecation
311312
const { metadata } = this;
312-
// eslint-disable-next-line deprecation/deprecation
313-
const { source } = metadata;
313+
314+
const source = this._attributes['sentry.source'] as TransactionSource | undefined;
314315

315316
const transaction: TransactionEvent = {
316317
contexts: {

packages/core/test/lib/tracing/dynamicSamplingContext.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ describe('getDynamicSamplingContextFromSpan', () => {
7575
name: 'tx',
7676
metadata: {
7777
sampleRate: 0.56,
78-
source: 'route',
78+
},
79+
attributes: {
80+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
7981
},
8082
sampled: true,
8183
});
@@ -98,9 +100,11 @@ describe('getDynamicSamplingContextFromSpan', () => {
98100
const transaction = new Transaction({
99101
name: 'tx',
100102
metadata: {
101-
source: 'url',
102103
sampleRate: 0.56,
103104
},
105+
attributes: {
106+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
107+
},
104108
});
105109

106110
const dsc = getDynamicSamplingContextFromSpan(transaction);
@@ -110,11 +114,11 @@ describe('getDynamicSamplingContextFromSpan', () => {
110114
test.each([
111115
['is included if transaction source is parameterized route/url', 'route'],
112116
['is included if transaction source is a custom name', 'custom'],
113-
])('%s', (_: string, source) => {
117+
] as const)('%s', (_: string, source: TransactionSource) => {
114118
const transaction = startInactiveSpan({
115119
name: 'tx',
116-
metadata: {
117-
...(source && { source: source as TransactionSource }),
120+
attributes: {
121+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
118122
},
119123
});
120124

packages/core/test/lib/tracing/trace.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ describe('startSpan', () => {
266266
data: {
267267
'sentry.origin': 'auto.http.browser',
268268
'sentry.sample_rate': 0,
269+
'sentry.source': 'custom',
269270
},
270271
origin: 'auto.http.browser',
271272
description: 'GET users/[id]',

0 commit comments

Comments
 (0)