Repository navigation
fix(telemetry): honour a base path in the OTLP HTTP endpoint - #667
Merged
lizhengfeng101 merged 2 commits intoAug 1, 2026
Merged
Conversation
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.
fafg
force-pushed
the
fix/otlp-http-endpoint-base-path
branch
from
August 1, 2026 07:59
8c68612 to
1c28173
Compare
…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
force-pushed
the
fix/otlp-http-endpoint-base-path
branch
from
August 1, 2026 08:18
8d5b3a6 to
891dc5f
Compare
Githab-capibara
added a commit
to Githab-capibara/open-code-review
that referenced
this pull request
Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The OTLP HTTP exporters were configured with
WithEndpoint, which takes a barehost:portand cannot express a path, andWithURLPathis never called. Any path inOTEL_EXPORTER_OTLP_ENDPOINTwas 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:produced requests to
http://langfuse:3000/v1/traces. The backend answered404and 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 explicitWithInsecurecall so the decision is made from one source rather than two.The signal path is appended by a new
otlpSignalURLhelper rather than left to the SDK, becauseWithEndpointURLassigns the URL's path straight toURLPathand so expects the full signal URL, whileOTEL_EXPORTER_OTLP_ENDPOINTis specified as a base.Existing behaviour is preserved in both directions:
http://host:4318/v1/traces/v1/traceshttps://host:4318/v1/traces/v1/traceshost:4318(no scheme)/v1/traces/v1/traceshttp://host:3000/base/v1/traces❌/base/v1/traces✅http://host:4318/v1/traces/v1/traces/v1/traces(not doubled)The last row matters: anyone who worked around this by writing the signal path out in full keeps working.
parseOTLPEndpointis unchanged and still used by the gRPC path, whereWithEndpointgenuinely does take a barehost:port— gRPC has no URL path.Type of Change
How Has This Been Tested?
make testpasses locallyTwo tests were added:
TestInitOTLPHTTPProviders_HonoursBasePathstands up anhttptestcollector under a/api/public/otelprefix, 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 intoWithEndpointURL—httptest.NewServerspeaks plaintext, so the request only arrives ifInsecurewas resolved totruefrom thehttp://scheme.TestOTLPSignalURLcovers 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 -sclean,go vetclean,go test -race -count=1 ./internal/telemetry/green.Manual verification of the real-world case that prompted this: with
OTEL_ENABLE_TELEMETRY=1and an endpoint carrying a base path, requests now reach<base>/v1/tracesinstead of/v1/traces.Documentation
pages/src/content/docs/*/telemetry.mdclaimed in two places that the HTTP protocols were "accepted but not yet wired up". They are —initOTLPProvidersroutes both toinitOTLPHTTPProviders, andTestInitOTLPProviders_ProtocolRoutingcovers 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:
http://plaintext,https://and barehost:portTLS);4317for gRPC,4318for HTTP — while every example used4317;Translations: the
jaandzhcode 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:249pages/src/content/docs/zh/telemetry.md:249Happy to take a suggested wording in either language and apply it here.
Checklist
go fmt,go vet)Related Issues
closes #668