diff --git a/examples/express/src/tracer.ts b/examples/express/src/tracer.ts index 059bef7b60..6906f72819 100644 --- a/examples/express/src/tracer.ts +++ b/examples/express/src/tracer.ts @@ -2,7 +2,7 @@ import { SpanKind, Attributes } from "@opentelemetry/api"; -const opentelemetry = require('@opentelemetry/api'); +import opentelemetry = require('@opentelemetry/api'); // Not functionally required but gives some insight what happens behind the scenes const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry; @@ -13,16 +13,16 @@ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { Sampler, AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; import { Resource } from '@opentelemetry/resources'; -import { SEMRESATTRS_SERVICE_NAME, SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions'; +import { ATTR_SERVICE_NAME, ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions'; const Exporter = OTLPTraceExporter; import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; -const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); +import {HttpInstrumentation} from '@opentelemetry/instrumentation-http'; export const setupTracing = (serviceName: string) => { const provider = new NodeTracerProvider({ resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName, + [ATTR_SERVICE_NAME]: serviceName, }), sampler: filterSampler(ignoreHealthCheck, new AlwaysOnSampler()), }); @@ -30,8 +30,8 @@ export const setupTracing = (serviceName: string) => { tracerProvider: provider, instrumentations: [ // Express instrumentation expects HTTP layer to be instrumented - HttpInstrumentation, - ExpressInstrumentation, + new HttpInstrumentation(), + new ExpressInstrumentation(), ], }); @@ -62,5 +62,5 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler { } function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: Attributes) { - return spanKind !== opentelemetry.SpanKind.SERVER || attributes[SEMATTRS_HTTP_ROUTE] !== "/health"; + return spanKind !== opentelemetry.SpanKind.SERVER || attributes[ATTR_HTTP_ROUTE] !== "/health"; }