11'use strict' ;
22
3- import { SpanKind , Attributes } from "@opentelemetry/api" ;
4-
5- import opentelemetry = require( '@opentelemetry/api' ) ;
6-
7- // Not functionally required but gives some insight what happens behind the scenes
8- const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry ;
9- diag . setLogger ( new DiagConsoleLogger ( ) , DiagLogLevel . INFO ) ;
10-
3+ import { trace , SamplingDecision , SpanKind , Attributes } from '@opentelemetry/api' ;
114import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
125import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node' ;
136import { Sampler , AlwaysOnSampler , SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base' ;
147import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' ;
158import { Resource } from '@opentelemetry/resources' ;
169import { ATTR_SERVICE_NAME , ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions' ;
17-
1810import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' ;
19- import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
11+ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
2012
2113export const setupTracing = ( serviceName : string ) => {
2214 const provider = new NodeTracerProvider ( {
@@ -41,7 +33,7 @@ export const setupTracing = (serviceName: string) => {
4133 // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
4234 provider . register ( ) ;
4335
44- return opentelemetry . trace . getTracer ( serviceName ) ;
36+ return trace . getTracer ( serviceName ) ;
4537} ;
4638
4739type FilterFunction = ( spanName : string , spanKind : SpanKind , attributes : Attributes ) => boolean ;
@@ -50,7 +42,7 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
5042 return {
5143 shouldSample ( ctx , tid , spanName , spanKind , attr , links ) {
5244 if ( ! filterFn ( spanName , spanKind , attr ) ) {
53- return { decision : opentelemetry . SamplingDecision . NOT_RECORD } ;
45+ return { decision : SamplingDecision . NOT_RECORD } ;
5446 }
5547 return parent . shouldSample ( ctx , tid , spanName , spanKind , attr , links ) ;
5648 } ,
@@ -61,5 +53,5 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
6153}
6254
6355function ignoreHealthCheck ( spanName : string , spanKind : SpanKind , attributes : Attributes ) {
64- return spanKind !== opentelemetry . SpanKind . SERVER || attributes [ ATTR_HTTP_ROUTE ] !== "/health" ;
56+ return spanKind !== SpanKind . SERVER || attributes [ ATTR_HTTP_ROUTE ] !== "/health" ;
6557}
0 commit comments