Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otel: automatically inject ContextManager, MetricsProvider, and TraceProvider #27314

Open
lucacasonato opened this issue Dec 10, 2024 · 1 comment
Labels
feat new feature (which has been agreed to/accepted) otel

Comments

@lucacasonato
Copy link
Member

Right now you have to import @deno/otel to hook Deno's built in OpenTelemetry API into @opentelemetry/api. @opentelemetry/api however has code to read all three of these from the global object. This code is intended to ensure that multiple copies of @opentelemetry/api can still work correctly.

I propose we set this global on startup as follows:

globalThis[Symbol.for("opentelemetry.js.api.1")] = {
  trace: new Deno.telemetry.TraceProvider(),
  context: new Deno.telemetry.ContextManager(),
  metrics: new Deno.telemetry.MetricsProvider(),
};

This may seem a bit unorthodox, but it is very useful because users do not have to import @deno/otel anymore. This is particularly helpful when using frameworks where you may not control the entrypoint (Next.js, Remix, etc).

I want to run this by the otel-js folks, but I don't think this is really very controversial - one could think of this as bundling @opentelemetry/api and automatically invoking trace.setGlobalTraceProvider and friends on startup.

@lucacasonato lucacasonato added feat new feature (which has been agreed to/accepted) otel labels Dec 10, 2024
@lucacasonato
Copy link
Member Author

(This does mean we need to bundle @opentelemetry/sdk-trace-base or a fork thereof to be able to provide a TraceProvider built-in.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) otel
Projects
None yet
Development

No branches or pull requests

1 participant