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 @@ -22,15 +22,15 @@ test('Transaction includes span and correct value for decorated async function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'wait and return a string',
},
description: 'wait',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'wait and return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand All @@ -57,15 +57,15 @@ test('Transaction includes span and correct value for decorated sync function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'return a string',
},
description: 'getString',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ test('Transaction includes span and correct value for decorated async function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'wait and return a string',
},
description: 'wait',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'wait and return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand All @@ -57,15 +57,15 @@ test('Transaction includes span and correct value for decorated sync function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'return a string',
},
description: 'getString',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ test('Transaction includes span and correct value for decorated async function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'wait and return a string',
},
description: 'wait',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'wait and return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand All @@ -57,15 +57,15 @@ test('Transaction includes span and correct value for decorated sync function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'return a string',
},
description: 'getString',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ test('Transaction includes span and correct value for decorated async function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'wait and return a string',
},
description: 'wait',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'wait and return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand All @@ -57,15 +57,15 @@ test('Transaction includes span and correct value for decorated sync function',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'manual',
'sentry.origin': 'auto.function.nestjs.sentry_traced',
'sentry.op': 'return a string',
},
description: 'getString',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
status: 'ok',
op: 'return a string',
origin: 'manual',
origin: 'auto.function.nestjs.sentry_traced',
}),
]),
);
Expand Down
11 changes: 10 additions & 1 deletion packages/nestjs/src/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { MonitorConfig } from '@sentry/core';
import { captureException, isThenable } from '@sentry/core';
import {
captureException,
isThenable,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
} from '@sentry/core';
import * as Sentry from '@sentry/node';
import { startSpan } from '@sentry/node';
import { isExpectedError } from './helpers';
Expand Down Expand Up @@ -52,6 +57,10 @@ export function SentryTraced(op: string = 'function') {
{
op: op,
name: propertyKey,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
},
},
() => {
return originalMethod.apply(this, args);
Expand Down
13 changes: 13 additions & 0 deletions packages/nestjs/test/decorators.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'reflect-metadata';
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';
import { SentryCron, SentryExceptionCaptured, SentryTraced } from '../src/decorators';
import * as helpers from '../src/helpers';
Expand Down Expand Up @@ -38,6 +39,10 @@ describe('SentryTraced decorator', () => {
{
op: 'test-operation',
name: 'testMethod',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'test-operation',
},
},
expect.any(Function),
);
Expand Down Expand Up @@ -67,6 +72,10 @@ describe('SentryTraced decorator', () => {
{
op: 'function', // default value
name: 'testDefaultOp',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function',
},
},
expect.any(Function),
);
Expand Down Expand Up @@ -96,6 +105,10 @@ describe('SentryTraced decorator', () => {
{
op: 'sync-operation',
name: 'syncMethod',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nestjs.sentry_traced',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'sync-operation',
},
},
expect.any(Function),
);
Expand Down
Loading