-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/biothings/bte-server into dev
- Loading branch information
Showing
6 changed files
with
65 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import { NodeSDK } from "@opentelemetry/sdk-node"; | ||
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node"; | ||
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node"; | ||
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"; | ||
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express"; | ||
import { Resource } from "@opentelemetry/resources"; | ||
import Debug from "debug"; | ||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; | ||
const debug = Debug("bte:biothings-explorer:otel-init"); | ||
import { JaegerExporter } from "@opentelemetry/exporter-jaeger"; | ||
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; | ||
|
||
const jaegerHost = process.env.JAEGER_HOST ?? 'jaeger-otel-collector.sri'; | ||
const jaegerPort = process.env.JAEGER_PORT ?? 4318; | ||
const jaegerResName = process.env.JAEGER_RES_NAME ?? '/v1/traces'; | ||
|
||
const traceExporter = new OTLPTraceExporter({ | ||
url: `http://${jaegerHost}:${jaegerPort}${jaegerResName}` | ||
}); | ||
const spanProcessor = new BatchSpanProcessor(traceExporter); | ||
|
||
debug("Initializing Opentelemetry instrumentation..."); | ||
const sdk = new NodeSDK({ | ||
traceExporter: new JaegerExporter({ | ||
host: process.env.JAEGER_HOST ?? "jaeger-otel-agent.sri", | ||
port: parseInt(process.env.JAEGER_PORT ?? "6832"), | ||
}), | ||
instrumentations: [getNodeAutoInstrumentations()], | ||
// metrics, if needed, shall be exported on a different endpoint | ||
// trace a subset of instrumentations to avoid performance overhead | ||
instrumentations: [new HttpInstrumentation(), new ExpressInstrumentation()], | ||
resource: new Resource({ | ||
"service.name": "biothings-explorer", | ||
[ATTR_SERVICE_NAME]: "biothings-explorer", | ||
}), | ||
// @ts-ignore because MetinSeylan/Nestjs-OpenTelemetry#63 | ||
spanProcessors: [spanProcessor], | ||
}); | ||
debug(`OTel URL http://${jaegerHost}:${jaegerPort}${jaegerResName}`); | ||
sdk.start(); | ||
debug("Opentelemetry instrumentation initialized."); | ||
|
||
export async function flushRemainingSpans(): Promise<void> { | ||
// avoid losing any spans in the buffer when taskHandler exits | ||
debug("Flushing remaining spans..."); | ||
await spanProcessor.forceFlush(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters