Skip to content

Conversation

@noamzbr
Copy link
Contributor

@noamzbr noamzbr commented Dec 2, 2025

Related Issues

What this does

  • AI SDK has an experimental_telemetry flag. When enabled, it will automatically emit OTEL spans. I've added an optional config that turns that on in all calls to AI SDK generation functions.
  • The user can then use any OTEL supporting framework for tracing. For example, in Langfuse it's pretty simple - the user can build a simple plugin to send the generated spans to Langfuse.

Happy to add / edit / expand if needed!

- AI SDK emits Open Telemetry Spans when experimental_telemetry is true
- Define an open_telemetry config field to control this flag (false by default)
@r-costa-tornis
Copy link

👀

@r-costa-tornis
Copy link

r-costa-tornis commented Dec 3, 2025

Can you provide a little doc explaining how to enable langfuse for example?
In the config files I mean.

@noamzbr
Copy link
Contributor Author

noamzbr commented Dec 3, 2025

Sure, you should add "open_telemetry": true in your opencode.jsonc, and then add a relevant plugin. For Langfuse, the following plugin worked for me

/**
 * Langfuse OpenTelemetry Plugin for OpenCode
 * 
 * Requires: bun add @langfuse/otel @opentelemetry/sdk-node
 * Env vars: LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_HOST
 */
import { NodeSDK } from "@opentelemetry/sdk-node"
import { LangfuseSpanProcessor } from "@langfuse/otel"

let initialized = false

export const LangfusePlugin = async () => ({
  async config(config) {
    if (!config.open_telemetry || initialized) return
    initialized = true

    const processor = new LangfuseSpanProcessor()
    new NodeSDK({ spanProcessors: [processor] }).start()

    // // Flush frequently - Required in headless mode to make sure flushes are made before process exit
    // setInterval(() => processor.forceFlush(), 500)
  },
})

@r-costa-tornis
Copy link

@rekram1-node 👀

@rekram1-node
Copy link
Collaborator

I'm a bit behind on prs at the moment but lemme take a look

@rekram1-node
Copy link
Collaborator

/oc rename open_telemetry to be under "experimental" object in the config, update all locations it's used

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Dec 5, 2025

Perfect! All changes are in place. Let me create a summary of what was changed:

Summary

I've successfully renamed open_telemetry to be under the experimental object in the config. Here are the changes made:

Changes Made:

  1. Config Schema (packages/opencode/src/config/config.ts):

    • Removed open_telemetry from the root config object
    • Added openTelemetry to the experimental object (line 673-676)
  2. Agent (packages/opencode/src/agent/agent.ts):

    • Updated line 233: cfg.open_telemetrycfg.experimental?.openTelemetry
  3. Session Compaction (packages/opencode/src/session/compaction.ts):

    • Updated line 196: cfg.open_telemetrycfg.experimental?.openTelemetry
  4. Session Prompt (packages/opencode/src/session/prompt.ts):

    • Updated line 618: cfg.open_telemetrycfg.experimental?.openTelemetry
    • Updated line 1470: cfg.open_telemetrycfg.experimental?.openTelemetry
  5. Session Summary (packages/opencode/src/session/summary.ts):

    • Updated line 114: cfg.open_telemetrycfg.experimental?.openTelemetry
    • Updated line 156: cfg.open_telemetrycfg.experimental?.openTelemetry

New Config Format:

Users should now use the following format in their opencode.jsonc:

{
  "experimental": {
    "openTelemetry": true
  }
}

Instead of the previous format:

{
  "open_telemetry": true
}

New%20session%20-%202025-12-05T16%3A37%3A16.175Z
opencode session  |  github run

@rekram1-node rekram1-node changed the title Enable AI SDK Open Telemetry spans add experimental.open_telemetry config option to enable the ai sdk spans Dec 5, 2025
@rekram1-node rekram1-node changed the title add experimental.open_telemetry config option to enable the ai sdk spans add experimental.open_telemetry config option to enable OTEL spans Dec 5, 2025
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
@r-costa-tornis
Copy link

🎉 🎉 🎉 🎉
Ty so much @rekram1-node

@rekram1-node rekram1-node merged commit 864c098 into anomalyco:dev Dec 5, 2025
2 of 3 checks passed
shuv1337 added a commit to Latitudes-Dev/shuvcode that referenced this pull request Dec 5, 2025
* fix: ensure checkUpgrade sets `init:` (anomalyco#5040)

* chore: format code

* ci: use blacksmith runners in review workflow too (anomalyco#5042)

* zen: make session provider sticky

* ci: only maintainer can trigger

* ci: cleaner

* ignore: update download stats 2025-12-04

* fix(tui): cursor color

* Preserve prompt input when creating new session (anomalyco#4993)

* fix: model not being passed correctly to tool

* tweak: bash tool messages regarding timeouts and truncation more clear for agent (anomalyco#5066)

* tui: fix /new slash command being persisted in prompt input

* add optional prompt Input to Github Action (anomalyco#4828)

Co-authored-by: Github Action <action@github.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>

* bump: builtin plugin versions

* feat: Add SAP AI Core provider support (anomalyco#5023)

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>

* core: ensure model npm package falls back to dev models config when not explicitly defined

* docs: add CodeCompanion.nvim integration instructions (anomalyco#5079)

* tweak: bash tool description re commit stuff

* core: add test for custom model npm package inheritance

* feat(desktop): terminal pane (anomalyco#5081)

Co-authored-by: Github Action <action@github.com>
Co-authored-by: Dax Raad <d@ironbay.co>

* Revert "feat(desktop): terminal pane (anomalyco#5081)"

This reverts commit d763c11.

* release: v1.0.133

* Update Nix flake.lock and hashes

* Reapply "feat(desktop): terminal pane (anomalyco#5081)"

This reverts commit f9dcd97.

* chore: format code

* Update Nix flake.lock and hashes

* zen: fix byok

* ignore: fix provider credentials query for BYOK

Provider credentials field was being selected from ProviderTable even when the table wasn't joined (when byokProvider was undefined). Now the join is conditional - when byokProvider exists, we join and get the credentials; when it doesn't, the join condition is always false so provider remains null.

* docs: llama.cpp docs: `limit` moved under model (anomalyco#5089)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>

* fix: add getModel to SAP AI Core provider for correct SDK initialization (anomalyco#5086)

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>

* fix pty builds

* fix

* increase default scroll speed

* ci: review

* fix: ensure that vcs is still set to git even if no commits in repo

* ignore: rm slop commnand (only for opencode repo this isnt shipping)

* chore: format code

* ignore: cmd tweak

* tui: wrap dialog option descriptions (anomalyco#5083)

* ci: keybinds

* fix: ensure projects that go from having no commits to having commits have sessions migrated (anomalyco#5105)

Co-authored-by: GitHub Action <action@github.com>

* ignore: tweak

* ignore: update download stats 2025-12-05

* Zen: add codex max

* do not use required pty for local dev

* fix: anomalyco#5064 ProviderInitError github-copilot-enterprise (anomalyco#5123)

* feat(theme): Vercel (anomalyco#5119)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>

* fix(desktop): new session not selecting tab

* fix(desktop): clone pty session on reconnect

* add experimental.open_telemetry config option to enable OTEL spans (anomalyco#4978)

Co-authored-by: noamzbr <noamzbr@users.noreply.github.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>

* ignore: regen sdk

* fix(desktop): prompting

* fix(desktop): terminal cursor position

* feat: add max steps for supervisor and sub-agents (anomalyco#4062)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>

* tweak: bash tool improve output metadata for agent consumption, fix small timeout issue (anomalyco#5131)

* OpenCode Desktop app (anomalyco#5044)

Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com>

* Update Nix flake.lock and hashes

* release: v1.0.134

* sync: record last synced tag v1.0.134

* chore: format code

---------

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Co-authored-by: YeonGyu-Kim <code.yeon.gyu@gmail.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: wsx99outlook <247713593+wsx99outlook@users.noreply.github.com>
Co-authored-by: Frank <frank@sst.dev>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com>
Co-authored-by: Daniel Gray <DanielFGray@gmail.com>
Co-authored-by: Shantur Rathore <i@shantur.com>
Co-authored-by: Daniel Polito <danielbpolito@gmail.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Co-authored-by: Dax Raad <d@ironbay.co>
Co-authored-by: Cason Adams <casonadams@gmail.com>
Co-authored-by: opencode <opencode@sst.dev>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: ry2009 <134240944+ry2009@users.noreply.github.com>
Co-authored-by: Julian Visser <12615757+justmejulian@users.noreply.github.com>
Co-authored-by: Anthony Shew <anthonyshew@gmail.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Noam Bressler <noamzbr@gmail.com>
Co-authored-by: noamzbr <noamzbr@users.noreply.github.com>
Co-authored-by: Nathan Thomas <nwthomas@me.com>
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
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.

3 participants