diff options
author | haturau <135221985+haturatu@users.noreply.github.com> | 2024-11-20 01:20:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 01:20:47 +0900 |
commit | 85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch) | |
tree | face0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/registry/jsr/@deno/otel/0.0.2/src/index.ts | |
parent | 67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff) | |
parent | 186b52731c6bb326c4d32905c5e732d082e83465 (diff) |
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/registry/jsr/@deno/otel/0.0.2/src/index.ts')
-rw-r--r-- | tests/registry/jsr/@deno/otel/0.0.2/src/index.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/registry/jsr/@deno/otel/0.0.2/src/index.ts b/tests/registry/jsr/@deno/otel/0.0.2/src/index.ts new file mode 100644 index 000000000..9c4445783 --- /dev/null +++ b/tests/registry/jsr/@deno/otel/0.0.2/src/index.ts @@ -0,0 +1,38 @@ +// Copyright 2024-2024 the Deno authors. All rights reserved. MIT license. + +import { context } from "npm:@opentelemetry/api@1"; +import { + BasicTracerProvider, + SimpleSpanProcessor, +} from "npm:@opentelemetry/sdk-trace-base@1"; + +// @ts-ignore Deno.telemetry is not typed yet +const telemetry = Deno.telemetry ?? Deno.tracing; + +let COUNTER = 1; + +/** + * Register `Deno.telemetry` with the OpenTelemetry library. + */ +export function register() { + context.setGlobalContextManager( + new telemetry.ContextManager() ?? telemetry.ContextManager(), + ); + + const provider = new BasicTracerProvider({ + idGenerator: Deno.env.get("DENO_UNSTABLE_OTEL_DETERMINISTIC") === "1" ? { + generateSpanId() { + return "1" + String(COUNTER++).padStart(15, "0"); + }, + generateTraceId() { + return "1" + String(COUNTER++).padStart(31, "0"); + } + } : undefined + }); + + // @ts-ignore Deno.tracing is not typed yet + const exporter = new telemetry.SpanExporter(); + provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + + provider.register(); +} |