Skip to content

Commit

Permalink
feat(opentelemetry): Allow skipping of span data inference (#12779)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Jul 5, 2024
1 parent 552fc2a commit 15230f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/opentelemetry/src/utils/parseSpanDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface SpanDescription {
op: string | undefined;
description: string;
source: TransactionSource;
data?: Record<string, string>;
data?: Record<string, string | undefined>;
}

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

// This attribute is intentionally exported as a SEMATTR constant because it should stay intimite API
if (attributes['sentry.skip_span_data_inference']) {
return {
op: undefined,
description: name,
source: 'custom',
data: {
// Suggest to callers of `parseSpanDescription` to wipe the hint because it is unnecessary data in the end.
'sentry.skip_span_data_inference': undefined,
},
};
}

// if http.method exists, this is an http request span
//
// TODO: Referencing `http.request.method` is a temporary workaround until the semantic
Expand Down
21 changes: 21 additions & 0 deletions packages/opentelemetry/test/utils/parseSpanDescription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ describe('parseSpanDescription', () => {
source: 'route',
},
],
[
"should not do any data parsing when the 'sentry.skip_span_data_inference' attribute is set",
{
'sentry.skip_span_data_inference': true,

// All of these should be ignored
[SEMATTRS_HTTP_METHOD]: 'GET',
[SEMATTRS_DB_SYSTEM]: 'mysql',
[SEMATTRS_DB_STATEMENT]: 'SELECT * from users',
},
'test name',
undefined,
{
op: undefined,
description: 'test name',
source: 'custom',
data: {
'sentry.skip_span_data_inference': undefined,
},
},
],
])('%s', (_, attributes, name, kind, expected) => {
const actual = parseSpanDescription({ attributes, kind, name } as unknown as Span);
expect(actual).toEqual(expected);
Expand Down

0 comments on commit 15230f1

Please sign in to comment.