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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('Transaction includes span and correct value for decorated async function',
data: {
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'wait and return a string',
'code.function.name': 'wait',
},
description: 'wait',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
Expand Down Expand Up @@ -59,6 +60,7 @@ test('Transaction includes span and correct value for decorated sync function',
data: {
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'return a string',
'code.function.name': 'getString',
},
description: 'getString',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('Trace includes span and correct value for decorated async function', async
attributes: expect.objectContaining({
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: 'wait and return a string' },
'code.function.name': { type: 'string', value: 'wait' },
}),
}),
);
Expand All @@ -44,6 +45,7 @@ test('Trace includes span and correct value for decorated sync function', async
attributes: expect.objectContaining({
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: 'return a string' },
'code.function.name': { type: 'string', value: 'getString' },
}),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function tracedSpan(segmentSpan: SerializedStreamedSpan, name: string, op: strin
: {}),
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: op },
'code.function.name': { type: 'string', value: name },
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('Trace includes span and correct value for decorated async function', async
attributes: expect.objectContaining({
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: 'wait and return a string' },
'code.function.name': { type: 'string', value: 'wait' },
}),
}),
);
Expand All @@ -44,6 +45,7 @@ test('Trace includes span and correct value for decorated sync function', async
attributes: expect.objectContaining({
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: 'return a string' },
'code.function.name': { type: 'string', value: 'getString' },
}),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function tracedSpan(segmentSpan: SerializedStreamedSpan, name: string, op: strin
: {}),
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: op },
'code.function.name': { type: 'string', value: name },
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('Trace includes span and correct value for decorated async function', async
attributes: expect.objectContaining({
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: 'wait and return a string' },
'code.function.name': { type: 'string', value: 'wait' },
}),
}),
);
Expand All @@ -44,6 +45,7 @@ test('Trace includes span and correct value for decorated sync function', async
attributes: expect.objectContaining({
'sentry.origin': { type: 'string', value: 'auto.function.nestjs.sentry_traced' },
'sentry.op': { type: 'string', value: 'return a string' },
'code.function.name': { type: 'string', value: 'getString' },
}),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ test('Sends streamed spans for an API route', async ({ baseURL }) => {
'sentry.origin': { type: 'string', value: 'auto.http.nestjs' },
component: { type: 'string', value: '@nestjs/core' },
'nestjs.type': { type: 'string', value: 'request_context' },
'code.function.name': { type: 'string', value: 'AppController.testTransaction' },
'nestjs.controller': { type: 'string', value: 'AppController' },
'nestjs.callback': { type: 'string', value: 'testTransaction' },
'http.route': { type: 'string', value: '/test-transaction' },
Expand Down Expand Up @@ -429,6 +430,7 @@ test('Sets error status on nest spans when a handler throws', async ({ baseURL }
'sentry.op': { type: 'string', value: 'function' },
'sentry.status.message': { type: 'string', value: 'internal_error' },
'nestjs.type': { type: 'string', value: 'request_context' },
'code.function.name': { type: 'string', value: 'AppController.testException' },
}),
});

Expand Down
2 changes: 2 additions & 0 deletions packages/nestjs/src/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MonitorConfig } from '@sentry/core';
import { CODE_FUNCTION_NAME } from '@sentry/conventions/attributes';
import { captureException, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import * as Sentry from '@sentry/node';
import { startSpan } from '@sentry/node';
Expand Down Expand Up @@ -43,6 +44,7 @@ export function SentryTraced(op: string = 'function') {
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
[CODE_FUNCTION_NAME]: propertyKey,
},
},
() => {
Expand Down
9 changes: 8 additions & 1 deletion packages/nestjs/src/integrations/wrap-route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { HTTP_REQUEST_METHOD, HTTP_ROUTE, SENTRY_OP, URL_FULL } from '@sentry/conventions/attributes';
import {
CODE_FUNCTION_NAME,
HTTP_REQUEST_METHOD,
HTTP_ROUTE,
SENTRY_OP,
URL_FULL,
} from '@sentry/conventions/attributes';
import { FUNCTION, HANDLER } from '@sentry/conventions/op';
import type { SpanAttributes } from '@sentry/core';
import {
Expand Down Expand Up @@ -107,6 +113,7 @@ export function wrapRequestContextHandler(
component: NESTJS_COMPONENT,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: HTTP_ORIGIN,
[SENTRY_OP]: FUNCTION,
[CODE_FUNCTION_NAME]: spanName,
[AttributeNames.TYPE]: NestType.REQUEST_CONTEXT,
[AttributeNames.CONTROLLER]: instanceName,
[AttributeNames.CALLBACK]: callbackName,
Comment thread
Lms24 marked this conversation as resolved.
Expand Down
4 changes: 4 additions & 0 deletions packages/nestjs/test/decorators.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'reflect-metadata';
import { CODE_FUNCTION_NAME } from '@sentry/conventions/attributes';
import * as core from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import { beforeEach, describe, expect, it, vi } from 'vitest';
Expand Down Expand Up @@ -42,6 +43,7 @@ describe('SentryTraced decorator', () => {
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'test-operation',
[CODE_FUNCTION_NAME]: 'testMethod',
},
},
expect.any(Function),
Expand Down Expand Up @@ -75,6 +77,7 @@ describe('SentryTraced decorator', () => {
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function',
[CODE_FUNCTION_NAME]: 'testDefaultOp',
},
},
expect.any(Function),
Expand Down Expand Up @@ -108,6 +111,7 @@ describe('SentryTraced decorator', () => {
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'sync-operation',
[CODE_FUNCTION_NAME]: 'syncMethod',
},
},
expect.any(Function),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ describe('NestJS orchestrion subscriber: request_context / request_handler', ()
expect(contextSpanJson!.attributes['sentry.origin']).toBe('auto.http.nestjs');
expect(contextSpanJson!.attributes).toMatchObject({
component: '@nestjs/core',
'code.function.name': 'CatsController.getCats',
'nestjs.type': 'request_context',
'nestjs.controller': 'CatsController',
'nestjs.callback': 'getCats',
Expand Down
Loading