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]',

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Transaction } from '../../../src';
1+
import {
2+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
3+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
4+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
5+
Transaction,
6+
} from '../../../src';
27

38
describe('transaction', () => {
49
describe('name', () => {
@@ -16,7 +21,7 @@ describe('transaction', () => {
1621
transaction.name = 'new name';
1722

1823
expect(transaction.name).toEqual('new name');
19-
expect(transaction.metadata.source).toEqual('custom');
24+
expect(transaction.attributes['sentry.source']).toEqual('custom');
2025
});
2126

2227
it('allows to update the name via setName', () => {
@@ -27,7 +32,7 @@ describe('transaction', () => {
2732
transaction.setName('new name');
2833

2934
expect(transaction.name).toEqual('new name');
30-
expect(transaction.metadata.source).toEqual('custom');
35+
expect(transaction.attributes['sentry.source']).toEqual('custom');
3136
});
3237

3338
it('allows to update the name via updateName', () => {
@@ -38,7 +43,7 @@ describe('transaction', () => {
3843
transaction.updateName('new name');
3944

4045
expect(transaction.name).toEqual('new name');
41-
expect(transaction.metadata.source).toEqual('route');
46+
expect(transaction.attributes['sentry.source']).toEqual('route');
4247
});
4348
/* eslint-enable deprecation/deprecation */
4449
});
@@ -48,15 +53,13 @@ describe('transaction', () => {
4853
it('works with defaults', () => {
4954
const transaction = new Transaction({ name: 'span name' });
5055
expect(transaction.metadata).toEqual({
51-
source: 'custom',
5256
spanMetadata: {},
5357
});
5458
});
5559

5660
it('allows to set metadata in constructor', () => {
57-
const transaction = new Transaction({ name: 'span name', metadata: { source: 'url', request: {} } });
61+
const transaction = new Transaction({ name: 'span name', metadata: { request: {} } });
5862
expect(transaction.metadata).toEqual({
59-
source: 'url',
6063
spanMetadata: {},
6164
request: {},
6265
});
@@ -71,37 +74,31 @@ describe('transaction', () => {
7174
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 0.5,
7275
},
7376
});
77+
7478
expect(transaction.metadata).toEqual({
75-
source: 'url',
7679
sampleRate: 0.5,
7780
spanMetadata: {},
7881
request: {},
7982
});
80-
});
81-
82-
it('allows to update metadata via setMetadata', () => {
83-
const transaction = new Transaction({ name: 'span name', metadata: { source: 'url', request: {} } });
84-
85-
transaction.setMetadata({ source: 'route' });
8683

87-
expect(transaction.metadata).toEqual({
88-
source: 'route',
89-
spanMetadata: {},
90-
request: {},
84+
expect(transaction.attributes).toEqual({
85+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',
86+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
87+
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 0.5,
9188
});
9289
});
9390

94-
it('allows to update metadata via setAttribute', () => {
95-
const transaction = new Transaction({ name: 'span name', metadata: { source: 'url', request: {} } });
91+
it('allows to update metadata via setMetadata', () => {
92+
const transaction = new Transaction({ name: 'span name', metadata: {} });
9693

97-
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
94+
transaction.setMetadata({ request: {} });
9895

9996
expect(transaction.metadata).toEqual({
100-
source: 'route',
10197
spanMetadata: {},
10298
request: {},
10399
});
104100
});
101+
105102
/* eslint-enable deprecation/deprecation */
106103
});
107104
});

packages/deno/test/__snapshots__/mod.test.ts.snap

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,6 @@ snapshot[`captureException 1`] = `
4141
},
4242
stacktrace: {
4343
frames: [
44-
{
45-
colno: 20,
46-
filename: "ext:cli/40_testing.js",
47-
function: "outerWrapped",
48-
in_app: false,
49-
lineno: 472,
50-
},
51-
{
52-
colno: 33,
53-
filename: "ext:cli/40_testing.js",
54-
function: "exitSanitizer",
55-
in_app: false,
56-
lineno: 458,
57-
},
58-
{
59-
colno: 31,
60-
filename: "ext:cli/40_testing.js",
61-
function: "resourceSanitizer",
62-
in_app: false,
63-
lineno: 410,
64-
},
65-
{
66-
colno: 33,
67-
filename: "ext:cli/40_testing.js",
68-
function: "asyncOpSanitizer",
69-
in_app: false,
70-
lineno: 177,
71-
},
72-
{
73-
colno: 11,
74-
filename: "ext:cli/40_testing.js",
75-
function: "innerWrapped",
76-
in_app: false,
77-
lineno: 526,
78-
},
7944
{
8045
colno: 27,
8146
context_line: " client.captureException(something());",

packages/deno/test/normalize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ function normalizeEvent(event: sentryTypes.Event): sentryTypes.Event {
152152
}
153153

154154
if (event.exception?.values?.[0].stacktrace?.frames) {
155-
// Exlcude Deno frames since these may change between versions
155+
// Exclude Deno frames since these may change between versions
156156
event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames.filter(
157-
frame => !frame.filename?.includes('deno:'),
157+
frame => !frame.filename?.includes('deno:') && !frame.filename?.startsWith('ext:'),
158158
);
159159
}
160160

0 commit comments

Comments
 (0)