Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(opentelemetry): Allow skipping of span data inference #12779

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading