-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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
mainHEAD)
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.