Skip to content

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

Closed as not planned

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

Activity

  1. github-actions commented on May 31, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If this is the same underlying problem, consider contributing the fix to the existing issue or linking them.

  2. astefanutti commented on May 31, 2026

    @astefanutti
    Author

    Yes, this is the root cause of #13438. The fix is in #30089 — one-line change to dispose the runtime before process.exit().

  3. github-actions commented on Jul 31, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions