Skip to content
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
21 changes: 19 additions & 2 deletions packages/opentelemetry/src/utils/parseSpanDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import {
URL_QUERY,
} from '@sentry/conventions/attributes';
import {
GENERAL_FUNCTION_SPAN_OP,
MESSAGING_QUEUE_PROCESS_SPAN_OP,
MESSAGING_QUEUE_PUBLISH_SPAN_OP,
MESSAGING_QUEUE_RECEIVE_SPAN_OP,
MESSAGING_QUEUE_SPAN_OP,
WEB_SERVER_HTTP_SERVER_SPAN_OP,
} from '@sentry/conventions/op';
import type { Span, SpanAttributes } from '@sentry/core';
import {
Expand Down Expand Up @@ -81,17 +83,32 @@ export function inferSpanData(attributes: SpanAttributes): SpanDescription {
}

// If faas.trigger exists then this is a function as a service span.
// eslint-disable-next-line typescript/no-deprecated
const faasTrigger = attributes[FAAS_TRIGGER];
if (faasTrigger) {
return {
op: faasTrigger.toString(),
op: getFaasOp(faasTrigger),
};
}

return { op: undefined };
}

/**
* Maps an OTel `faas.trigger` to a registered span op. `http` triggers are inbound HTTP requests and
* `pubsub` triggers process queued messages; everything else (`timer`, `datasource`, `other`, or any
* non-conformant value) is a plain function invocation.
*/
function getFaasOp(trigger: unknown): string {
switch (trigger) {
case 'http':
return WEB_SERVER_HTTP_SERVER_SPAN_OP;
case 'pubsub':
return MESSAGING_QUEUE_PROCESS_SPAN_OP;
default:
return GENERAL_FUNCTION_SPAN_OP;
}
}

/**
* Maps an OTel `messaging.operation.type` to the corresponding `queue.*` span op. `send` is the
* pre-1.0 spelling of `publish`; both map to `queue.publish`. Unknown or missing types fall back to
Expand Down
28 changes: 23 additions & 5 deletions packages/opentelemetry/test/utils/parseSpanDescription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,30 @@ describe('inferSpanData', () => {
},
],
[
'works with faas trigger',
'works with http faas trigger',
{
[FAAS_TRIGGER]: 'http',
},
{
op: 'http.server',
},
],
[
'works with pubsub faas trigger',
{
[FAAS_TRIGGER]: 'pubsub',
},
{
op: 'queue.process',
},
],
[
'falls back to function op for unknown faas trigger',
{
[FAAS_TRIGGER]: 'test-faas-trigger',
},
{
op: 'test-faas-trigger',
op: 'function',
},
],
[
Expand All @@ -244,7 +262,7 @@ describe('inferSpanData', () => {
[FAAS_TRIGGER]: 'test-faas-trigger',
},
{
op: 'test-faas-trigger',
op: 'function',
},
],
[
Expand All @@ -255,7 +273,7 @@ describe('inferSpanData', () => {
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
},
{
op: 'test-faas-trigger',
op: 'function',
},
],
[
Expand All @@ -266,7 +284,7 @@ describe('inferSpanData', () => {
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
},
{
op: 'test-faas-trigger',
op: 'function',
Comment thread
msonnb marked this conversation as resolved.
},
],
] as const)('%s', (_, attributes, expected) => {
Expand Down
Loading