mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 15:48:16 -05:00
feat(unstable): no config npm:@opentelemetry/api integration (#27541)
After this PR, one does not need to import `jsr:@deno/otel` anymore.
This commit is contained in:
parent
ccd375802a
commit
f483996658
10 changed files with 23 additions and 57 deletions
11
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
11
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -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/otel@0.0.2/register";
|
||||
*
|
||||
* const tracer = trace.getTracer("example-tracer");
|
||||
*
|
||||
|
|
|
@ -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,
|
||||
|
@ -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 = {
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"name": "@deno/otel",
|
||||
"version": "0.0.2",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./register": "./src/register.ts"
|
||||
},
|
||||
"tasks": {
|
||||
"check:license": "deno run -A tools/check_license.ts",
|
||||
"check:docs": "deno doc --lint src/index.ts",
|
||||
"check": "deno task check:license --check",
|
||||
"ok": "deno fmt --check && deno lint && deno task check"
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2024-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { context, trace, metrics } from "npm:@opentelemetry/api@1";
|
||||
|
||||
// @ts-ignore Deno.telemetry is not typed yet
|
||||
const telemetry = Deno.telemetry ?? Deno.tracing;
|
||||
|
||||
/**
|
||||
* Register `Deno.telemetry` with the OpenTelemetry library.
|
||||
*/
|
||||
export function register() {
|
||||
context.setGlobalContextManager(telemetry.contextManager);
|
||||
trace.setGlobalTracerProvider(telemetry.tracerProvider);
|
||||
metrics.setGlobalMeterProvider(telemetry.meterProvider);
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
// Copyright 2024-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { register } from "./index.ts";
|
||||
|
||||
register();
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./register": "./src/register.ts"
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"scope": "deno",
|
||||
"name": "otel",
|
||||
"latest": "0.0.2",
|
||||
"versions": {
|
||||
"0.0.2": {}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
|
||||
import { trace } from "npm:@opentelemetry/api@1.9.0";
|
||||
import "jsr:@deno/otel@0.0.2/register";
|
||||
|
||||
const tracer = trace.getTracer("example-tracer");
|
||||
|
||||
|
|
Loading…
Reference in a new issue