1- 'use strict' ;
1+ /*
2+ * Copyright The OpenTelemetry Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
216
3- import { trace , SamplingDecision , SpanKind , Attributes } from '@opentelemetry/api' ;
17+ import {
18+ trace ,
19+ SamplingDecision ,
20+ SpanKind ,
21+ Attributes ,
22+ } from '@opentelemetry/api' ;
423import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
524import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node' ;
6- import { Sampler , AlwaysOnSampler , SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base' ;
25+ import {
26+ Sampler ,
27+ AlwaysOnSampler ,
28+ SimpleSpanProcessor ,
29+ } from '@opentelemetry/sdk-trace-base' ;
730import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' ;
831import { Resource } from '@opentelemetry/resources' ;
9- import { ATTR_SERVICE_NAME , ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions' ;
32+ import {
33+ ATTR_SERVICE_NAME ,
34+ ATTR_HTTP_ROUTE ,
35+ } from '@opentelemetry/semantic-conventions' ;
1036import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' ;
1137import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
1238
39+ // eslint-disable-next-line import/prefer-default-export
1340export const setupTracing = ( serviceName : string ) => {
1441 const exporter = new OTLPTraceExporter ( { } ) ;
1542 const provider = new NodeTracerProvider ( {
1643 resource : new Resource ( {
1744 [ ATTR_SERVICE_NAME ] : serviceName ,
1845 } ) ,
19- spanProcessors : [
20- new SimpleSpanProcessor ( exporter ) ,
21- ] ,
46+ spanProcessors : [ new SimpleSpanProcessor ( exporter ) ] ,
2247 sampler : filterSampler ( ignoreHealthCheck , new AlwaysOnSampler ( ) ) ,
2348 } ) ;
2449 registerInstrumentations ( {
@@ -36,7 +61,11 @@ export const setupTracing = (serviceName: string) => {
3661 return trace . getTracer ( serviceName ) ;
3762} ;
3863
39- type FilterFunction = ( spanName : string , spanKind : SpanKind , attributes : Attributes ) => boolean ;
64+ type FilterFunction = (
65+ spanName : string ,
66+ spanKind : SpanKind ,
67+ attributes : Attributes
68+ ) => boolean ;
4069
4170function filterSampler ( filterFn : FilterFunction , parent : Sampler ) : Sampler {
4271 return {
@@ -48,10 +77,16 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
4877 } ,
4978 toString ( ) {
5079 return `FilterSampler(${ parent . toString ( ) } )` ;
51- }
52- }
80+ } ,
81+ } ;
5382}
5483
55- function ignoreHealthCheck ( spanName : string , spanKind : SpanKind , attributes : Attributes ) {
56- return spanKind !== SpanKind . SERVER || attributes [ ATTR_HTTP_ROUTE ] !== "/health" ;
84+ function ignoreHealthCheck (
85+ spanName : string ,
86+ spanKind : SpanKind ,
87+ attributes : Attributes
88+ ) {
89+ return (
90+ spanKind !== SpanKind . SERVER || attributes [ ATTR_HTTP_ROUTE ] !== '/health'
91+ ) ;
5792}
0 commit comments