mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -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
|
* OpenTelemetry API. This is done using the official OpenTelemetry package
|
||||||
* for JavaScript:
|
* for JavaScript:
|
||||||
* [`npm:@opentelemetry/api`](https://opentelemetry.io/docs/languages/js/).
|
* [`npm:@opentelemetry/api`](https://opentelemetry.io/docs/languages/js/).
|
||||||
* Deno integrates with this package to provide trace context propagation
|
* Deno integrates with this package to provide tracing, metrics, and trace
|
||||||
* between native Deno APIs (like `Deno.serve` or `fetch`) and custom user
|
* context propagation between native Deno APIs (like `Deno.serve` or `fetch`)
|
||||||
* code. Deno also provides APIs that allow exporting custom telemetry data
|
* and custom user code. Deno automatically registers the providers with the
|
||||||
* via the same OTLP channel used by the Deno runtime. This is done using the
|
* OpenTelemetry API, so users can start creating custom traces, metrics, and
|
||||||
* [`jsr:@deno/otel`](https://jsr.io/@deno/otel) package.
|
* logs without any additional setup.
|
||||||
*
|
*
|
||||||
* @example Using OpenTelemetry API to create custom traces
|
* @example Using OpenTelemetry API to create custom traces
|
||||||
* ```ts,ignore
|
* ```ts,ignore
|
||||||
* import { trace } from "npm:@opentelemetry/api@1";
|
* import { trace } from "npm:@opentelemetry/api@1";
|
||||||
* import "jsr:@deno/otel@0.0.2/register";
|
|
||||||
*
|
*
|
||||||
* const tracer = trace.getTracer("example-tracer");
|
* const tracer = trace.getTracer("example-tracer");
|
||||||
*
|
*
|
||||||
|
|
|
@ -1075,6 +1075,11 @@ export function builtinTracer(): Tracer {
|
||||||
return builtinTracerCache;
|
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(
|
export function bootstrap(
|
||||||
config: [
|
config: [
|
||||||
0 | 1,
|
0 | 1,
|
||||||
|
@ -1102,6 +1107,19 @@ export function bootstrap(
|
||||||
default:
|
default:
|
||||||
break;
|
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 = {
|
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.
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
|
|
||||||
import { trace } from "npm:@opentelemetry/api@1.9.0";
|
import { trace } from "npm:@opentelemetry/api@1.9.0";
|
||||||
import "jsr:@deno/otel@0.0.2/register";
|
|
||||||
|
|
||||||
const tracer = trace.getTracer("example-tracer");
|
const tracer = trace.getTracer("example-tracer");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue