Skip to content

opencode run: OTel spans lost because AppRuntime is not disposed before process.exit() #30087

Description

@astefanutti

Summary

opencode run never emits OTel spans to an OTLP collector because process.exit() in the finally block of index.ts kills the process before the BatchSpanProcessor can flush its buffer.

The AppRuntime wraps a ManagedRuntime whose Observability.layer initializes the OTel NodeSdk with a BatchSpanProcessor. Disposing the runtime would trigger the SDK's shutdown()forceFlush() chain, but AppRuntime.dispose() is never called.

Root cause

In packages/opencode/src/index.ts:

} finally {
  process.exit() // kills pending async ops including span export
}

Fix

Call await AppRuntime.dispose() before process.exit():

} finally {
  await AppRuntime.dispose().catch(() => {})
  process.exit()
}

Reproduction

  1. Start a local OTLP collector on localhost:4318
  2. Run: OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 opencode run --format json "Say hi"
  3. Observe: 0 spans received by the collector

Related: #13438

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions