Skip to content

Commit b3bd16b

Browse files
committed
WIP name inferral
1 parent c6e3775 commit b3bd16b

73 files changed

Lines changed: 370 additions & 768 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev-packages/node-integration-tests/suites/express/tracing/updateName/scenario.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ app.get('/test/:id/span-updateName', (_req, res) => {
1818
res.send({ response: 'response 1' });
1919
});
2020

21-
app.get('/test/:id/span-updateName-source', (_req, res) => {
22-
const span = Sentry.getActiveSpan();
23-
const rootSpan = Sentry.getRootSpan(span);
24-
rootSpan.updateName('new-name');
25-
rootSpan.setAttribute(Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom');
26-
res.send({ response: 'response 2' });
27-
});
28-
2921
app.get('/test/:id/updateSpanName', (_req, res) => {
3022
const span = Sentry.getActiveSpan();
3123
const rootSpan = Sentry.getRootSpan(span);

dev-packages/node-integration-tests/suites/express/tracing/updateName/test.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@ describe('express tracing - updateName', () => {
1212
// This test documents the unfortunate behaviour of using `span.updateName` on the server-side.
1313
// For http.server root spans (which is the root span on the server 99% of the time), Otel's http instrumentation
1414
// calls `span.updateName` and overwrites whatever the name was set to before (by us or by users).
15-
test("calling just `span.updateName` doesn't update the final name in express (missing source)", async () => {
16-
const runner = createRunner()
17-
.expect({
18-
transaction: {
19-
transaction: 'GET /test/:id/span-updateName',
20-
transaction_info: {
21-
source: 'route',
22-
},
23-
},
24-
})
25-
.start();
26-
runner.makeRequest('get', '/test/123/span-updateName');
27-
await runner.completed();
28-
});
29-
30-
// Also calling `updateName` AND setting a source doesn't change anything - Otel has no concept of source, this is sentry-internal.
31-
// Therefore, only the source is updated but the name is still overwritten by Otel.
32-
test('calling `span.updateName` and setting attribute source updates the final name in express', async () => {
15+
test('calling just `span.updateName` updates the final name in express', async () => {
3316
const runner = createRunner()
3417
.expect({
3518
transaction: {
@@ -40,7 +23,7 @@ describe('express tracing - updateName', () => {
4023
},
4124
})
4225
.start();
43-
runner.makeRequest('get', '/test/123/span-updateName-source');
26+
runner.makeRequest('get', '/test/123/span-updateName');
4427
await runner.completed();
4528
});
4629

dev-packages/node-integration-tests/suites/public-api/startSpan/basic-usage-streamed/test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ test('sends a streamed span envelope with correct spans for a manually started s
6969
[SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: { type: 'string', value: '1.0.0' },
7070
[SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: { type: 'string', value: 'production' },
7171
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: { type: 'string', value: 'manual' },
72-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: { type: 'string', value: 'custom' },
7372
},
7473
name: 'test-child-span',
7574
is_segment: false,
@@ -93,7 +92,6 @@ test('sends a streamed span envelope with correct spans for a manually started s
9392
[SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: { type: 'string', value: '1.0.0' },
9493
[SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: { type: 'string', value: 'production' },
9594
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: { type: 'string', value: 'manual' },
96-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: { type: 'string', value: 'custom' },
9795
},
9896
links: [
9997
{
@@ -130,7 +128,6 @@ test('sends a streamed span envelope with correct spans for a manually started s
130128
[SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: { type: 'string', value: '1.0.0' },
131129
[SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: { type: 'string', value: 'production' },
132130
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: { type: 'string', value: 'manual' },
133-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: { type: 'string', value: 'custom' },
134131
},
135132
name: 'test-manual-span',
136133
is_segment: false,

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-invalid-root-span.mjs

Lines changed: 0 additions & 22 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
import * as Sentry from '@sentry/node';
22

3-
const tracer = Sentry.getClient().tracer;
4-
53
async function run() {
64
const { createApolloServer } = await import('../../apollo-server.mjs');
75
const server = createApolloServer();
86

9-
await tracer.startActiveSpan(
10-
'test span name',
11-
{
12-
kind: 1,
13-
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
14-
},
15-
async span => {
16-
for (let i = 1; i < 10; i++) {
17-
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
18-
await server.executeOperation({
19-
query: `query GetHello${i} {hello}`,
20-
});
21-
}
7+
await Sentry.startSpan({ name: 'test span name' }, async span => {
8+
for (let i = 1; i < 10; i++) {
9+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
10+
await server.executeOperation({
11+
query: `query GetHello${i} {hello}`,
12+
});
13+
}
2214

23-
setTimeout(() => {
24-
span.end();
25-
server.stop();
26-
}, 500);
27-
},
28-
);
15+
setTimeout(() => {
16+
span.end();
17+
server.stop();
18+
}, 500);
19+
});
2920
}
3021

3122
run();
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
import * as Sentry from '@sentry/node';
22

3-
const tracer = Sentry.getClient().tracer;
4-
53
async function run() {
64
const { createApolloServer } = await import('../../apollo-server.mjs');
75
const server = createApolloServer();
86

9-
await tracer.startActiveSpan(
10-
'test span name',
11-
{
12-
kind: 1,
13-
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
14-
},
15-
async span => {
16-
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
17-
await server.executeOperation({
18-
query: 'query GetWorld {world}',
19-
});
7+
await Sentry.startSpan({ name: 'test span name' }, async span => {
8+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
9+
await server.executeOperation({
10+
query: 'query GetWorld {world}',
11+
});
2012

21-
await server.executeOperation({
22-
query: 'query GetHello {hello}',
23-
});
13+
await server.executeOperation({
14+
query: 'query GetHello {hello}',
15+
});
2416

25-
setTimeout(() => {
26-
span.end();
27-
server.stop();
28-
}, 500);
29-
},
30-
);
17+
setTimeout(() => {
18+
span.end();
19+
server.stop();
20+
}, 500);
21+
});
3122
}
3223

3324
run();
Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
import * as Sentry from '@sentry/node';
22
import gql from 'graphql-tag';
33

4-
const tracer = Sentry.getClient().tracer;
5-
64
async function run() {
75
const { createApolloServer } = await import('../../apollo-server.mjs');
86
const server = createApolloServer();
97

10-
await tracer.startActiveSpan(
11-
'test span name',
12-
{
13-
kind: 1,
14-
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
15-
},
16-
async span => {
17-
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
18-
await server.executeOperation({
19-
query: gql`
20-
mutation TestMutation($email: String) {
21-
login(email: $email)
22-
}
23-
`,
24-
variables: { email: 'test@email.com' },
25-
});
8+
await Sentry.startSpan({ name: 'test span name' }, async span => {
9+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
10+
await server.executeOperation({
11+
query: gql`
12+
mutation TestMutation($email: String) {
13+
login(email: $email)
14+
}
15+
`,
16+
variables: { email: 'test@email.com' },
17+
});
2618

27-
setTimeout(() => {
28-
span.end();
29-
server.stop();
30-
}, 500);
31-
},
32-
);
19+
setTimeout(() => {
20+
span.end();
21+
server.stop();
22+
}, 500);
23+
});
3324
}
3425

3526
run();
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import * as Sentry from '@sentry/node';
22

3-
const tracer = Sentry.getClient().tracer;
4-
53
async function run() {
64
const { createApolloServer } = await import('../../apollo-server.mjs');
75
const server = createApolloServer();
86

9-
await tracer.startActiveSpan(
10-
'test span name',
11-
{
12-
kind: 1,
13-
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
14-
},
15-
async span => {
16-
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
17-
await server.executeOperation({
18-
query: 'query {hello}',
19-
});
7+
await Sentry.startSpan({ name: 'test span name' }, async span => {
8+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
9+
await server.executeOperation({
10+
query: 'query {hello}',
11+
});
2012

21-
setTimeout(() => {
22-
span.end();
23-
server.stop();
24-
}, 500);
25-
},
26-
);
13+
setTimeout(() => {
14+
span.end();
15+
server.stop();
16+
}, 500);
17+
});
2718
}
2819

2920
run();
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import * as Sentry from '@sentry/node';
22

3-
const tracer = Sentry.getClient().tracer;
4-
53
async function run() {
64
const { createApolloServer } = await import('../../apollo-server.mjs');
75
const server = createApolloServer();
86

9-
await tracer.startActiveSpan(
10-
'test span name',
11-
{
12-
kind: 1,
13-
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
14-
},
15-
async span => {
16-
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
17-
await server.executeOperation({
18-
query: 'query GetHello {hello}',
19-
});
7+
await Sentry.startSpan({ name: 'test span name' }, async span => {
8+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
9+
await server.executeOperation({
10+
query: 'query GetHello {hello}',
11+
});
2012

21-
setTimeout(() => {
22-
span.end();
23-
server.stop();
24-
}, 500);
25-
},
26-
);
13+
setTimeout(() => {
14+
span.end();
15+
server.stop();
16+
}, 500);
17+
});
2718
}
2819

2920
run();

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/test.ts

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
1313

1414
describe('single query operation', () => {
1515
const EXPECTED_TRANSACTION = {
16-
transaction: 'GET /test-graphql (query GetHello)',
16+
transaction: 'test span name (query GetHello)',
1717
spans: expect.arrayContaining([
1818
expect.objectContaining({
1919
data: {
@@ -42,7 +42,7 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
4242

4343
describe('single mutation operation', () => {
4444
const EXPECTED_TRANSACTION = {
45-
transaction: 'GET /test-graphql (mutation TestMutation)',
45+
transaction: 'test span name (mutation TestMutation)',
4646
spans: expect.arrayContaining([
4747
expect.objectContaining({
4848
data: {
@@ -71,38 +71,9 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
7171
});
7272
});
7373

74-
describe('invalid root span', () => {
75-
const EXPECTED_TRANSACTION = {
76-
transaction: 'test span name (query GetHello)',
77-
spans: expect.arrayContaining([
78-
expect.objectContaining({
79-
data: {
80-
'graphql.operation.name': 'GetHello',
81-
'graphql.operation.type': 'query',
82-
'graphql.source': 'query GetHello {hello}',
83-
'sentry.origin': 'auto.graphql.otel.graphql',
84-
},
85-
description: 'query GetHello',
86-
status: 'ok',
87-
origin: 'auto.graphql.otel.graphql',
88-
}),
89-
]),
90-
};
91-
92-
createEsmAndCjsTests(__dirname, 'scenario-invalid-root-span.mjs', 'instrument.mjs', (createTestRunner, test) => {
93-
test('useOperationNameForRootSpan ignores an invalid root span', async () => {
94-
await createTestRunner()
95-
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
96-
.expect({ transaction: EXPECTED_TRANSACTION })
97-
.start()
98-
.completed();
99-
});
100-
});
101-
});
102-
10374
describe('query without name', () => {
10475
const EXPECTED_TRANSACTION = {
105-
transaction: 'GET /test-graphql (query)',
76+
transaction: 'test span name (query)',
10677
spans: expect.arrayContaining([
10778
expect.objectContaining({
10879
data: {
@@ -130,7 +101,7 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
130101

131102
describe('multiple operations', () => {
132103
const EXPECTED_TRANSACTION = {
133-
transaction: 'GET /test-graphql (query GetHello, query GetWorld)',
104+
transaction: 'test span name (query GetHello, query GetWorld)',
134105
spans: expect.arrayContaining([
135106
expect.objectContaining({
136107
data: {
@@ -171,7 +142,7 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
171142
describe('many operations', () => {
172143
const EXPECTED_TRANSACTION = {
173144
transaction:
174-
'GET /test-graphql (query GetHello1, query GetHello2, query GetHello3, query GetHello4, query GetHello5, +4)',
145+
'test span name (query GetHello1, query GetHello2, query GetHello3, query GetHello4, query GetHello5, +4)',
175146
};
176147

177148
createEsmAndCjsTests(

0 commit comments

Comments
 (0)