Skip to content

OTLP HTTP exporter discards a base path in OTEL_EXPORTER_OTLP_ENDPOINT #668

Closed

Description

@fafg

OpenCodeReview Version

open-code-review v1.8.0 (e670b3b3) linux/arm64

Also reproduced against main at 80a5794.

Operating System

Linux (ARM64) — a container image, linux/arm64.

Installation Method

GitHub Release binary (pinned into a container image); also built from source to confirm.

LLM Provider

Other OpenAI-compatible endpoint (LiteLLM proxy). Not relevant to the bug — this is in the telemetry exporter, not the LLM path.

Bug Description

When OTEL_EXPORTER_OTLP_PROTOCOL selects an HTTP protocol, a base path in OTEL_EXPORTER_OTLP_ENDPOINT is silently discarded. Every request goes to /v1/traces (and /v1/metrics) at the root of the host instead of under the configured path.

internal/telemetry/exporter.go configures the HTTP exporters with WithEndpoint, which takes a bare host:port and cannot express a path — parseOTLPEndpoint strips the scheme and the exporter never calls WithURLPath, which does not appear anywhere in the repository.

This excludes any backend addressed through a path prefix. Langfuse, for example, receives OTLP at /api/public/otel.

The failure is silent, which is what makes it costly to diagnose:

  • Exporter creation is lazy, so telemetry initialises without error.
  • Nothing is written to stderr.
  • The backend answers 404 and the spans are simply gone.

From the outside it looks like telemetry is off, so the natural response is to check OCR_ENABLE_TELEMETRY, then the endpoint, then the protocol — none of which is wrong. I only found it by reading internal/telemetry/exporter.go.

Steps to Reproduce

  1. Start any OTLP/HTTP collector that serves under a path prefix. A one-line stand-in:

    python3 -c "
    import http.server
    class H(http.server.BaseHTTPRequestHandler):
        def do_POST(self):
            print('received POST', self.path, flush=True)
            self.send_response(200); self.send_header('Content-Length','0'); self.end_headers()
        def log_message(self,*a): pass
    http.server.HTTPServer(('127.0.0.1',4318),H).serve_forever()"
  2. Run a review with telemetry pointed at a base path on that collector:

    export OCR_ENABLE_TELEMETRY=1
    export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
    export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318/api/public/otel
    ocr review --from origin/main --to HEAD --format json
  3. Observe the path the collector receives.

Expected Behavior

received POST /api/public/otel/v1/traces

The OpenTelemetry specification defines OTEL_EXPORTER_OTLP_ENDPOINT for the HTTP protocols as a base URL to which the per-signal path is appended — an endpoint of https://backend.example.com sends traces to https://backend.example.com/v1/traces.

Logs / Error Output

received POST /v1/traces

The configured /api/public/otel prefix is gone. Against a real backend this is a 404 and the spans are dropped; ocr itself prints nothing.

Additional Context

The gRPC path is correct as written and should not change — gRPC has no URL path, and WithEndpoint there genuinely does take a bare host:port.

I have opened #667 with a fix: the HTTP path switches to WithEndpointURL (which accepts a scheme and a path, and derives TLS from the scheme) with the signal path appended by a small helper, since WithEndpointURL assigns the URL's path straight to URLPath and so expects the full signal URL while the environment variable is specified as a base.

Existing behaviour is preserved for every endpoint form that works today, including a bare host:port still meaning TLS, and an endpoint that already names /v1/traces is left alone rather than doubled — so a configuration written to work around this does not break.

The PR includes a regression test that asserts on the request path the collector receives, and which fails against the current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions