Skip to content

Repository files navigation

Langfuse OpenCode Plugin

OpenCode plugin that sends OpenCode session telemetry to Langfuse. It traces user turns, assistant generations, tool calls, retries, reasoning output, compaction output, and failed generation steps.

Quick Start

For OpenCode 2, enable the plugin in your configuration:

{
  "plugins": ["@langfuse/opencode-observability-plugin@latest"]
}

For OpenCode 1, use the same package in your opencode.json or opencode.jsonc:

{
  "plugin": ["@langfuse/opencode-observability-plugin@latest"]
}

Restart OpenCode after changing the config.

Supported Versions

The default package entrypoint supports both OpenCode 1 and OpenCode 2. OpenCode 1 calls the plugin's server() implementation, while OpenCode 2 calls its setup() implementation. The /v1 and /v2 entrypoints remain available for direct imports.

Validated versions and entrypoints:

  • OpenCode 2.0.4 and newer: @langfuse/opencode-observability-plugin
  • OpenCode 1.18.29 and newer: @langfuse/opencode-observability-plugin

Langfuse Credentials

Create ~/.config/opencode/opencode-langfuse.json with your Langfuse credentials.

{
  "publicKey": "pk-lf-...",
  "secretKey": "sk-lf-...",
  "baseUrl": "https://cloud.langfuse.com",
  "environment": "development",
  "userId": "your-user-id"
}

Only publicKey and secretKey are required. If baseUrl is not set, the plugin uses https://cloud.langfuse.com. If environment is not set, it uses development.

You can also set credentials with environment variables:

export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_BASE_URL="https://cloud.langfuse.com"
export LANGFUSE_ENVIRONMENT="development"
export LANGFUSE_USER_ID="your-user-id"

If both LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY are set, the plugin uses environment variables instead of reading the config file. Optional values can be supplied either way.

Contributing

See the contributing guide.

License

MIT

About

🪢 An opencode plugin that instruments sessions in Langfuse

Topics

Resources

Contributing

Stars

29 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages