22
33import { SpanKind , Attributes } from "@opentelemetry/api" ;
44
5- const opentelemetry = require ( '@opentelemetry/api' ) ;
5+ import opentelemetry = require( '@opentelemetry/api' ) ;
66
77// Not functionally required but gives some insight what happens behind the scenes
88const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry ;
@@ -13,25 +13,25 @@ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
1313import { Sampler , AlwaysOnSampler , SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base' ;
1414import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' ;
1515import { Resource } from '@opentelemetry/resources' ;
16- import { SEMRESATTRS_SERVICE_NAME , SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions' ;
16+ import { ATTR_SERVICE_NAME , ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions' ;
1717
1818const Exporter = OTLPTraceExporter ;
1919import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' ;
20- const { HttpInstrumentation } = require ( '@opentelemetry/instrumentation-http' ) ;
20+ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
2121
2222export const setupTracing = ( serviceName : string ) => {
2323 const provider = new NodeTracerProvider ( {
2424 resource : new Resource ( {
25- [ SEMRESATTRS_SERVICE_NAME ] : serviceName ,
25+ [ ATTR_SERVICE_NAME ] : serviceName ,
2626 } ) ,
2727 sampler : filterSampler ( ignoreHealthCheck , new AlwaysOnSampler ( ) ) ,
2828 } ) ;
2929 registerInstrumentations ( {
3030 tracerProvider : provider ,
3131 instrumentations : [
3232 // Express instrumentation expects HTTP layer to be instrumented
33- HttpInstrumentation ,
34- ExpressInstrumentation ,
33+ new HttpInstrumentation ( ) ,
34+ new ExpressInstrumentation ( ) ,
3535 ] ,
3636 } ) ;
3737
@@ -62,5 +62,5 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
6262}
6363
6464function ignoreHealthCheck ( spanName : string , spanKind : SpanKind , attributes : Attributes ) {
65- return spanKind !== opentelemetry . SpanKind . SERVER || attributes [ SEMATTRS_HTTP_ROUTE ] !== "/health" ;
65+ return spanKind !== opentelemetry . SpanKind . SERVER || attributes [ ATTR_HTTP_ROUTE ] !== "/health" ;
6666}
0 commit comments