Skip to content

Trailing slashes are stripped from trace endpoint URLs #6709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mjq opened this issue Apr 29, 2025 · 0 comments · May be fixed by #6710
Open

Trailing slashes are stripped from trace endpoint URLs #6709

mjq opened this issue Apr 29, 2025 · 0 comments · May be fixed by #6710
Labels
bug Something isn't working pkg:exporter:otlp Related to the OTLP exporter package

Comments

@mjq
Copy link

mjq commented Apr 29, 2025

Description

When setting an explicit OTLP traces endpoint URL (via otlptracehttp.WithEndpointURL or the OTEL_EXPORTER_OTLP_TRACES_ENDPOINT environment variable), any given trailing slash is stripped. This makes it impossible to export traces to an endpoint requiring a trailing slash. It also conflicts with the spec:

For the per-signal variables (OTEL_EXPORTER_OTLP_<signal>_ENDPOINT), the URL MUST be used as-is without any modification. The only exception is that if an URL contains no path part, the root path / MUST be used (see Example 2).

This stripping happens due to the use of path.Clean in otlpconfig.cleanPath. From the path.Clean docs:

The returned path ends in a slash only if it is the root "/".

Other signals appear to use path.Clean and might therefore have the same bug, but I've only tested traces.

Environment

  • OS: macOS
  • Architecture: arm64
  • Go Version: 1.24.2
  • opentelemetry-go version: v1.35.0, b4b461d (current main HEAD)

Steps To Reproduce

The following tests fail (with a URLPath of /somepath and /endpoint respectively).

diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go
index 55a3ad96..16aadf6c 100644
--- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go
+++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go
@@ -102,6 +102,15 @@ func TestConfigs(t *testing.T) {
                                assert.True(t, c.Traces.Insecure)
                        },
                },
+               {
+                       name: "Test With Endpoint URL With Trailing Slash",
+                       opts: []GenericOption{
+                               WithEndpointURL("http://someendpoint/somepath/"),
+                       },
+                       asserts: func(t *testing.T, c *Config, grpcOption bool) {
+                               assert.Equal(t, "/somepath/", c.Traces.URLPath)
+                       },
+               },
                {
                        name: "Test With Secure Endpoint URL",
                        opts: []GenericOption{
@@ -190,6 +199,17 @@ func TestConfigs(t *testing.T) {
                                }
                        },
                },
+               {
+                       name: "Test Environment Signal Specific Endpoint With Trailing Slash",
+                       env: map[string]string{
+                               "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "http://env.traces/endpoint/",
+                       },
+                       asserts: func(t *testing.T, c *Config, grpcOption bool) {
+                               if !grpcOption {
+                                       assert.Equal(t, "/endpoint/", c.Traces.URLPath)
+                               }
+                       },
+               },
                {
                        name: "Test Mixed Environment and With Endpoint",
                        opts: []GenericOption{

Expected behavior

Trace endpoint URLs with trailing slashes should be used by the exporter without modification.

@mjq mjq added the bug Something isn't working label Apr 29, 2025
@pellared pellared added the pkg:exporter:otlp Related to the OTLP exporter package label May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:exporter:otlp Related to the OTLP exporter package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants