Skip to content

Commit 648b60d

Browse files
committed
add otel test
1 parent 5ea5d93 commit 648b60d

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
tracesSampleRate: 1.0,
7+
transport: loggingTransport,
8+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
const tracer = Sentry.getClient().tracer;
4+
5+
async function run() {
6+
await tracer.startActiveSpan('test span name', async span => {
7+
try {
8+
throw new Error('Test error from tracer.startActiveSpan');
9+
} finally {
10+
span.end();
11+
}
12+
});
13+
}
14+
15+
run();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { afterAll, describe, expect } from 'vitest';
2+
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
3+
4+
describe('tracer.startActiveSpan errors', () => {
5+
afterAll(() => {
6+
cleanupChildProcesses();
7+
});
8+
9+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
10+
// When a callback to raw OTel `tracer.startActiveSpan` throws and the error propagates
11+
// (uncaught), the span status is NOT automatically marked as errored. The user's `finally`
12+
// calls `span.end()` before the error propagates, and an OTel span becomes immutable on end.
13+
//
14+
// Users who want auto-status-on-error should use `Sentry.startSpan` instead, or follow the
15+
// OTel-idiomatic pattern: `span.recordException(err); span.setStatus({ code: ERROR })` in a
16+
// `catch` inside the callback.
17+
test('does NOT mark span errored when uncaught error escapes raw tracer.startActiveSpan callback (status quo)', async () => {
18+
await createRunner()
19+
.expect({
20+
transaction: {
21+
transaction: 'test span name',
22+
contexts: {
23+
trace: {
24+
status: 'ok',
25+
},
26+
},
27+
},
28+
})
29+
.start()
30+
.completed();
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)