Skip to content

fix: keep exporting spans after OpenCode instance disposal - #44

Open
Ha02hen wants to merge 1 commit into
langfuse:mainfrom
Ha02hen:fix/keep-exporting-after-dispose
Open

Ha02hen wants to merge 1 commit into
langfuse:mainfrom
Ha02hen:fix/keep-exporting-after-dispose

Conversation

@Ha02hen

@Ha02hen Ha02hen commented Sep 21, 2026

Copy link
Copy Markdown

Summary

Fixes a lifecycle bug where Langfuse traces stopped exporting after OpenCode disposed and re-created the plugin instance in the same process.

OpenCode can re-create plugin instances when the effective runtime configuration changes, such as after a model or plugin configuration update. The plugin's dispose path shut down the process-wide OpenTelemetry tracer provider. Since that provider cannot be registered again in the same process, spans created after the plugin was re-created were silently dropped.

OpenCode 0.5.0 also requires the re-created plugin instance to reuse the existing Langfuse client. Otherwise, spans can be created through the process-wide provider while forceFlush operates on a different provider.

The plugin now:

  • Flushes spans instead of shutting down the tracer provider during OpenCode 1 and OpenCode 2 plugin disposal.
  • Reuses the Langfuse client while the same tracer provider remains registered.
  • Re-creates the client when the global tracer provider has been replaced.
  • Includes an integration regression test covering disposal and re-creation in the same process.

Verification

  • pnpm install
  • pnpm run format
  • pnpm run format:check
  • pnpm run build
  • pnpm run lint
  • pnpm run knip
  • pnpm run test:integration
  • 3 integration test files passed
  • 32 integration tests passed

@CLAassistant

CLAassistant commented Sep 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Ha02hen Ha02hen changed the title Keep exporting spans after OpenCode instance disposal fix: keep exporting spans after OpenCode instance disposal Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants