Skip to content

Support standard OTEL SDK environment variables#98

Open
pavolloffay wants to merge 3 commits into
openshift:mainfrom
pavolloffay:use-otel-sdk-autoconfig
Open

Support standard OTEL SDK environment variables#98
pavolloffay wants to merge 3 commits into
openshift:mainfrom
pavolloffay:use-otel-sdk-autoconfig

Conversation

@pavolloffay

@pavolloffay pavolloffay commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Refactor tracer initialization to respect all standard OTEL_* environment variables
  • Add support for OTEL_SERVICE_NAME, OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_HEADERS, OTEL_RESOURCE_ATTRIBUTES, OTEL_TRACES_EXPORTER
  • Add opentelemetry-exporter-otlp-proto-http dependency for HTTP protocol support

Test plan

  • Deploy with OTEL_EXPORTER_OTLP_ENDPOINT only (backward compatible)
  • Test OTEL_SERVICE_NAME override
  • Test OTEL_EXPORTER_OTLP_INSECURE=true for explicit TLS control
  • Test OTEL_TRACES_EXPORTER=none disables export
  • Verify traces appear in Tempo with a test Proposal

Test Image: ghcr.io/pavolloffay/lightspeed-agentic-sandbox:otel-sdk-autoconfig

🤖 Generated with Claude Code

The tracer initialization now respects all standard OTEL_* environment
variables instead of only OTEL_EXPORTER_OTLP_ENDPOINT:

- OTEL_SERVICE_NAME: Override service name
- OTEL_EXPORTER_OTLP_INSECURE: Explicit TLS control
- OTEL_EXPORTER_OTLP_PROTOCOL: Protocol selection (grpc/http)
- OTEL_EXPORTER_OTLP_HEADERS: Custom headers (auth tokens)
- OTEL_RESOURCE_ATTRIBUTES: Additional resource attributes
- OTEL_TRACES_EXPORTER: Exporter selection (otlp/console/none)

Also adds opentelemetry-exporter-otlp-proto-http dependency to support
the HTTP protocol option.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ac5a4417-5d09-465b-a0d3-eceb13086d2c

📥 Commits

Reviewing files that changed from the base of the PR and between 0b87447 and 6cfaefa.

📒 Files selected for processing (1)
  • src/lightspeed_agentic/tracing.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/lightspeed-agentic-operator (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lightspeed_agentic/tracing.py

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Expanded tracing support with configurable OpenTelemetry export options.
    • Added support for HTTP/protobuf OTLP export alongside existing gRPC export.
    • Tracing now honors service name, resource attributes, endpoint, headers, protocol, and TLS/insecure settings from environment configuration.

Walkthrough

Adds an OTLP HTTP exporter dependency and updates tracer initialization to build resources from OTEL environment variables, select exporter transport/protocol, and parse exporter headers.

Changes

OTel tracing setup

Layer / File(s) Summary
HTTP exporter dependency
pyproject.toml
Adds opentelemetry-exporter-otlp-proto-http>=1.33.0 to project dependencies.
Tracer initialization and helper docs
src/lightspeed_agentic/tracing.py
Updates init_tracer() to derive Resource data from OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES, configure OTLP export from OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_TRACES_EXPORTER, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_INSECURE, and OTEL_EXPORTER_OTLP_HEADERS, and adds docstrings for shutdown_tracer(), get_tracer(), parse_traceparent(), and _generate_trace_id().

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant init_tracer
  participant Resource
  participant OTLPExporter
  participant TracerProvider

  App->>init_tracer: call init_tracer()
  init_tracer->>Resource: build from OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES
  init_tracer->>init_tracer: read OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_TRACES_EXPORTER, OTEL_EXPORTER_OTLP_PROTOCOL
  init_tracer->>OTLPExporter: configure transport, TLS, and headers
  init_tracer->>TracerProvider: attach BatchSpanProcessor
  TracerProvider-->>App: tracer ready
Loading

Related Issues: None specified.

Related PRs: None specified.

Suggested labels: tracing, dependencies

Suggested reviewers: None specified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the PR's main change: adding standard OTEL SDK env var support.
Description check ✅ Passed The description is on-topic and matches the tracer and dependency changes in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@openshift-ci openshift-ci Bot requested review from joshuawilson and raptorsun July 6, 2026 16:58
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign blublinsky for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lightspeed_agentic/tracing.py`:
- Line 11: The OTEL_TRACES_EXPORTER documentation and implementation are
inconsistent because the documented console mode is not actually handled in
tracing.py. Update the exporter selection logic in the tracing setup so the
TracerProvider/export configuration explicitly supports
OTEL_TRACES_EXPORTER=console (for example by wiring a console/span exporter
path) or remove console from the documented options, and make sure the same
behavior is reflected wherever exporter choices are parsed or described,
including the traced setup around the exporter selection and related lines near
the fallback handling.
- Around line 67-75: The OTLP header parsing in tracing.py should decode
URL-encoded header values before they are appended to the headers list. Update
the custom header handling in the logic that reads OTEL_EXPORTER_OTLP_HEADERS so
that each parsed value is unquoted/decoded after splitting key and value, while
keeping the existing headers_env parsing and headers.append flow intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ac6c5565-863e-459c-96a6-06b7693a095c

📥 Commits

Reviewing files that changed from the base of the PR and between a33a945 and db1cf71.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !uv.lock
📒 Files selected for processing (2)
  • pyproject.toml
  • src/lightspeed_agentic/tracing.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/lightspeed-agentic-operator (manual)

Comment thread src/lightspeed_agentic/tracing.py Outdated
Comment thread src/lightspeed_agentic/tracing.py Outdated
…ders

- Remove 'console' from OTEL_TRACES_EXPORTER documentation (not implemented)
- URL-decode OTEL_EXPORTER_OTLP_HEADERS values per OTEL spec (W3C Baggage format)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown

@pavolloffay: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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