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
1 change: 1 addition & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ The following span names were adjusted:
| `http.client`, `http.client.stream` | The request method and sanitized URL | `GET https://api.example.com/users/123` | The request method and the domain, or just the method if there is no domain | `GET api.example.com`, `GET` |
| `router` | Framework-specific, sometimes containing the raw URL | `/users/123`, `SvelteKit Route Change` | The span's `http.route`, or `Router` if the SDK has none | `/users/:id`, `Router` |
| `handler` | Framework-specific, often carrying the request method | `GET /users/:id`, `route-handler`, `getUser` | The span's `http.route`, or `Request handler` if the SDK has none | `/users/:id`, `Request handler` |
| `function` (Angular `TraceMethod`) | The decorator's `name` option in angle brackets | `<getUser>`, `<unnamed>` | The decorator's `name` option, or `Function execution` if it has none | `Login.ngOnInit`, `getUsers`, `Function execution` |
| `function.gcp` | The request method and path for HTTP functions, otherwise the trigger's event or trigger type | `POST /users`, `google.pubsub.topic.publish`, `firebase.function.http.request` | The function name, or `Serverless function execution` if the SDK cannot resolve one | `myFunction`, `Serverless function execution` |
| `function.aws` | The Lambda function name | `my-function` | Unchanged, except that the SDK now falls back to `Serverless function execution` if it cannot resolve the function name | `my-function`, `Serverless function execution` |
| `graphql` | The graphql phase and, for operations, the operation name | `query GetUser`, `graphql.parse`, `graphql.resolve user.0.name` | The operation type, or the processing type where there is none | `GraphQL query`, `GraphQL parse`, `GraphQL resolve` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@ test.describe('TraceMethod Decorator', () => {
expect(ngInitSpan).toBeDefined();
expect(ngInitSpan).toEqual(
expect.objectContaining({
name: '<ngOnInit>',
name: 'ngOnInit',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'code.function.name': { type: 'string', value: 'ngOnInit' },
'sentry.description': { type: 'string', value: '<ngOnInit>' },
}),
}),
);
Expand Down Expand Up @@ -393,10 +394,11 @@ test.describe('TraceMethod Decorator', () => {
expect(ngAfterViewInitSpan).toBeDefined();
expect(ngAfterViewInitSpan).toEqual(
expect.objectContaining({
name: '<unnamed>',
name: 'Function execution',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'sentry.description': { type: 'string', value: '<unnamed>' },
'code.function.name': { type: 'string', value: 'ngAfterViewInit' },
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,12 @@ test.describe('TraceMethod Decorator', () => {
expect(ngInitSpan).toBeDefined();
expect(ngInitSpan).toEqual(
expect.objectContaining({
name: '<ngOnInit>',
name: 'ngOnInit',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'code.function.name': { type: 'string', value: 'ngOnInit' },
'sentry.description': { type: 'string', value: '<ngOnInit>' },
}),
}),
);
Expand Down Expand Up @@ -383,10 +384,11 @@ test.describe('TraceMethod Decorator', () => {
expect(ngAfterViewInitSpan).toBeDefined();
expect(ngAfterViewInitSpan).toEqual(
expect.objectContaining({
name: '<unnamed>',
name: 'Function execution',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'sentry.description': { type: 'string', value: '<unnamed>' },
'code.function.name': { type: 'string', value: 'ngAfterViewInit' },
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@ test.describe('TraceMethod Decorator', () => {
expect(ngInitSpan).toBeDefined();
expect(ngInitSpan).toEqual(
expect.objectContaining({
name: '<ngOnInit>',
name: 'ngOnInit',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'code.function.name': { type: 'string', value: 'ngOnInit' },
'sentry.description': { type: 'string', value: '<ngOnInit>' },
}),
}),
);
Expand Down Expand Up @@ -393,10 +394,11 @@ test.describe('TraceMethod Decorator', () => {
expect(ngAfterViewInitSpan).toBeDefined();
expect(ngAfterViewInitSpan).toEqual(
expect.objectContaining({
name: '<unnamed>',
name: 'Function execution',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'sentry.description': { type: 'string', value: '<unnamed>' },
'code.function.name': { type: 'string', value: 'ngAfterViewInit' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q/l: why is this gone? the implementation falls back to the value we used before so iiuc the value should still be there

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it back. I removed the logic to set this previously because I thought it was weird that span description was unnamed but we had this attribute. I then walked back on this to keep as much information as possible but forgot to read the assertion 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only an issue if users don't pass a name to the decorator, which is generally what we recommend to avoid mangled/minified function names

}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@ test.describe('TraceMethod Decorator', () => {
expect(ngInitSpan).toBeDefined();
expect(ngInitSpan).toEqual(
expect.objectContaining({
name: '<ngOnInit>',
name: 'ngOnInit',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'code.function.name': { type: 'string', value: 'ngOnInit' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for instance here we keep the assertion

'sentry.description': { type: 'string', value: '<ngOnInit>' },
}),
}),
);
Expand Down Expand Up @@ -393,10 +394,11 @@ test.describe('TraceMethod Decorator', () => {
expect(ngAfterViewInitSpan).toBeDefined();
expect(ngAfterViewInitSpan).toEqual(
expect.objectContaining({
name: '<unnamed>',
name: 'Function execution',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'sentry.description': { type: 'string', value: '<unnamed>' },
'code.function.name': { type: 'string', value: 'ngAfterViewInit' },
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ test.describe('TraceMethod Decorator', () => {
expect(ngInitSpan).toBeDefined();
expect(ngInitSpan).toEqual(
expect.objectContaining({
name: '<ngOnInit>',
name: 'ngOnInit',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'code.function.name': { type: 'string', value: 'ngOnInit' },
'sentry.description': { type: 'string', value: '<ngOnInit>' },
}),
}),
);
Expand Down Expand Up @@ -393,10 +393,11 @@ test.describe('TraceMethod Decorator', () => {
expect(ngAfterViewInitSpan).toBeDefined();
expect(ngAfterViewInitSpan).toEqual(
expect.objectContaining({
name: '<unnamed>',
name: 'Function execution',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'function' },
'sentry.origin': { type: 'string', value: 'auto.ui.angular.trace_method_decorator' },
'sentry.description': { type: 'string', value: '<unnamed>' },
'code.function.name': { type: 'string', value: 'ngAfterViewInit' },
}),
}),
Expand Down
16 changes: 14 additions & 2 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
URL_FULL,
URL_PATH,
URL_TEMPLATE,
SENTRY_DESCRIPTION,
} from '@sentry/conventions/attributes';
import { FUNCTION, ROUTER } from '@sentry/conventions/op';
import type { Integration, Span } from '@sentry/core';
Expand All @@ -39,6 +40,7 @@ import {
stripUrlQueryAndFragment,
timestampInSeconds,
filterCollectedUrl,
FUNCTION_SPAN_NAME_FALLBACK,
} from '@sentry/core';
import type { Observable } from 'rxjs';
import { Subscription } from 'rxjs';
Expand Down Expand Up @@ -404,15 +406,25 @@ export function TraceMethod(options?: TraceMethodOptions): MethodDecorator {
descriptor.value = function (...args: unknown[]): ReturnType<typeof originalMethod> {
const now = timestampInSeconds();

const methodName = options?.name;
const description = `<${methodName || 'unnamed'}>`;

const client = getClient();
const hasSpanStreaming = client && hasSpanStreamingEnabled(client);
const name = hasSpanStreaming ? methodName || FUNCTION_SPAN_NAME_FALLBACK : description;

runOutsideAngular(() => {
startInactiveSpan({
onlyIfParent: true,
name: `<${options?.name ? options.name : 'unnamed'}>`,
name,
Comment thread
cursor[bot] marked this conversation as resolved.
startTime: now,
attributes: {
[SENTRY_OP]: FUNCTION,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_method_decorator',
[CODE_FUNCTION_NAME]: String(propertyKey),
// override description inference by Relay to preserve the original (transaction-based) description.
// sentry-conventions can't map the special case with the angle brackets.
...(hasSpanStreaming && { [SENTRY_DESCRIPTION]: description }),
[CODE_FUNCTION_NAME]: methodName || String(propertyKey),
},
}).end(now);
});
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/tracing/spans/spanNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export const REQUEST_HANDLER_SPAN_NAME_FALLBACK = 'Request handler';
*/
export const SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK = 'Serverless function execution';

/**
* Fallback name for function execution spans when no better-suited span name is available.
* @see https://getsentry.github.io/sentry-conventions/names/#function
*/
export const FUNCTION_SPAN_NAME_FALLBACK = 'Function execution';

/**
* The `cache.operation` attribute value each cache op carries. Cache span names are
* `cache.{{cache.operation}}`, so the op constant itself doubles as the low-cardinality span name.
Expand Down
Loading