Skip to content

Commit 4aba201

Browse files
authored
refactor(examples/express): small refactor of imports (open-telemetry#2562)
1 parent d7773a2 commit 4aba201

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

examples/express/src/tracer.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
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';
114
import { registerInstrumentations } from '@opentelemetry/instrumentation';
125
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
136
import { Sampler, AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
147
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
158
import { Resource } from '@opentelemetry/resources';
169
import { ATTR_SERVICE_NAME, ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
17-
1810
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
19-
import {HttpInstrumentation} from '@opentelemetry/instrumentation-http';
11+
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
2012

2113
export 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

4739
type 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

6355
function 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

Comments
 (0)