addBunApp: OTLP not auto-wired and spire otel <subcmd> <resource> returns misleading 'Resource not found'
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
## Summary
Resources created via `addBunApp` (from `Aspire.Hosting.JavaScript`) start up Healthy and serve traffic correctly, but they do **not** appear in Aspire's OTLP telemetry pipeline. Running any of the per-resource OTLP queries returns a misleading "Resource not found" error even though the resource is clearly present in `aspire describe` / `aspire ps`:
```
> aspire otel traces bun-svc
Scanning for running AppHosts...
❌ Resource 'bun-svc' not found.
> aspire otel logs bun-svc
❌ Resource 'bun-svc' not found.
> aspire otel spans bun-svc
❌ Resource 'bun-svc' not found.
```
Meanwhile `aspire describe --format Json` lists `bun-svc` as Running/Healthy, and `GET http://` returns the expected response.
This is a parity gap with .NET project resources, where OTLP is auto-wired and the `aspire otel ...` subcommands Just Work. It also undermines a core Aspire value prop (observability by default) for Bun apps.
The Bun SDK surface does expose `.withOtlpExporter(options?)` so this is presumably opt-in by design, but:
1. Nothing in the `addBunApp` docs/IntelliSense surfaces this.
2. The error message is actively misleading — the resource DOES exist; only its telemetry stream doesn't.
3. Even when `.withOtlpExporter()` is wired, the Bun runtime itself doesn't auto-instrument HTTP / fetch / etc., so the exporter has nothing to send unless the user wires up an OpenTelemetry SDK manually inside their Bun app.
## Repro
`apphost.mts`:
```ts
const bunSvc = await builder.addBunApp("bun-svc", "../services/bun-svc", "index.ts")
.withHttpEndpoint({ name: "http", env: "PORT" })
.withExternalHttpEndpoints();
```
`services/bun-svc/index.ts`:
```ts
Bun.serve({
port: Number(process.env.PORT ?? 4000),
fetch(req) { return new Response("bun ok\n"); },
});
```
1. `aspire run`.
2. `aspire describe --format Json` — `bun-svc` is Running/Healthy.
3. `curl http://localhost:` returns `bun ok`.
4. `aspire otel traces bun-svc` → "Resource 'bun-svc' not found".
## Environment
- OS: Windows 11
- Aspire CLI: 13.4
- Bun: 1.3.14
## Asks
1. **Preferred:** auto-wire OTLP for Bun apps the way .NET projects get it — at minimum the standard OTel env vars (`OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS`, `OTEL_SERVICE_NAME`) so a developer who drops in `@opentelemetry/sdk-node` (or the Bun-native equivalent when it lands) gets traces flowing for free. Parity with .NET would make this delightful.
2. **At minimum:** fix the error message. `aspire otel traces ` for a resource that exists but isn't emitting OTLP should say something like:
> Resource 'bun-svc' is running but is not emitting OpenTelemetry data. To enable, call `.withOtlpExporter()` on the resource and instrument your Bun app with an OpenTelemetry SDK. See .
3. Document the recommended Bun observability story end-to-end in the JS hosting docs — what to import, how to call `Bun.serve` so spans get created, what `.withOtlpExporter()` actually plumbs through.
## References
- `addBunApp` introduced in dotnet/aspire#17416
- Hit during Phase 5 validation of Aspire 13.4 (TS AppHost, polyglot brownfield).
Contributor guide
Assessment
This issue has not been assessed yet.