feat: integrate OpenTelemetry#5245
Conversation
- Updated bun.lock and package.json to include OpenTelemetry dependencies. - Implemented tracing in various components including session management and tool execution. - Enhanced error handling and event logging for better observability.
|
I think opencode already emits telemetry spans if you set: experimental_opentelemetry to true in your opencode.json |
…lemetry - Moved Tracing initialization to occur before the root CLI span is created. - Wrapped CLI parsing in a span to include command-line arguments in telemetry.
|
Thanks for the quick response @rekram1-node. I set the following and it didn't work: //.opencode/opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"experimental": {
"openTelemetry": true
},
}I had to modify the repo to get it to emit open telemetry. |
|
Would be nice to have something like this https://www.reddit.com/r/ClaudeCode/comments/1pjon1r/til_that_claude_code_has_opentelemetry_metrics/ |
|
Hi, doesn't work for me either. Minimally, additional packages from OpenTelemetry JavaScript SDK need to be added |
|
I love this feature, is it possible to add open telemetry support and contains productivity metrics (such as acceptance rate or lines of code) like claude code? https://code.claude.com/docs/en/monitoring-usage#lines-of-code-counter |
|
Working on a PR to fully enable OTEL for opencode in a container image. Hope to be able to share it soon |
|
If it helps. I submitted a merge request to add otel support awhile back, but it got very little traction: |
|
@Phantal : Yes, I saw your PR. On my side, I am trying to obtain full leverage of AI SDK Otel implementation by Vercel. I want to add much less code than your PR and just minimally change the current Otel setup. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Let me document how OTel in OpenCode works without this PR. I tested the current OpenCode (opencode-ai@1.1.51, opencode-ai@1.1.53, without this PR), and the spans are emitted/exported subject to the following pre-requisites:
Here:
There are 3 types (i.e. 3 values of span.name) logged: ai.streamText, ai.toolCall, ai.streamText.doStream. The spans are not coming directly from OpenCode but from Vercel AI SDK opencode is using. They contain full text of prompts. Here is one of 3 lines where span is created: https://github.com/vercel/ai/blob/c36a873ce00892a4c587c2e9492220b392aefd09/packages/ai/src/generate-text/stream-text.ts#L1142 |
@rekram1-node This isn't quite true since there's never a span collector set up (e.g. see #6629 and https://github.com/DEVtheOPS/opencode-plugin-otel) A quick search of otel shows many PRs and issues |
|
Should we use custom opencode plugins?
or wait native implementation? Because plugins don't have such support as opencode has and we need some guaranties that attributes names won't change in the near future because many commands need to write alerts and parsers of this traces. |
+1 |
Hi @thdxr, @adamdotdevin, and @rekram1-node
I love opencode. Trying to run it with open telemetry and wanted to add back some code to the project. If you generaly like this commit, I can work on resolving the merge conflict (just imports, nothing big).
Summary
Changes