Skip to content

Commit 15230f1

Browse files
author
Luca Forstner
authored
feat(opentelemetry): Allow skipping of span data inference (#12779)
1 parent 552fc2a commit 15230f1

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/opentelemetry/src/utils/parseSpanDescription.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface SpanDescription {
2323
op: string | undefined;
2424
description: string;
2525
source: TransactionSource;
26-
data?: Record<string, string>;
26+
data?: Record<string, string | undefined>;
2727
}
2828

2929
/**
@@ -35,6 +35,19 @@ export function parseSpanDescription(span: AbstractSpan): SpanDescription {
3535
const attributes = spanHasAttributes(span) ? span.attributes : {};
3636
const name = spanHasName(span) ? span.name : '<unknown>';
3737

38+
// This attribute is intentionally exported as a SEMATTR constant because it should stay intimite API
39+
if (attributes['sentry.skip_span_data_inference']) {
40+
return {
41+
op: undefined,
42+
description: name,
43+
source: 'custom',
44+
data: {
45+
// Suggest to callers of `parseSpanDescription` to wipe the hint because it is unnecessary data in the end.
46+
'sentry.skip_span_data_inference': undefined,
47+
},
48+
};
49+
}
50+
3851
// if http.method exists, this is an http request span
3952
//
4053
// TODO: Referencing `http.request.method` is a temporary workaround until the semantic

packages/opentelemetry/test/utils/parseSpanDescription.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,27 @@ describe('parseSpanDescription', () => {
132132
source: 'route',
133133
},
134134
],
135+
[
136+
"should not do any data parsing when the 'sentry.skip_span_data_inference' attribute is set",
137+
{
138+
'sentry.skip_span_data_inference': true,
139+
140+
// All of these should be ignored
141+
[SEMATTRS_HTTP_METHOD]: 'GET',
142+
[SEMATTRS_DB_SYSTEM]: 'mysql',
143+
[SEMATTRS_DB_STATEMENT]: 'SELECT * from users',
144+
},
145+
'test name',
146+
undefined,
147+
{
148+
op: undefined,
149+
description: 'test name',
150+
source: 'custom',
151+
data: {
152+
'sentry.skip_span_data_inference': undefined,
153+
},
154+
},
155+
],
135156
])('%s', (_, attributes, name, kind, expected) => {
136157
const actual = parseSpanDescription({ attributes, kind, name } as unknown as Span);
137158
expect(actual).toEqual(expected);

0 commit comments

Comments
 (0)