#11530: diagnostics-otel: fix OpenTelemetry v2 resource/logs API compatibility
extensions: diagnostics-otel
stale
## Summary
Fixes `diagnostics-otel` startup failures after upgrading OpenTelemetry dependencies.
Root cause was API drift in OTel v2:
- `@opentelemetry/resources`: `new Resource(...)` is no longer the supported constructor path.
- `@opentelemetry/sdk-logs`: `LoggerProvider#addLogRecordProcessor` is no longer available.
## Changes
- Switch resource creation to `resourceFromAttributes(...)`.
- Initialize `LoggerProvider` with `processors: [...]` instead of calling `addLogRecordProcessor(...)`.
- Update the extension unit test mock from `Resource` to `resourceFromAttributes`.
## Why this matters
Without this patch, `diagnostics-otel` fails during plugin startup and telemetry export is disabled at runtime.
## Validation
- `pnpm vitest run extensions/diagnostics-otel/src/service.test.ts`
- Manual runtime verification on a live gateway:
- plugin starts successfully
- `diagnostics-otel: logs exporter enabled (OTLP/HTTP)` appears in logs
- no further plugin startup TypeErrors for diagnostics-otel
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the `diagnostics-otel` plugin to match OpenTelemetry v2 API changes by switching resource creation to `resourceFromAttributes(...)` and constructing `LoggerProvider` with `processors: [...]` instead of calling `addLogRecordProcessor`.
The runtime changes in `extensions/diagnostics-otel/src/service.ts` align with the described OTel API drift, and the unit test updates the resources mock accordingly. One issue remains in the test harness: the `@opentelemetry/sdk-logs` mock `LoggerProvider` still models the removed `addLogRecordProcessor` API and does not capture/validate the new `processors` constructor option, so the test can pass without actually asserting that processors are wired.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but fix the unit test mock to reflect the new LoggerProvider initialization semantics.
- The production change is small and directly addresses known OTel v2 API incompatibilities. The main risk is around test coverage correctness: the current sdk-logs mock can mask regressions because it doesn’t model the new `processors` option and retains an unused API.
- extensions/diagnostics-otel/src/service.test.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#4255: fix(diagnostics-otel): complete OpenTelemetry v2.x compatibility
by arbgjr · 2026-01-29
89.9%
#10199: fix(diagnostics-otel): opentelemetry bug fix
by yourtion · 2026-02-06
88.2%
#2574: fix(diagnostics-otel): update to @opentelemetry/resources v2.x API
by dillera · 2026-01-27
87.5%
#19353: fix(diagnostics-otel): fix cross-chunk module isolation breaking even…
by nez · 2026-02-17
84.0%
#16865: fix(diagnostics-otel): share listeners/transports across module bun...
by leonnardo · 2026-02-15
78.7%
#21290: feat(diagnostics-otel): OpenTelemetry diagnostics with GenAI semant...
by Baukebrenninkmeijer · 2026-02-19
77.2%
#18901: feat(diagnostics-otel): add trace context propagation and GenAI sem...
by sergical · 2026-02-17
73.8%
#18182: fix(security): redact sensitive data in OTEL log exports (CWE-532)
by brandonwise · 2026-02-16
73.5%
#22478: fix(diagnostics-otel): wire OTLP exporter to emit traffic to config...
by LuffySama-Dev · 2026-02-21
70.9%
#13957: Enhanced OpenClaw Observability with OTEL Integration
by trevorgordon981 · 2026-02-11
70.1%