Skip to content

Commit

Permalink
feat(unstable): no config npm:@opentelemetry/api integration (#27541)
Browse files Browse the repository at this point in the history
After this PR, one does not need to import `jsr:@deno/otel` anymore.
  • Loading branch information
lucacasonato authored and dsherret committed Jan 9, 2025
1 parent 5eff7df commit 00719ec
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 57 deletions.
11 changes: 5 additions & 6 deletions cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,16 +1268,15 @@ declare namespace Deno {
* OpenTelemetry API. This is done using the official OpenTelemetry package
* for JavaScript:
* [`npm:@opentelemetry/api`](https://opentelemetry.io/docs/languages/js/).
* Deno integrates with this package to provide trace context propagation
* between native Deno APIs (like `Deno.serve` or `fetch`) and custom user
* code. Deno also provides APIs that allow exporting custom telemetry data
* via the same OTLP channel used by the Deno runtime. This is done using the
* [`jsr:@deno/otel`](https://jsr.io/@deno/otel) package.
* Deno integrates with this package to provide tracing, metrics, and trace
* context propagation between native Deno APIs (like `Deno.serve` or `fetch`)
* and custom user code. Deno automatically registers the providers with the
* OpenTelemetry API, so users can start creating custom traces, metrics, and
* logs without any additional setup.
*
* @example Using OpenTelemetry API to create custom traces
* ```ts,ignore
* import { trace } from "npm:@opentelemetry/api@1";
* import "jsr:@deno/[email protected]/register";
*
* const tracer = trace.getTracer("example-tracer");
*
Expand Down
18 changes: 18 additions & 0 deletions ext/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,11 @@ export function builtinTracer(): Tracer {
return builtinTracerCache;
}

// We specify a very high version number, to allow any `@opentelemetry/api`
// version to load this module. This does cause @opentelemetry/api to not be
// able to register anything itself with the global registration methods.
const OTEL_API_COMPAT_VERSION = "1.999.999";

export function bootstrap(
config: [
0 | 1,
Expand Down Expand Up @@ -1102,6 +1107,19 @@ export function bootstrap(
default:
break;
}

if (TRACING_ENABLED || METRICS_ENABLED) {
const otel = globalThis[SymbolFor("opentelemetry.js.api.1")] ??= {
version: OTEL_API_COMPAT_VERSION,
};
if (TRACING_ENABLED) {
otel.trace = TracerProvider;
otel.context = ContextManager;
}
if (METRICS_ENABLED) {
otel.metrics = MeterProvider;
}
}
}

export const telemetry = {
Expand Down
14 changes: 0 additions & 14 deletions tests/registry/jsr/@deno/otel/0.0.2/deno.json

This file was deleted.

15 changes: 0 additions & 15 deletions tests/registry/jsr/@deno/otel/0.0.2/src/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions tests/registry/jsr/@deno/otel/0.0.2/src/register.ts

This file was deleted.

6 changes: 0 additions & 6 deletions tests/registry/jsr/@deno/otel/0.0.2_meta.json

This file was deleted.

8 changes: 0 additions & 8 deletions tests/registry/jsr/@deno/otel/meta.json

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/specs/cli/otel_basic/basic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2025 the Deno authors. MIT license.

import { trace } from "npm:@opentelemetry/[email protected]";
import "jsr:@deno/[email protected]/register";

const tracer = trace.getTracer("example-tracer");

Expand Down

0 comments on commit 00719ec

Please sign in to comment.