Skip to content

fix(telemetry): honour a base path in the OTLP HTTP endpoint - #667

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
fafg:fix/otlp-http-endpoint-base-path
Aug 1, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
fafg:fix/otlp-http-endpoint-base-path

Conversation

@fafg

@fafg fafg commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

The OTLP HTTP exporters were configured with WithEndpoint, which takes a bare host:port and cannot express a path, and WithURLPath is never called. Any path in OTEL_EXPORTER_OTLP_ENDPOINT was therefore discarded and every request went to /v1/traces (or /v1/metrics) at the root of the host.

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

OTEL_EXPORTER_OTLP_ENDPOINT=http://langfuse:3000/api/public/otel
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf

produced requests to http://langfuse:3000/v1/traces. The backend answered 404 and every span was dropped. Nothing surfaced the problem: exporter creation is lazy, so telemetry appears to initialise correctly and the failure only shows up as missing data.

The change

The HTTP path now uses WithEndpointURL, which accepts a scheme and a path and derives TLS from the scheme — replacing the explicit WithInsecure call so the decision is made from one source rather than two.

The signal path is appended by a new otlpSignalURL helper rather than left to the SDK, because WithEndpointURL assigns the URL's path straight to URLPath and so expects the full signal URL, while OTEL_EXPORTER_OTLP_ENDPOINT is specified as a base.

Existing behaviour is preserved in both directions:

Endpoint Before After
http://host:4318 plaintext, /v1/traces plaintext, /v1/traces
https://host:4318 TLS, /v1/traces TLS, /v1/traces
host:4318 (no scheme) TLS, /v1/traces TLS, /v1/traces
http://host:3000/base plaintext, /v1/traces ❌ plaintext, /base/v1/traces ✅
http://host:4318/v1/traces plaintext, /v1/traces plaintext, /v1/traces (not doubled)

The last row matters: anyone who worked around this by writing the signal path out in full keeps working.

parseOTLPEndpoint is unchanged and still used by the gRPC path, where WithEndpoint genuinely does take a bare host:port — gRPC has no URL path.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • Manual testing (described below)

Two tests were added:

  • TestInitOTLPHTTPProviders_HonoursBasePath stands up an httptest collector under a /api/public/otel prefix, exports a span, and asserts on the request path the collector actually receives. This is the regression test: it fails against the previous implementation (receives /v1/traces, wants /api/public/otel/v1/traces), which I verified by reverting the fix with the test in place. It also covers the TLS decision that moved into WithEndpointURL — httptest.NewServer speaks plaintext, so the request only arrives if Insecure was resolved to true from the http:// scheme.
  • TestOTLPSignalURL covers the normalisation table above, including the trailing-slash and already-has-the-signal-path cases.

Existing tests are unchanged and pass, including TestParseOTLPEndpoint (that function keeps its behaviour for gRPC).

Verified with the project's own targets: gofmt -s clean, go vet clean, go test -race -count=1 ./internal/telemetry/ green.

Manual verification of the real-world case that prompted this: with OTEL_ENABLE_TELEMETRY=1 and an endpoint carrying a base path, requests now reach <base>/v1/traces instead of /v1/traces.

Documentation

pages/src/content/docs/*/telemetry.md claimed in two places that the HTTP protocols were "accepted but not yet wired up". They are — initOTLPProviders routes both to initOTLPHTTPProviders, and TestInitOTLPProviders_ProtocolRouting covers it.

The troubleshooting row was the more costly of the two, because it surfaces exactly when someone is debugging this and points the wrong way ("switching it won't help ... verify the collector is listening for gRPC"). Replaced with the check that does help, plus a row for the failure mode that produces no error at all: exporter creation is lazy, so a wrong endpoint fails silently at export time.

Also added an Endpoint format section covering three things that were undocumented and are each easy to get wrong:

  • the scheme decides transport security (http:// plaintext, https:// and bare host:port TLS);
  • the default port differs by protocol — 4317 for gRPC, 4318 for HTTP — while every example used 4317;
  • for the HTTP protocols the endpoint is a base URL to which the signal path is appended, and a base path is preserved.

Translations: the ja and zh code blocks carry that note in English, so they are corrected here. Their troubleshooting rows are translated prose and I have deliberately left them alone rather than guess at Japanese and Chinese I cannot review — they still carry the outdated claim and would need a translator:

  • pages/src/content/docs/ja/telemetry.md:249
  • pages/src/content/docs/zh/telemetry.md:249

Happy to take a suggested wording in either language and apply it here.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

closes #668

@CLAassistant

CLAassistant commented Aug 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: No comments generated. Looks good to me.

The HTTP exporters were configured with WithEndpoint, which takes a bare
host:port and cannot express a path, and WithURLPath was never called. Any
path in OTEL_EXPORTER_OTLP_ENDPOINT was therefore discarded and every request
went to /v1/traces at the root of the host.

That silently excludes backends addressed through a path prefix. Langfuse
receives OTLP at /api/public/otel, so an endpoint of
"http://langfuse:3000/api/public/otel" produced requests to
"http://langfuse:3000/v1/traces": the collector answered 404 and every span
was dropped, with nothing on stderr to say why. The exporter is created
lazily, so telemetry appeared to initialise correctly.

Switches the HTTP path to WithEndpointURL, which accepts a scheme and a path
and derives TLS from the scheme — replacing the explicit WithInsecure call
with the same decision made from one source rather than two.

The signal path is appended by a new otlpSignalURL rather than left to the
SDK, because WithEndpointURL assigns the URL's path straight to URLPath and so
expects the full signal URL, while OTEL_EXPORTER_OTLP_ENDPOINT is specified as
a base. Existing behaviour is preserved in both directions: a bare host:port
still means 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.

parseOTLPEndpoint is unchanged and still used by the gRPC path, where
WithEndpoint genuinely does take a bare host:port.

TestInitOTLPHTTPProviders_HonoursBasePath asserts on the request path the
collector receives, which is what was wrong; it fails against the previous
implementation. TestOTLPSignalURL covers the normalisation, including the
trailing-slash and already-has-the-path cases.
…oint format

Two places claimed the HTTP protocols were not implemented. They are:
initOTLPProviders routes http/protobuf and http/json to initOTLPHTTPProviders,
which TestInitOTLPProviders_ProtocolRouting covers.

The troubleshooting row was the more costly of the two, because it appears
exactly when someone is debugging this and sends them the wrong way: it told
them switching the protocol "won't help" and to verify the collector is
listening for gRPC. Replaced with the check that does help, plus a row for the
failure mode that has no error at all — the exporter is created lazily, so a
wrong endpoint fails silently at export time rather than at startup.

Adds an endpoint-format section, since two things were undocumented and both
are easy to get wrong: the scheme decides transport security, and the default
port differs between gRPC (4317) and HTTP (4318) while every example used 4317.
It also documents that for the HTTP protocols the endpoint is a base URL to
which the signal path is appended, and that a base path is preserved — the
behaviour the accompanying fix restores.

The ja and zh code blocks carry the same note in English and are corrected
alongside. Their troubleshooting rows are translated prose and are left for a
translator rather than guessed at.
@fafg
fafg force-pushed the fix/otlp-http-endpoint-base-path branch from 8d5b3a6 to 891dc5f Compare August 1, 2026 08:18

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 5829539 into alibaba:main Aug 1, 2026
9 checks passed
Githab-capibara added a commit to Githab-capibara/open-code-review that referenced this pull request Sep 17, 2026
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.

OTLP HTTP exporter discards a base path in OTEL_EXPORTER_OTLP_ENDPOINT

3 participants