Skip to content

Commit d1d21aa

Browse files
committed
fix a bunch of tests
1 parent aebc065 commit d1d21aa

File tree

14 files changed

+135
-29
lines changed

14 files changed

+135
-29
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/middleware.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
6969
type: 'fetch',
7070
url: 'http://localhost:3030/',
7171
'sentry.op': 'http.client',
72+
'sentry.origin': 'auto.http.wintercg_fetch',
7273
},
7374
description: 'GET http://localhost:3030/',
7475
op: 'http.client',

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
@@ -64,6 +64,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
6464
'otel.kind': 'SERVER',
6565
'http.response.status_code': 200,
6666
'sentry.op': 'http.server',
67+
'sentry.origin': 'auto.http.otel.http',
6768
},
6869
op: 'http.server',
6970
span_id: expect.any(String),
@@ -87,6 +88,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
8788
'otel.kind': 'SERVER',
8889
'http.response.status_code': 200,
8990
'sentry.op': 'http.server',
91+
'sentry.origin': 'auto.http.otel.http',
9092
},
9193
op: 'http.server',
9294
parent_span_id: outgoingHttpSpanId,
@@ -159,6 +161,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
159161
'otel.kind': 'SERVER',
160162
'http.response.status_code': 200,
161163
'sentry.op': 'http.server',
164+
'sentry.origin': 'auto.http.otel.http',
162165
},
163166
op: 'http.server',
164167
span_id: expect.any(String),
@@ -182,6 +185,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
182185
'otel.kind': 'SERVER',
183186
'http.response.status_code': 200,
184187
'sentry.op': 'http.server',
188+
'sentry.origin': 'auto.http.otel.http',
185189
},
186190
op: 'http.server',
187191
parent_span_id: outgoingHttpSpanId,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
2929
'otel.kind': 'SERVER',
3030
'http.response.status_code': 200,
3131
'sentry.op': 'http.server',
32+
'sentry.origin': 'auto.http.otel.http',
3233
},
3334
op: 'http.server',
3435
span_id: expect.any(String),
@@ -48,6 +49,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
4849
'fastify.type': 'request_handler',
4950
'http.route': '/test-transaction',
5051
'otel.kind': 'INTERNAL',
52+
'sentry.origin': 'auto.http.otel.fastify',
5153
},
5254
description: 'request handler - fastify -> app-auto-0',
5355
parent_span_id: expect.any(String),
@@ -61,6 +63,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
6163
{
6264
data: {
6365
'otel.kind': 'INTERNAL',
66+
'sentry.origin': 'manual',
6467
},
6568
description: 'test-span',
6669
parent_span_id: expect.any(String),
@@ -74,6 +77,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
7477
{
7578
data: {
7679
'otel.kind': 'INTERNAL',
80+
'sentry.origin': 'manual',
7781
},
7882
description: 'child-span',
7983
parent_span_id: expect.any(String),

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ describe('span', () => {
8484
strArray: ['aa', 'bb'],
8585
boolArray: [true, false],
8686
arrayWithUndefined: [1, undefined, 2],
87+
// origin is set by default to 'manual' in the Span constructor
88+
'sentry.origin': 'manual',
8789
});
8890
});
8991

@@ -92,11 +94,12 @@ describe('span', () => {
9294

9395
span.setAttribute('str', 'bar');
9496

95-
expect(Object.keys(span['_attributes']).length).toEqual(1);
97+
// length 2 because `sentry.origin` is always set by default
98+
expect(Object.keys(span['_attributes']).length).toEqual(2);
9699

97100
span.setAttribute('str', undefined);
98101

99-
expect(Object.keys(span['_attributes']).length).toEqual(0);
102+
expect(Object.keys(span['_attributes']).length).toEqual(1);
100103
});
101104

102105
it('disallows invalid attribute types', () => {
@@ -119,7 +122,10 @@ describe('span', () => {
119122

120123
const initialAttributes = span['_attributes'];
121124

122-
expect(initialAttributes).toEqual({});
125+
expect(initialAttributes).toEqual({
126+
// origin is set by default to 'manual' in the Span constructor
127+
'sentry.origin': 'manual',
128+
});
123129

124130
const newAttributes = {
125131
str: 'bar',
@@ -145,6 +151,7 @@ describe('span', () => {
145151
strArray: ['aa', 'bb'],
146152
boolArray: [true, false],
147153
arrayWithUndefined: [1, undefined, 2],
154+
'sentry.origin': 'manual',
148155
});
149156

150157
expect(span['_attributes']).not.toBe(newAttributes);
@@ -164,6 +171,7 @@ describe('span', () => {
164171
strArray: ['aa', 'bb'],
165172
boolArray: [true, false],
166173
arrayWithUndefined: [1, undefined, 2],
174+
'sentry.origin': 'manual',
167175
});
168176
});
169177

@@ -172,11 +180,12 @@ describe('span', () => {
172180

173181
span.setAttribute('str', 'bar');
174182

175-
expect(Object.keys(span['_attributes']).length).toEqual(1);
183+
// length 2 because `sentry.origin` is always set by default
184+
expect(Object.keys(span['_attributes']).length).toEqual(2);
176185

177186
span.setAttributes({ str: undefined });
178187

179-
expect(Object.keys(span['_attributes']).length).toEqual(0);
188+
expect(Object.keys(span['_attributes']).length).toEqual(1);
180189
});
181190
});
182191

@@ -275,24 +284,38 @@ describe('span', () => {
275284
it('works without data & attributes', () => {
276285
const span = new Span();
277286

278-
expect(span['_getData']()).toEqual(undefined);
287+
expect(span['_getData']()).toEqual({
288+
// origin is set by default to 'manual' in the Span constructor
289+
'sentry.origin': 'manual',
290+
});
279291
});
280292

281293
it('works with data only', () => {
282294
const span = new Span();
283295
// eslint-disable-next-line deprecation/deprecation
284296
span.setData('foo', 'bar');
285297

286-
expect(span['_getData']()).toEqual({ foo: 'bar' });
287-
// eslint-disable-next-line deprecation/deprecation
288-
expect(span['_getData']()).toBe(span.data);
298+
expect(span['_getData']()).toEqual({
299+
foo: 'bar',
300+
// origin is set by default to 'manual' in the Span constructor
301+
'sentry.origin': 'manual',
302+
});
303+
expect(span['_getData']()).toStrictEqual({
304+
// eslint-disable-next-line deprecation/deprecation
305+
...span.data,
306+
'sentry.origin': 'manual',
307+
});
289308
});
290309

291310
it('works with attributes only', () => {
292311
const span = new Span();
293312
span.setAttribute('foo', 'bar');
294313

295-
expect(span['_getData']()).toEqual({ foo: 'bar' });
314+
expect(span['_getData']()).toEqual({
315+
foo: 'bar',
316+
// origin is set by default to 'manual' in the Span constructor
317+
'sentry.origin': 'manual',
318+
});
296319
// eslint-disable-next-line deprecation/deprecation
297320
expect(span['_getData']()).toBe(span.attributes);
298321
});
@@ -306,7 +329,13 @@ describe('span', () => {
306329
// eslint-disable-next-line deprecation/deprecation
307330
span.setData('baz', 'baz');
308331

309-
expect(span['_getData']()).toEqual({ foo: 'foo', bar: 'bar', baz: 'baz' });
332+
expect(span['_getData']()).toEqual({
333+
foo: 'foo',
334+
bar: 'bar',
335+
baz: 'baz',
336+
// origin is set by default to 'manual' in the Span constructor
337+
'sentry.origin': 'manual',
338+
});
310339
// eslint-disable-next-line deprecation/deprecation
311340
expect(span['_getData']()).not.toBe(span.attributes);
312341
// eslint-disable-next-line deprecation/deprecation

packages/core/test/lib/utils/spanUtils.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ describe('spanToJSON', () => {
5555
trace_id: span.spanContext().traceId,
5656
origin: 'manual',
5757
start_timestamp: span['_startTime'],
58+
data: {
59+
'sentry.origin': 'manual',
60+
},
5861
});
5962
});
6063

@@ -89,6 +92,7 @@ describe('spanToJSON', () => {
8992
timestamp: 456,
9093
data: {
9194
'sentry.op': 'test op',
95+
'sentry.origin': 'auto',
9296
},
9397
});
9498
});

packages/nextjs/test/integration/test/client/tracingFetch.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { Transaction } from '@sentry/types';
2+
import { SerializedEvent } from '@sentry/types';
33
import { countEnvelopes, getMultipleSentryEnvelopeRequests } from './utils/helpers';
44

55
test('should correctly instrument `fetch` for performance tracing', async ({ page }) => {
@@ -12,7 +12,7 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
1212
});
1313
});
1414

15-
const transaction = await getMultipleSentryEnvelopeRequests<Transaction>(page, 1, {
15+
const transaction = await getMultipleSentryEnvelopeRequests<SerializedEvent>(page, 1, {
1616
url: '/fetch',
1717
envelopeType: 'transaction',
1818
});
@@ -27,7 +27,6 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
2727
},
2828
});
2929

30-
// @ts-expect-error - We know that `spans` is inside Transaction envelopes
3130
expect(transaction[0].spans).toEqual(
3231
expect.arrayContaining([
3332
expect.objectContaining({
@@ -38,6 +37,7 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
3837
'http.response_content_length': expect.any(Number),
3938
'http.response.status_code': 200,
4039
'sentry.op': 'http.client',
40+
'sentry.origin': 'auto.http.client',
4141
},
4242
description: 'GET http://example.com',
4343
op: 'http.client',
@@ -47,6 +47,7 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
4747
timestamp: expect.any(Number),
4848
trace_id: expect.any(String),
4949
status: expect.any(String),
50+
origin: 'auto.http.client',
5051
}),
5152
]),
5253
);

packages/opentelemetry/test/custom/transaction.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ describe('NodeExperimentalTransaction', () => {
2828
expect.objectContaining({
2929
contexts: {
3030
trace: {
31+
data: {
32+
'sentry.origin': 'manual',
33+
},
3134
span_id: expect.any(String),
3235
trace_id: expect.any(String),
3336
origin: 'manual',
@@ -109,6 +112,9 @@ describe('NodeExperimentalTransaction', () => {
109112
expect.objectContaining({
110113
contexts: {
111114
trace: {
115+
data: {
116+
'sentry.origin': 'manual',
117+
},
112118
span_id: expect.any(String),
113119
trace_id: expect.any(String),
114120
origin: 'manual',

packages/opentelemetry/test/integration/scope.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ describe('Integration | Scope', () => {
9494
expect.objectContaining({
9595
contexts: expect.objectContaining({
9696
trace: {
97-
data: { 'otel.kind': 'INTERNAL' },
97+
data: {
98+
'otel.kind': 'INTERNAL',
99+
'sentry.origin': 'manual',
100+
},
98101
span_id: spanId,
99102
status: 'ok',
100103
trace_id: traceId,

packages/opentelemetry/test/integration/transactions.test.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ describe('Integration | Transactions', () => {
8383
},
8484
},
8585
trace: {
86-
data: { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op' },
86+
data: {
87+
'otel.kind': 'INTERNAL',
88+
'sentry.op': 'test op',
89+
'sentry.origin': 'auto.test',
90+
},
8791
op: 'test op',
8892
span_id: expect.any(String),
8993
status: 'ok',
@@ -146,6 +150,7 @@ describe('Integration | Transactions', () => {
146150
{
147151
data: {
148152
'otel.kind': 'INTERNAL',
153+
'sentry.origin': 'manual',
149154
},
150155
description: 'inner span 1',
151156
origin: 'manual',
@@ -157,7 +162,11 @@ describe('Integration | Transactions', () => {
157162
trace_id: expect.any(String),
158163
},
159164
{
160-
data: { 'otel.kind': 'INTERNAL', 'test.inner': 'test value' },
165+
data: {
166+
'otel.kind': 'INTERNAL',
167+
'test.inner': 'test value',
168+
'sentry.origin': 'manual',
169+
},
161170
description: 'inner span 2',
162171
origin: 'manual',
163172
parent_span_id: expect.any(String),
@@ -238,7 +247,11 @@ describe('Integration | Transactions', () => {
238247
},
239248
}),
240249
trace: {
241-
data: { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op' },
250+
data: {
251+
'otel.kind': 'INTERNAL',
252+
'sentry.op': 'test op',
253+
'sentry.origin': 'auto.test',
254+
},
242255
op: 'test op',
243256
span_id: expect.any(String),
244257
status: 'ok',
@@ -280,7 +293,11 @@ describe('Integration | Transactions', () => {
280293
},
281294
}),
282295
trace: {
283-
data: { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op b' },
296+
data: {
297+
'otel.kind': 'INTERNAL',
298+
'sentry.op': 'test op b',
299+
'sentry.origin': 'manual',
300+
},
284301
op: 'test op b',
285302
span_id: expect.any(String),
286303
status: 'ok',
@@ -360,6 +377,7 @@ describe('Integration | Transactions', () => {
360377
data: {
361378
'otel.kind': 'INTERNAL',
362379
'sentry.op': 'test op',
380+
'sentry.origin': 'auto.test',
363381
},
364382
op: 'test op',
365383
span_id: expect.any(String),
@@ -398,7 +416,10 @@ describe('Integration | Transactions', () => {
398416
// This is the same behavior as for the "regular" SDKs
399417
expect(spans.map(span => spanToJSON(span))).toEqual([
400418
{
401-
data: { 'otel.kind': 'INTERNAL' },
419+
data: {
420+
'otel.kind': 'INTERNAL',
421+
'sentry.origin': 'manual',
422+
},
402423
description: 'inner span 1',
403424
origin: 'manual',
404425
parent_span_id: expect.any(String),
@@ -409,7 +430,10 @@ describe('Integration | Transactions', () => {
409430
trace_id: traceId,
410431
},
411432
{
412-
data: { 'otel.kind': 'INTERNAL' },
433+
data: {
434+
'otel.kind': 'INTERNAL',
435+
'sentry.origin': 'manual',
436+
},
413437
description: 'inner span 2',
414438
origin: 'manual',
415439
parent_span_id: expect.any(String),

packages/tracing-internal/test/browser/request.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ describe('callbacks', () => {
264264
type: 'fetch',
265265
url: 'http://dogs.are.great/',
266266
'sentry.op': 'http.client',
267+
'sentry.origin': 'auto.http.browser',
267268
});
268269
expect(finishedSpan.op).toBe('http.client');
269270
});

packages/tracing/test/hub.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ describe('Hub', () => {
305305
makeMain(hub);
306306
hub.startTransaction({ name: 'dogpark', parentSampled: true });
307307

308-
expect(Transaction.prototype.setAttribute).toHaveBeenCalledTimes(0);
308+
// length 1 because `sentry.origin` is set on span initialization
309+
expect(Transaction.prototype.setAttribute).toHaveBeenCalledTimes(1);
309310
});
310311

311312
it('should record sampling method and rate when sampling decision comes from traceSampleRate', () => {

0 commit comments

Comments
 (0)