Skip to content

Commit c8e81d5

Browse files
authored
feat(opentelemetry): Stop looking at propagation context for span creation (#14481)
This PR changes the behavior of the OTEL-based Node SDK to ignore the propagation context when starting spans. Previously, when you called `startSpan` and there was no incoming trace, we would ensure that the new span has the trace ID + span ID from the propagation context. This has a few problems: 1. Multiple parallel root spans will continue the same virtual trace, instead of having separate traces. 2. This is really invalid in OTEL, as we have to provide a span ID and cannot really tell it to use a specific trace ID out of the box. Because of this, we had to add a bunch of special handling to ensure we can differentiate real and fake parent span IDs properly. This PR fixes this by simply not looking at this anymore. For TWP and error marking the propagation context is still used as before, only for new spans is there a difference. I also added docs explaining how trace propagation in node works now: ![node-sdk-trace-propagation-3](https://github.com/user-attachments/assets/73cc5972-2d2a-438c-9c32-2551fc52568e)
1 parent 97abe0a commit c8e81d5

File tree

37 files changed

+433
-329
lines changed

37 files changed

+433
-329
lines changed

dev-packages/e2e-tests/test-applications/nestjs-8/tests/errors.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
2626
expect(errorEvent.contexts?.trace).toEqual({
2727
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2828
span_id: expect.stringMatching(/[a-f0-9]{16}/),
29+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2930
});
3031
});
3132

dev-packages/e2e-tests/test-applications/nestjs-basic-with-graphql/tests/errors.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
2626
expect(errorEvent.contexts?.trace).toEqual({
2727
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2828
span_id: expect.stringMatching(/[a-f0-9]{16}/),
29+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2930
});
3031
});
3132

@@ -114,5 +115,6 @@ test('Sends graphql exception to Sentry', async ({ baseURL }) => {
114115
expect(errorEvent.contexts?.trace).toEqual({
115116
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
116117
span_id: expect.stringMatching(/[a-f0-9]{16}/),
118+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
117119
});
118120
});

dev-packages/e2e-tests/test-applications/nestjs-basic/tests/errors.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
2626
expect(errorEvent.contexts?.trace).toEqual({
2727
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2828
span_id: expect.stringMatching(/[a-f0-9]{16}/),
29+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2930
});
3031
});
3132

dev-packages/e2e-tests/test-applications/nestjs-graphql/tests/errors.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
4545
expect(errorEvent.contexts?.trace).toEqual({
4646
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
4747
span_id: expect.stringMatching(/[a-f0-9]{16}/),
48+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
4849
});
4950
});

dev-packages/e2e-tests/test-applications/nestjs-with-submodules-decorator/tests/errors.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test('Sends unexpected exception to Sentry if thrown in module with global filte
3434
expect(errorEvent.contexts?.trace).toEqual({
3535
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
3636
span_id: expect.stringMatching(/[a-f0-9]{16}/),
37+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
3738
});
3839
});
3940

@@ -70,6 +71,7 @@ test('Sends unexpected exception to Sentry if thrown in module with local filter
7071
expect(errorEvent.contexts?.trace).toEqual({
7172
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
7273
span_id: expect.stringMatching(/[a-f0-9]{16}/),
74+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
7375
});
7476
});
7577

@@ -108,6 +110,7 @@ test('Sends unexpected exception to Sentry if thrown in module that was register
108110
expect(errorEvent.contexts?.trace).toEqual({
109111
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
110112
span_id: expect.stringMatching(/[a-f0-9]{16}/),
113+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
111114
});
112115
});
113116

dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/errors.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('Sends unexpected exception to Sentry if thrown in module with global filte
2626
expect(errorEvent.contexts?.trace).toEqual({
2727
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2828
span_id: expect.stringMatching(/[a-f0-9]{16}/),
29+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2930
});
3031
});
3132

@@ -54,6 +55,7 @@ test('Sends unexpected exception to Sentry if thrown in module with local filter
5455
expect(errorEvent.contexts?.trace).toEqual({
5556
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
5657
span_id: expect.stringMatching(/[a-f0-9]{16}/),
58+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
5759
});
5860
});
5961

@@ -84,6 +86,7 @@ test('Sends unexpected exception to Sentry if thrown in module that was register
8486
expect(errorEvent.contexts?.trace).toEqual({
8587
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
8688
span_id: expect.stringMatching(/[a-f0-9]{16}/),
89+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
8790
});
8891
});
8992

dev-packages/e2e-tests/test-applications/node-fastify-5/tests/errors.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ test('Sends correct error event', async ({ baseURL }) => {
2525
expect(errorEvent.contexts?.trace).toEqual({
2626
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2727
span_id: expect.stringMatching(/[a-f0-9]{16}/),
28+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2829
});
2930
});

dev-packages/e2e-tests/test-applications/node-fastify/tests/errors.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ test('Sends correct error event', async ({ baseURL }) => {
2525
expect(errorEvent.contexts?.trace).toEqual({
2626
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2727
span_id: expect.stringMatching(/[a-f0-9]{16}/),
28+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2829
});
2930
});

dev-packages/e2e-tests/test-applications/node-koa/tests/assert.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('Returns 400 from failed assert', async ({ baseURL }) => {
2626
expect(errorEvent.contexts?.trace).toEqual({
2727
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2828
span_id: expect.stringMatching(/[a-f0-9]{16}/),
29+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2930
});
3031
});
3132

dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ test('Sends correct error event', async ({ baseURL }) => {
2525
expect(errorEvent.contexts?.trace).toEqual({
2626
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2727
span_id: expect.stringMatching(/[a-f0-9]{16}/),
28+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2829
});
2930
});

0 commit comments

Comments
 (0)