Skip to content

Conversation

Schniz
Copy link
Contributor

@Schniz Schniz commented Jul 9, 2025

This branch adds OpenTelemetry (OTEL) instrumentation for performance monitoring and debugging across both the Node.js backend and Go TUI components.

Key changes:

  • Added telemetry infrastructure: New telemetry modules in both packages with OTEL tracing capabilities
  • Performance instrumentation: Spans and measurements added to critical paths like message processing, API calls, and UI operations
  • Refactored timing logic: Replaced custom timing utilities with standardized OTEL spans
  • Cross-language tracing: Coordinated telemetry between Node.js server and Go TUI client

The goal is to provide better observability into performance bottlenecks and user interaction patterns within the opencode application.


The way I'm using it is with Grafana LGTM stack (with my script) but the easiest way is probably otel-desktop-viewer. I think it only supports traces and not logs or metrics which I haven't implemented yet anyway.

An example run would be to do

$ otel-desktop-viewer &
...
$ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 opencode
[tui intensifies]

the going to localhost:8000 and see the traces in action :)

@Schniz Schniz force-pushed the schniz/add-otel-for-tracing branch from 1d79d13 to cf7d065 Compare July 9, 2025 13:29
@adamdotdevin
Copy link
Contributor

new perf issues reported #805 #811

@Schniz
Copy link
Contributor Author

Schniz commented Jul 10, 2025

Lots of conflicts because the proper golang way would probably be to not have a closure but instead defer a close span method. Will do

@Schniz Schniz force-pushed the schniz/add-otel-for-tracing branch 2 times, most recently from b447a57 to 638a830 Compare July 11, 2025 06:37
@Schniz
Copy link
Contributor Author

Schniz commented Jul 11, 2025

wrt #805 we can have a follow up to have metrics reported if otel is set up for cpu usage in each sub-process we invoke (like LSP)

@Schniz Schniz force-pushed the schniz/add-otel-for-tracing branch 7 times, most recently from 6a2bc71 to 60d94d1 Compare July 11, 2025 07:39
@Schniz Schniz marked this pull request as ready for review July 11, 2025 07:42
@Schniz
Copy link
Contributor Author

Schniz commented Jul 11, 2025

@adamdotdevin okay i think it's ready for a review. here's how the distributed traces look like:

image

you can see that "opencode-server" calls "opencode-tui" and then we see that the tui request has a child of "opencode-server".

some drawbacks but we can improve over time:

  • Every use of app.TelemetryContext is probably bad, because we use the "root span" instead of where it happened. It means we need to propagate context.Context more instead of using context.Background() everywhere (which I replaced with app.TelemetryContext) so we get the actual propagation of component->action->trace. Might be hard but I think that we can evolve this over time
  • SSE is still not traced well
  • no implementation for metrics, which might be valuable too.

@Schniz Schniz force-pushed the schniz/add-otel-for-tracing branch from 60d94d1 to bd1e10b Compare July 11, 2025 08:18
go mod tidy

Add more traces

starts to work, but logs weird, nvm for now

pass trace context to tui

otel propagation how fun

some refactoring

some refactoring

Refactor telemetry tracing in messages component

Improve telemetry instrumentation by using WithSpan for better span management and cleanup in the renderView method.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

remove util.Measure since we have otel now

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>

unused code

refactor: update bootstrap telemetry to use WithSpan directly

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>
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