diff options
author | Luca Casonato <hello@lcas.dev> | 2024-11-19 00:55:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-18 23:55:22 +0000 |
commit | 594a99817cbe44553b2c288578fbba8e1e9c1907 (patch) | |
tree | 1ea268742bc626482005fac460a189b4a03f0a53 /tests/registry/jsr/@deno/otel/0.0.2/src/index.ts | |
parent | 106d47a0136c04ca219a81c3f91505116e13855e (diff) |
feat(runtime): remove public OTEL trace API (#26854)
This PR removes the public Deno.tracing.Span API.
We are not confident we can ship an API that is
better than the `@opentelemetry/api` API, because
V8 CPED does not support us using `using` to
manage span context. If this changes, we can
revisit this decision. For now, users wanting
custom spans can instrument their code using
the `@opentelemetry/api` API and `@deno/otel`.
This PR also speeds up the OTEL trace generation
by a 30% by using Uint8Array instead of
strings for the trace ID and span ID.
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(); +} |