Skip to content

Commit f483996

Browse files
authored
feat(unstable): no config npm:@opentelemetry/api integration (denoland#27541)
After this PR, one does not need to import `jsr:@deno/otel` anymore.
1 parent ccd3758 commit f483996

File tree

10 files changed

+23
-57
lines changed

10 files changed

+23
-57
lines changed

cli/tsc/dts/lib.deno.unstable.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,16 +1268,15 @@ declare namespace Deno {
12681268
* OpenTelemetry API. This is done using the official OpenTelemetry package
12691269
* for JavaScript:
12701270
* [`npm:@opentelemetry/api`](https://opentelemetry.io/docs/languages/js/).
1271-
* Deno integrates with this package to provide trace context propagation
1272-
* between native Deno APIs (like `Deno.serve` or `fetch`) and custom user
1273-
* code. Deno also provides APIs that allow exporting custom telemetry data
1274-
* via the same OTLP channel used by the Deno runtime. This is done using the
1275-
* [`jsr:@deno/otel`](https://jsr.io/@deno/otel) package.
1271+
* Deno integrates with this package to provide tracing, metrics, and trace
1272+
* context propagation between native Deno APIs (like `Deno.serve` or `fetch`)
1273+
* and custom user code. Deno automatically registers the providers with the
1274+
* OpenTelemetry API, so users can start creating custom traces, metrics, and
1275+
* logs without any additional setup.
12761276
*
12771277
* @example Using OpenTelemetry API to create custom traces
12781278
* ```ts,ignore
12791279
* import { trace } from "npm:@opentelemetry/api@1";
1280-
* import "jsr:@deno/[email protected]/register";
12811280
*
12821281
* const tracer = trace.getTracer("example-tracer");
12831282
*

ext/telemetry/telemetry.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,11 @@ export function builtinTracer(): Tracer {
10751075
return builtinTracerCache;
10761076
}
10771077

1078+
// We specify a very high version number, to allow any `@opentelemetry/api`
1079+
// version to load this module. This does cause @opentelemetry/api to not be
1080+
// able to register anything itself with the global registration methods.
1081+
const OTEL_API_COMPAT_VERSION = "1.999.999";
1082+
10781083
export function bootstrap(
10791084
config: [
10801085
0 | 1,
@@ -1102,6 +1107,19 @@ export function bootstrap(
11021107
default:
11031108
break;
11041109
}
1110+
1111+
if (TRACING_ENABLED || METRICS_ENABLED) {
1112+
const otel = globalThis[SymbolFor("opentelemetry.js.api.1")] ??= {
1113+
version: OTEL_API_COMPAT_VERSION,
1114+
};
1115+
if (TRACING_ENABLED) {
1116+
otel.trace = TracerProvider;
1117+
otel.context = ContextManager;
1118+
}
1119+
if (METRICS_ENABLED) {
1120+
otel.metrics = MeterProvider;
1121+
}
1122+
}
11051123
}
11061124

11071125
export const telemetry = {

tests/registry/jsr/@deno/otel/0.0.2/deno.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/registry/jsr/@deno/otel/0.0.2/src/index.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/registry/jsr/@deno/otel/0.0.2/src/register.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/registry/jsr/@deno/otel/0.0.2_meta.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/registry/jsr/@deno/otel/meta.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/registry/npm/@opentelemetry/sdk-metrics/registry.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/registry/npm/@opentelemetry/sdk-trace-base/registry.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/specs/cli/otel_basic/basic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

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

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

0 commit comments

Comments
 (0)