Skip to content

Commit e706b54

Browse files
committed
move assertions around with new client
1 parent c6ebbce commit e706b54

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

packages/opentelemetry-node/test/spanprocessor.test.ts

+25-27
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,20 @@ describe('SentrySpanProcessor', () => {
766766
});
767767

768768
it('associates an error to a transaction', () => {
769-
let sentryEvent: any;
770769
let otelSpan: any;
771770

771+
expect.assertions(3);
772+
772773
client = new NodeClient({
773774
...DEFAULT_NODE_CLIENT_OPTIONS,
774-
beforeSend: event => {
775-
sentryEvent = event;
775+
beforeSend: sentryEvent => {
776+
expect(sentryEvent).toBeDefined();
777+
expect(sentryEvent.exception).toBeDefined();
778+
expect(sentryEvent.contexts?.trace).toEqual({
779+
parent_span_id: otelSpan.parentSpanId,
780+
span_id: otelSpan.spanContext().spanId,
781+
trace_id: otelSpan.spanContext().traceId,
782+
});
776783
return null;
777784
},
778785
});
@@ -790,24 +797,28 @@ describe('SentrySpanProcessor', () => {
790797

791798
parentOtelSpan.end();
792799
});
793-
794-
expect(sentryEvent).toBeDefined();
795-
expect(sentryEvent.exception).toBeDefined();
796-
expect(sentryEvent.contexts.trace).toEqual({
797-
parent_span_id: otelSpan.parentSpanId,
798-
span_id: otelSpan.spanContext().spanId,
799-
trace_id: otelSpan.spanContext().traceId,
800-
});
801800
});
802801

803802
it('generates Sentry errors from opentelemetry span exception events', () => {
804-
let sentryEvent: any;
805803
let otelSpan: any;
806804

805+
expect.assertions(4);
806+
807807
client = new NodeClient({
808808
...DEFAULT_NODE_CLIENT_OPTIONS,
809-
beforeSend: event => {
810-
sentryEvent = event;
809+
beforeSend: sentryEvent => {
810+
expect(sentryEvent).toBeDefined();
811+
expect(sentryEvent.exception).toBeDefined();
812+
expect(sentryEvent.exception?.values?.[0]).toEqual({
813+
mechanism: expect.any(Object),
814+
type: 'Error',
815+
value: 'this is an otel error!',
816+
});
817+
expect(sentryEvent.contexts?.trace).toEqual({
818+
parent_span_id: otelSpan.parentSpanId,
819+
span_id: otelSpan.spanContext().spanId,
820+
trace_id: otelSpan.spanContext().traceId,
821+
});
811822
return null;
812823
},
813824
});
@@ -825,19 +836,6 @@ describe('SentrySpanProcessor', () => {
825836

826837
parentOtelSpan.end();
827838
});
828-
829-
expect(sentryEvent).toBeDefined();
830-
expect(sentryEvent.exception).toBeDefined();
831-
expect(sentryEvent.exception.values[0]).toEqual({
832-
mechanism: expect.any(Object),
833-
type: 'Error',
834-
value: 'this is an otel error!',
835-
});
836-
expect(sentryEvent.contexts.trace).toEqual({
837-
parent_span_id: otelSpan.parentSpanId,
838-
span_id: otelSpan.spanContext().spanId,
839-
trace_id: otelSpan.spanContext().traceId,
840-
});
841839
});
842840

843841
// Regression test for https://github.com/getsentry/sentry-javascript/issues/7538

0 commit comments

Comments
 (0)