-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(otel): Add trace info to error events (#6364)
- Loading branch information
1 parent
6e915c3
commit 2ed5f8f
Showing
2 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ import { SENTRY_SPAN_PROCESSOR_MAP, SentrySpanProcessor } from '../src/spanproce | |
|
||
const SENTRY_DSN = 'https://[email protected]/0'; | ||
|
||
const DEFAULT_NODE_CLIENT_OPTIONS = { | ||
dsn: SENTRY_DSN, | ||
integrations: [], | ||
transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => resolvedSyncPromise({})), | ||
stackParser: () => [], | ||
}; | ||
|
||
// Integration Test of SentrySpanProcessor | ||
|
||
beforeAll(() => { | ||
|
@@ -21,16 +28,12 @@ beforeAll(() => { | |
|
||
describe('SentrySpanProcessor', () => { | ||
let hub: Hub; | ||
let client: NodeClient; | ||
let provider: NodeTracerProvider; | ||
let spanProcessor: SentrySpanProcessor; | ||
|
||
beforeEach(() => { | ||
const client = new NodeClient({ | ||
dsn: SENTRY_DSN, | ||
integrations: [], | ||
transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => resolvedSyncPromise({})), | ||
stackParser: () => [], | ||
}); | ||
client = new NodeClient(DEFAULT_NODE_CLIENT_OPTIONS); | ||
hub = new Hub(client); | ||
makeMain(hub); | ||
|
||
|
@@ -711,6 +714,42 @@ describe('SentrySpanProcessor', () => { | |
}); | ||
}); | ||
}); | ||
|
||
it('associates an error to a transaction', () => { | ||
let sentryEvent: any; | ||
let otelSpan: any; | ||
|
||
client = new NodeClient({ | ||
...DEFAULT_NODE_CLIENT_OPTIONS, | ||
beforeSend: event => { | ||
sentryEvent = event; | ||
return null; | ||
}, | ||
}); | ||
hub = new Hub(client); | ||
makeMain(hub); | ||
|
||
const tracer = provider.getTracer('default'); | ||
|
||
tracer.startActiveSpan('GET /users', parentOtelSpan => { | ||
tracer.startActiveSpan('SELECT * FROM users;', child => { | ||
hub.captureException(new Error('oh nooooo!')); | ||
otelSpan = child as OtelSpan; | ||
child.end(); | ||
}); | ||
|
||
parentOtelSpan.end(); | ||
}); | ||
|
||
expect(sentryEvent).toBeDefined(); | ||
expect(sentryEvent.exception).toBeDefined(); | ||
expect(sentryEvent.contexts.trace).toEqual({ | ||
description: otelSpan.name, | ||
parent_span_id: otelSpan.parentSpanId, | ||
span_id: otelSpan.spanContext().spanId, | ||
trace_id: otelSpan.spanContext().traceId, | ||
}); | ||
}); | ||
}); | ||
|
||
// OTEL expects a custom date format | ||
|