Post OpenTelemetry from Vite app to Aspire dashboard #11129
-
Hello, I have a setup where I want OTel traces to end up in the Aspire Dashboard. My app is configured like this: When my AppHost is started, I see OTEL_EXPORTER_OTLP_HEADERS and other OTel amongst the "frontend" resource's Environment variables. But my app tries to use them and gets empty string. So, the OTel is only working if I hardcode I tried to turn off OTel authentication, but got no luck. According to Aspire Docs I need to use either config file specified in the launch settings, or add "Dashboard" section in appsettings.
There is also option ASPIRE_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS, that should set Dashboard:Optl:AuthMode to Unsecured for me, but it doesn't. I checked with the source code and it seems to be true (from src\Aspire.Hosting\DistributedApplicationBuilder.cs) as it only sets resources' AuthMode:
I have also tried to pass another environment variable to frontend resource like this: How do I enable OpenTelemetry for my frontend app? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
TL;DR: The OTEL_EXPORTER_OTLP_* values you see on the frontend container are server-side env vars. The browser bundle can’t read them automatically. You need to bridge them into the client code. In vite.config.ts load the container env and add the values you need into the bundle as a constant: // vite.config.ts
Use it in the telemetry init: // init-otel.ts
The Node process that launches Vite (the NpmApp started by Aspire) does have OTEL_EXPORTER_OTLP_HEADERS in its env. Vite reads it at build/dev time injects only that string into the client. |
Beta Was this translation helpful? Give feedback.
TL;DR: The OTEL_EXPORTER_OTLP_* values you see on the frontend container are server-side env vars. The browser bundle can’t read them automatically. You need to bridge them into the client code.
In vite.config.ts load the container env and add the values you need into the bundle as a constant:
// vite.config.ts
Use it in the telem…