Skip to content

Commit 82c7890

Browse files
committed
fix tests for node
1 parent 92d2f72 commit 82c7890

File tree

3 files changed

+70
-48
lines changed

3 files changed

+70
-48
lines changed

packages/node-experimental/test/integration/scope.test.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,33 @@ describe('Integration | Scope', () => {
5656
await client.flush();
5757

5858
expect(beforeSend).toHaveBeenCalledTimes(1);
59+
60+
if (spanId) {
61+
expect(beforeSend).toHaveBeenCalledWith(
62+
expect.objectContaining({
63+
contexts: expect.objectContaining({
64+
trace: {
65+
span_id: spanId,
66+
trace_id: traceId,
67+
},
68+
}),
69+
}),
70+
{
71+
event_id: expect.any(String),
72+
originalException: error,
73+
syntheticException: expect.any(Error),
74+
},
75+
);
76+
}
77+
5978
expect(beforeSend).toHaveBeenCalledWith(
6079
expect.objectContaining({
61-
contexts: expect.objectContaining({
62-
trace: spanId
63-
? {
64-
span_id: spanId,
65-
trace_id: traceId,
66-
parent_span_id: undefined,
67-
}
68-
: expect.any(Object),
69-
}),
7080
tags: {
7181
tag1: 'val1',
7282
tag2: 'val2',
7383
tag3: 'val3',
7484
tag4: 'val4',
85+
...(enableTracing ? { transaction: 'outer' } : {}),
7586
},
7687
}),
7788
{
@@ -88,7 +99,12 @@ describe('Integration | Scope', () => {
8899
expect.objectContaining({
89100
contexts: expect.objectContaining({
90101
trace: {
91-
data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', 'sentry.source': 'custom' },
102+
data: {
103+
'otel.kind': 'INTERNAL',
104+
'sentry.origin': 'manual',
105+
'sentry.source': 'custom',
106+
'sentry.sample_rate': 1,
107+
},
92108
span_id: spanId,
93109
status: 'ok',
94110
trace_id: traceId,
@@ -102,6 +118,7 @@ describe('Integration | Scope', () => {
102118
tag2: 'val2',
103119
tag3: 'val3',
104120
tag4: 'val4',
121+
transaction: 'outer',
105122
},
106123
timestamp: expect.any(Number),
107124
transaction: 'outer',
@@ -186,6 +203,7 @@ describe('Integration | Scope', () => {
186203
tag2: 'val2a',
187204
tag3: 'val3a',
188205
tag4: 'val4a',
206+
...(enableTracing ? { transaction: 'outer' } : {}),
189207
},
190208
}),
191209
{
@@ -211,6 +229,7 @@ describe('Integration | Scope', () => {
211229
tag2: 'val2b',
212230
tag3: 'val3b',
213231
tag4: 'val4b',
232+
...(enableTracing ? { transaction: 'outer' } : {}),
214233
},
215234
}),
216235
{

packages/node-experimental/test/integration/transactions.test.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { TraceFlags, context, trace } from '@opentelemetry/api';
22
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
3-
import { spanToJSON } from '@sentry/core';
4-
import { SentrySpanProcessor, getClient, setPropagationContextOnContext } from '@sentry/opentelemetry';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, spanToJSON } from '@sentry/core';
4+
import { SentrySpanProcessor, setPropagationContextOnContext } from '@sentry/opentelemetry';
55
import type { PropagationContext, TransactionEvent } from '@sentry/types';
66
import { logger } from '@sentry/utils';
77

88
import * as Sentry from '../../src';
9-
import type { NodeClient } from '../../src/sdk/client';
109
import { cleanupOtel, getProvider, mockSdkInit } from '../helpers/mockSdkInit';
1110

1211
describe('Integration | Transactions', () => {
@@ -20,7 +19,7 @@ describe('Integration | Transactions', () => {
2019

2120
mockSdkInit({ enableTracing: true, beforeSendTransaction });
2221

23-
const client = Sentry.getClient<NodeClient>();
22+
const client = Sentry.getClient()!;
2423

2524
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });
2625
Sentry.setTag('outer.tag', 'test value');
@@ -29,11 +28,11 @@ describe('Integration | Transactions', () => {
2928
{
3029
op: 'test op',
3130
name: 'test name',
32-
attributes: {
33-
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
34-
},
3531
origin: 'auto.test',
3632
metadata: { requestPath: 'test-path' },
33+
attributes: {
34+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
35+
},
3736
},
3837
span => {
3938
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
@@ -88,6 +87,8 @@ describe('Integration | Transactions', () => {
8887
'sentry.op': 'test op',
8988
'sentry.origin': 'auto.test',
9089
'sentry.source': 'task',
90+
'sentry.sample_rate': 1,
91+
'test.outer': 'test value',
9192
},
9293
op: 'test op',
9394
span_id: expect.any(String),
@@ -120,6 +121,7 @@ describe('Integration | Transactions', () => {
120121
tags: {
121122
'outer.tag': 'test value',
122123
'test.tag': 'test value',
124+
transaction: 'test name',
123125
},
124126
timestamp: expect.any(Number),
125127
transaction: 'test name',
@@ -175,39 +177,31 @@ describe('Integration | Transactions', () => {
175177

176178
mockSdkInit({ enableTracing: true, beforeSendTransaction });
177179

178-
const client = Sentry.getClient();
180+
const client = Sentry.getClient()!;
179181

180182
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });
181183

182184
Sentry.withIsolationScope(() => {
183-
Sentry.startSpan(
184-
{
185-
op: 'test op',
186-
name: 'test name',
187-
origin: 'auto.test',
188-
attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task' },
189-
},
190-
span => {
191-
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
185+
Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
186+
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
192187

193-
span.setAttributes({
194-
'test.outer': 'test value',
195-
});
188+
span.setAttributes({
189+
'test.outer': 'test value',
190+
});
196191

197-
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
198-
subSpan.end();
192+
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
193+
subSpan.end();
199194

200-
Sentry.setTag('test.tag', 'test value');
195+
Sentry.setTag('test.tag', 'test value');
201196

202-
Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
203-
Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
197+
Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
198+
Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
204199

205-
innerSpan.setAttributes({
206-
'test.inner': 'test value',
207-
});
200+
innerSpan.setAttributes({
201+
'test.inner': 'test value',
208202
});
209-
},
210-
);
203+
});
204+
});
211205
});
212206

213207
Sentry.withIsolationScope(() => {
@@ -255,6 +249,8 @@ describe('Integration | Transactions', () => {
255249
'sentry.op': 'test op',
256250
'sentry.origin': 'auto.test',
257251
'sentry.source': 'task',
252+
'test.outer': 'test value',
253+
'sentry.sample_rate': 1,
258254
},
259255
op: 'test op',
260256
span_id: expect.any(String),
@@ -265,7 +261,7 @@ describe('Integration | Transactions', () => {
265261
}),
266262
spans: [expect.any(Object), expect.any(Object)],
267263
start_timestamp: expect.any(Number),
268-
tags: { 'test.tag': 'test value' },
264+
tags: { 'test.tag': 'test value', transaction: 'test name' },
269265
timestamp: expect.any(Number),
270266
transaction: 'test name',
271267
transaction_info: { source: 'task' },
@@ -295,6 +291,8 @@ describe('Integration | Transactions', () => {
295291
'sentry.op': 'test op b',
296292
'sentry.origin': 'manual',
297293
'sentry.source': 'custom',
294+
'test.outer': 'test value b',
295+
'sentry.sample_rate': 1,
298296
},
299297
op: 'test op b',
300298
span_id: expect.any(String),
@@ -305,7 +303,7 @@ describe('Integration | Transactions', () => {
305303
}),
306304
spans: [expect.any(Object), expect.any(Object)],
307305
start_timestamp: expect.any(Number),
308-
tags: { 'test.tag': 'test value b' },
306+
tags: { 'test.tag': 'test value b', transaction: 'test name b' },
309307
timestamp: expect.any(Number),
310308
transaction: 'test name b',
311309
transaction_info: { source: 'custom' },
@@ -322,7 +320,7 @@ describe('Integration | Transactions', () => {
322320

323321
mockSdkInit({ enableTracing: true, beforeSendTransaction });
324322

325-
const client = Sentry.getClient<NodeClient>();
323+
const client = Sentry.getClient<Sentry.NodeClient>();
326324

327325
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });
328326

@@ -401,6 +399,8 @@ describe('Integration | Transactions', () => {
401399
'otel.kind': 'INTERNAL',
402400
'sentry.origin': 'manual',
403401
'sentry.source': 'custom',
402+
'test.outer': 'test value',
403+
'sentry.sample_rate': 1,
404404
},
405405
span_id: expect.any(String),
406406
status: 'ok',
@@ -410,7 +410,7 @@ describe('Integration | Transactions', () => {
410410
}),
411411
spans: [expect.any(Object), expect.any(Object)],
412412
start_timestamp: expect.any(Number),
413-
tags: { 'test.tag': 'test value' },
413+
tags: { 'test.tag': 'test value', transaction: 'test name' },
414414
timestamp: expect.any(Number),
415415
transaction: 'test name',
416416
type: 'transaction',
@@ -438,6 +438,8 @@ describe('Integration | Transactions', () => {
438438
'otel.kind': 'INTERNAL',
439439
'sentry.origin': 'manual',
440440
'sentry.source': 'custom',
441+
'test.outer': 'test value b',
442+
'sentry.sample_rate': 1,
441443
},
442444
span_id: expect.any(String),
443445
status: 'ok',
@@ -447,7 +449,7 @@ describe('Integration | Transactions', () => {
447449
}),
448450
spans: [expect.any(Object), expect.any(Object)],
449451
start_timestamp: expect.any(Number),
450-
tags: { 'test.tag': 'test value b' },
452+
tags: { 'test.tag': 'test value b', transaction: 'test name b' },
451453
timestamp: expect.any(Number),
452454
transaction: 'test name b',
453455
type: 'transaction',
@@ -481,7 +483,7 @@ describe('Integration | Transactions', () => {
481483

482484
mockSdkInit({ enableTracing: true, beforeSendTransaction });
483485

484-
const client = getClient() as NodeClient;
486+
const client = Sentry.getClient()!;
485487

486488
// We simulate the correct context we'd normally get from the SentryPropagator
487489
context.with(
@@ -519,6 +521,7 @@ describe('Integration | Transactions', () => {
519521
'sentry.op': 'test op',
520522
'sentry.origin': 'auto.test',
521523
'sentry.source': 'task',
524+
'sentry.sample_rate': 1,
522525
},
523526
op: 'test op',
524527
span_id: expect.any(String),
@@ -592,7 +595,7 @@ describe('Integration | Transactions', () => {
592595

593596
mockSdkInit({ enableTracing: true, beforeSendTransaction });
594597

595-
const client = getClient() as NodeClient;
598+
const client = Sentry.getClient()!;
596599
const provider = getProvider();
597600
const multiSpanProcessor = provider?.activeSpanProcessor as
598601
| (SpanProcessor & { _spanProcessors?: SpanProcessor[] })

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Integration | Transactions', () => {
2020
it('correctly creates transaction & spans', async () => {
2121
const beforeSendTransaction = jest.fn(() => null);
2222

23-
mockSdkInit({ enableTracing: true, beforeSendTransaction, debug: true });
23+
mockSdkInit({ enableTracing: true, beforeSendTransaction });
2424

2525
const client = getClient() as TestClientInterface;
2626

0 commit comments

Comments
 (0)