1
+ import * as Sentry from "@sentry/node" ;
2
+ import {
3
+ SentrySpanProcessor ,
4
+ SentryPropagator ,
5
+ SentrySampler ,
6
+ } from "@sentry/opentelemetry" ;
7
+
8
+ Sentry . init ( {
9
+ // debug: true,
10
+ // fake DSN
11
+ dsn : "https://public@dsn.ingest.sentry.io/1337" ,
12
+ skipOpenTelemetrySetup : true ,
13
+
14
+ beforeSendTransaction : ( transaction ) => {
15
+ console . log ( transaction ) ;
16
+ return null ;
17
+ } ,
18
+
19
+ // The SentrySampler will use this to determine which traces to sample
20
+ tracesSampleRate : 1.0 ,
21
+ } ) ;
22
+
1
23
import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
2
24
import { trace , DiagConsoleLogger , DiagLogLevel , diag } from '@opentelemetry/api' ;
3
25
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
@@ -10,21 +32,32 @@ import { Resource } from '@opentelemetry/resources';
10
32
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' ;
11
33
import http from 'http' ;
12
34
13
- diag . setLogger ( new DiagConsoleLogger ( ) , DiagLogLevel . DEBUG ) ;
35
+ // Turn of OTEL debug logging in favour of Sentry debug logging
36
+ // diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
37
+
38
+ const sentryClient = Sentry . getClient ( ) ;
39
+
14
40
const tracerProvider = new NodeTracerProvider ( {
15
41
resource : new Resource ( {
16
42
[ SEMRESATTRS_SERVICE_NAME ] : 'esm-http-ts-example' ,
17
43
} ) ,
44
+ sampler : sentryClient ? new SentrySampler ( sentryClient ) : undefined ,
18
45
} ) ;
19
46
const exporter = new ConsoleSpanExporter ( ) ;
20
47
const processor = new SimpleSpanProcessor ( exporter ) ;
48
+ tracerProvider . addSpanProcessor ( new SentrySpanProcessor ( ) ) ;
21
49
tracerProvider . addSpanProcessor ( processor ) ;
22
- tracerProvider . register ( ) ;
50
+ tracerProvider . register ( {
51
+ propagator : new SentryPropagator ( ) ,
52
+ contextManager : new Sentry . SentryContextManager ( ) ,
53
+ } ) ;
23
54
24
55
registerInstrumentations ( {
25
56
instrumentations : [ new HttpInstrumentation ( ) ] ,
26
57
} ) ;
27
58
59
+ Sentry . validateOpenTelemetrySetup ( ) ;
60
+
28
61
const hostname = '0.0.0.0' ;
29
62
const port = 3000 ;
30
63
0 commit comments