File tree Expand file tree Collapse file tree 6 files changed +74
-6
lines changed
dev-packages/node-integration-tests/suites/express
handle-error-no-tracesSampleRate
handle-error-tracesSampleRate-0
packages/node/src/integrations Expand file tree Collapse file tree 6 files changed +74
-6
lines changed Original file line number Diff line number Diff line change
1
+ import { loggingTransport } from '@sentry-internal/node-integration-tests' ;
2
+ import * as Sentry from '@sentry/node' ;
3
+
4
+ Sentry . init ( {
5
+ dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
6
+ release : '1.0' ,
7
+ transport : loggingTransport ,
8
+ debug : true ,
9
+ tracesSampleRate : 0 ,
10
+ } ) ;
11
+
12
+ import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests' ;
13
+ import express from 'express' ;
14
+
15
+ const app = express ( ) ;
16
+
17
+ app . get ( '/test/express/:id' , req => {
18
+ throw new Error ( `test_error with id ${ req . params . id } ` ) ;
19
+ } ) ;
20
+
21
+ Sentry . setupExpressErrorHandler ( app ) ;
22
+
23
+ startExpressServerAndSendPortToRunner ( app ) ;
Original file line number Diff line number Diff line change
1
+ import { cleanupChildProcesses , createRunner } from '../../../utils/runner' ;
2
+
3
+ afterAll ( ( ) => {
4
+ cleanupChildProcesses ( ) ;
5
+ } ) ;
6
+
7
+ test ( 'should capture and send Express controller error.' , done => {
8
+ const runner = createRunner ( __dirname , 'server.ts' )
9
+ . ignore ( 'session' , 'sessions' )
10
+ . expect ( {
11
+ event : {
12
+ exception : {
13
+ values : [
14
+ {
15
+ mechanism : {
16
+ type : 'middleware' ,
17
+ handled : false ,
18
+ } ,
19
+ type : 'Error' ,
20
+ value : 'test_error with id 123' ,
21
+ stacktrace : {
22
+ frames : expect . arrayContaining ( [
23
+ expect . objectContaining ( {
24
+ function : expect . any ( String ) ,
25
+ lineno : expect . any ( Number ) ,
26
+ colno : expect . any ( Number ) ,
27
+ } ) ,
28
+ ] ) ,
29
+ } ,
30
+ } ,
31
+ ] ,
32
+ } ,
33
+ transaction : 'GET /test/express/:id' ,
34
+ } ,
35
+ } )
36
+ . start ( done ) ;
37
+
38
+ expect ( ( ) => runner . makeRequest ( 'get' , '/test/express/123' ) ) . rejects . toThrow ( ) ;
39
+ } ) ;
Original file line number Diff line number Diff line change @@ -5,15 +5,16 @@ Sentry.init({
5
5
dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
6
6
release : '1.0' ,
7
7
transport : loggingTransport ,
8
+ debug : true ,
8
9
} ) ;
9
10
10
11
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests' ;
11
12
import express from 'express' ;
12
13
13
14
const app = express ( ) ;
14
15
15
- app . get ( '/test/express' , ( ) => {
16
- throw new Error ( ' test_error' ) ;
16
+ app . get ( '/test/express/:id ' , req => {
17
+ throw new Error ( ` test_error with id ${ req . params . id } ` ) ;
17
18
} ) ;
18
19
19
20
Sentry . setupExpressErrorHandler ( app ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ test('should capture and send Express controller error.', done => {
17
17
handled : false ,
18
18
} ,
19
19
type : 'Error' ,
20
- value : 'test_error' ,
20
+ value : 'test_error with id 123 ' ,
21
21
stacktrace : {
22
22
frames : expect . arrayContaining ( [
23
23
expect . objectContaining ( {
@@ -34,5 +34,5 @@ test('should capture and send Express controller error.', done => {
34
34
} )
35
35
. start ( done ) ;
36
36
37
- expect ( ( ) => runner . makeRequest ( 'get' , '/test/express' ) ) . rejects . toThrow ( ) ;
37
+ expect ( ( ) => runner . makeRequest ( 'get' , '/test/express/123 ' ) ) . rejects . toThrow ( ) ;
38
38
} ) ;
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
93
93
requestHook : ( span , req ) => {
94
94
addOriginToSpan ( span , 'auto.http.otel.http' ) ;
95
95
96
- if ( getSpanKind ( span ) !== SpanKind . SERVER ) {
96
+ if ( span . isRecording ( ) && getSpanKind ( span ) !== SpanKind . SERVER ) {
97
97
return ;
98
98
}
99
99
Original file line number Diff line number Diff line change 1
1
import type * as http from 'http' ;
2
2
import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
3
3
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' ;
4
- import { defineIntegration } from '@sentry/core' ;
4
+ import { defineIntegration , getDefaultIsolationScope } from '@sentry/core' ;
5
5
import { captureException , getClient , getIsolationScope } from '@sentry/core' ;
6
6
import type { IntegrationFn } from '@sentry/types' ;
7
7
8
+ import { logger } from '@sentry/utils' ;
8
9
import type { NodeClient } from '../../sdk/client' ;
9
10
import { addOriginToSpan } from '../../utils/addOriginToSpan' ;
10
11
@@ -19,6 +20,10 @@ const _expressIntegration = (() => {
19
20
addOriginToSpan ( span , 'auto.http.otel.express' ) ;
20
21
} ,
21
22
spanNameHook ( info , defaultName ) {
23
+ if ( getIsolationScope ( ) === getDefaultIsolationScope ( ) ) {
24
+ logger . warn ( 'Isolation scope is still default isolation scope - skipping setting transactionName' ) ;
25
+ return defaultName ;
26
+ }
22
27
if ( info . layerType === 'request_handler' ) {
23
28
// type cast b/c Otel unfortunately types info.request as any :(
24
29
const req = info . request as { method ?: string } ;
You can’t perform that action at this time.
0 commit comments