Skip to content

Add OpenTelemetry instrumentation#1617

Closed
parmesant wants to merge 1 commit intomainfrom
otel/instrument-1775696201194
Closed

Add OpenTelemetry instrumentation#1617
parmesant wants to merge 1 commit intomainfrom
otel/instrument-1775696201194

Conversation

@parmesant
Copy link
Copy Markdown
Contributor

@parmesant parmesant commented Apr 9, 2026

What changed

  • Cargo.toml — added opentelemetry 0.29, opentelemetry_sdk 0.29 (rt-tokio), opentelemetry-otlp 0.29 (http-json, grpc-tonic), tracing-opentelemetry 0.30
  • src/telemetry.rs — created OTel init module with init_otel_tracer() and build_otel_layer(), W3C TraceContext propagator, OTLP exporter defaulting to HTTP/JSON
  • src/lib.rs — registered pub mod telemetry
  • src/main.rs — wired OTel layer into init_logger(), added provider shutdown on exit
  • src/handlers/http/query.rs — instrumented query() (root span POST /query), handle_count_query(), handle_non_streaming_query(), handle_streaming_query(), create_streams_for_distributed() (with JoinSet span propagation), into_query()
  • src/query/mod.rs — instrumented execute() with W3C cross-runtime propagation to QUERY_RUNTIME, Query::execute(), get_bin_density(), get_manifest_list()

Dependencies added

  • opentelemetry 0.29
  • opentelemetry_sdk 0.29 (features: rt-tokio)
  • opentelemetry-otlp 0.29 (features: http-json, grpc-tonic)
  • tracing-opentelemetry 0.30

Co-authored-by: otex-dev dev@otex.dev

Summary by CodeRabbit

Release Notes

New Features

  • Added OpenTelemetry integration for distributed tracing and observability
  • HTTP queries and database operations now emit detailed trace spans
  • Support for OTLP protocol-based trace exporters via environment configuration
  • Improved visibility into query execution and request handling across the system

## What changed
- `Cargo.toml` — added opentelemetry 0.29, opentelemetry_sdk 0.29 (rt-tokio), opentelemetry-otlp 0.29 (http-json, grpc-tonic), tracing-opentelemetry 0.30
- `src/telemetry.rs` — created OTel init module with `init_otel_tracer()` and `build_otel_layer()`, W3C TraceContext propagator, OTLP exporter defaulting to HTTP/JSON
- `src/lib.rs` — registered `pub mod telemetry`
- `src/main.rs` — wired OTel layer into `init_logger()`, added provider shutdown on exit
- `src/handlers/http/query.rs` — instrumented `query()` (root span `POST /query`), `handle_count_query()`, `handle_non_streaming_query()`, `handle_streaming_query()`, `create_streams_for_distributed()` (with JoinSet span propagation), `into_query()`
- `src/query/mod.rs` — instrumented `execute()` with W3C cross-runtime propagation to QUERY_RUNTIME, `Query::execute()`, `get_bin_density()`, `get_manifest_list()`

## Dependencies added
- opentelemetry 0.29
- opentelemetry_sdk 0.29 (features: rt-tokio)
- opentelemetry-otlp 0.29 (features: http-json, grpc-tonic)
- tracing-opentelemetry 0.30

Co-authored-by: otex-dev <dev@otex.dev>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b4ef7e0d-e003-4d2f-b61a-4145a36a3228

📥 Commits

Reviewing files that changed from the base of the PR and between 2469862 and 8fd8ecc.

📒 Files selected for processing (6)
  • Cargo.toml
  • src/handlers/http/query.rs
  • src/lib.rs
  • src/main.rs
  • src/query/mod.rs
  • src/telemetry.rs

Walkthrough

OpenTelemetry distributed tracing instrumentation was integrated into the project. Cargo dependencies were extended with OpenTelemetry SDK and related crates, a new telemetry module was created to initialize the OTel tracer, and tracing spans were added throughout HTTP handlers and query execution paths with trace context propagation across thread boundaries.

Changes

Cohort / File(s) Summary
Dependencies
Cargo.toml
Added OpenTelemetry SDK (0.29), opentelemetry-otlp (0.29 with HTTP and gRPC support), and tracing-opentelemetry (0.30).
Telemetry Infrastructure
src/telemetry.rs
New module implementing init_otel_tracer() for conditional OpenTelemetry initialization from environment config and build_otel_layer() for creating tracing subscriber layers.
Module Exports
src/lib.rs
Exposed telemetry module as public API.
Application Initialization
src/main.rs
Modified init_logger() to return Option<SdkTracerProvider>, integrating OTel layer into tracing registry and gracefully shutting down provider on application exit.
HTTP Query Handler
src/handlers/http/query.rs
Added #[instrument] spans to query handler and internal helpers (handle_count_query, handle_non_streaming_query, handle_streaming_query, create_streams_for_distributed, into_query) with instrumented task spawning.
Query Execution
src/query/mod.rs
Added #[instrument] spans to execute, Query::execute, CountsRequest::get_bin_density, and get_manifest_list; introduced W3C text-map trace context propagation across the dedicated query runtime thread pool.

Sequence Diagram

sequenceDiagram
    actor Client
    participant HTTP as HTTP Handler
    participant QueryExec as Query Executor
    participant QueryRuntime as QUERY_RUNTIME<br/>(Thread Pool)
    participant Exporter as OpenTelemetry<br/>Exporter
    
    Client->>HTTP: POST /query
    activate HTTP
    HTTP->>HTTP: Start "query" span
    HTTP->>QueryExec: execute(query)
    activate QueryExec
    QueryExec->>QueryExec: Extract trace context<br/>Create carrier (W3C)
    QueryExec->>QueryRuntime: Spawn task with carrier
    activate QueryRuntime
    QueryRuntime->>QueryRuntime: Extract context from carrier<br/>Create "query.execute_runtime" span
    QueryRuntime->>QueryRuntime: Set parent span context<br/>Execute query logic
    QueryRuntime->>Exporter: Emit spans
    deactivate QueryRuntime
    QueryExec-->>HTTP: Return results
    deactivate QueryExec
    HTTP-->>Client: 200 OK
    deactivate HTTP
    Exporter->>Exporter: Batch and export traces
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • parseablehq/parseable#1226: Modifies the same query execution code path in src/query/mod.rs including top-level execute() and Query::execute() functions, requiring coordination for trace context and instrumentation interaction.

Suggested reviewers

  • nikhilsinhaparseable

Poem

🐰 Hop, hop, a trace is born!
Spans dance through the code at dawn,
Thread pools linked with context ties,
OpenTelemetry sees all eyes,
Observability now in flight!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch otel/instrument-1775696201194

Comment @coderabbitai help to get the list of available commands and usage tips.

@parmesant parmesant closed this Apr 9, 2026
@nitisht nitisht deleted the otel/instrument-1775696201194 branch April 9, 2026 14:14
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.

1 participant