Skip to content

[Feature]: Propagation of trace/span ID into shell (and perhaps webfetch) tools #107

Description

@ivucica

Is your feature request related to a problem?

Currently the models cannot inject trace IDs/parent span IDs into the requests they're making because they don't see them.

This FR is similar to #62 but relates to builtin tools (generic shell invocation, webfetch) rather than MCPs.

Describe the solution you'd like

Assuming it's reasonably possible to do it with opencode's plugin architecture:

Since traceparent IDs are reasonably opaque (less problematic than much of the environment that's not being cleared away by OpenCode anyway -- api keys, etc), if OpenCode allows setting environment before invoking shell tool to execute commands, it would make sense to propagate the context via envvars. Then a script using curl could attach it as a header.

If possible for webfetch, it would make sense to attach it directly via the header -- in which case an allowlist of domains could be used as well.

I have not checked whether there's a properly standardized way, but I've spotted OTEL_BASH_PARENT_SPAN_ID and TRACEPARENT as possible environment variables to propagate (spotted in otel-bash). I don't know if SDK supports it, but it looks like otel-bash, terragrunt (reference) and otel-cli (reference) support TRACEPARENT.

Of course, this should be configurable and default to off.

Describe alternatives you've considered

Clearly a bad idea: Hack opencode-plugin-otel to write out desired env into tempfiles. Disable builtin opencode tools, and write custom MCPs for running bash commands and webfetch as described above. Hack opencode-plugin-pty to support the hacked env files.

Telemetry type

Other

Additional context

No response

Checklist

  • I have searched existing issues and discussions for similar feature requests
  • I have checked the changelog to see if this already exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions