Skip to content

Commit 1636bcd

Browse files
authored
fix(otlptrace,otlpmetric): remove endpoint URL path cleaning (#6710)
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](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#endpoint-urls-for-otlphttp): > 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](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#example-2)). This stripping happens due to [the use of `path.Clean` in `otlpconfig.cleanPath`](https://github.com/open-telemetry/opentelemetry-go/blob/b4b461d050f1d0f5bda89ddac718180162120606/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go#L97). From [the `path.Clean` docs](https://pkg.go.dev/path#Clean): > The returned path ends in a slash only if it is the root "/". Fixes #6709.
1 parent 274e939 commit 1636bcd

File tree

13 files changed

+37
-84
lines changed

13 files changed

+37
-84
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3434
- The semantic conventions have been upgraded from `v1.26.0` to `v1.34.0` in `go.opentelemetry.io/otel/sdk/trace`. (#6835)
3535
- The semantic conventions have been upgraded from `v1.26.0` to `v1.34.0` in `go.opentelemetry.io/otel/trace`. (#6836)
3636

37+
### Fixed
38+
39+
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#6710)
40+
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#6710)
41+
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#6710)
42+
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#6710)
43+
3744
<!-- Released section -->
3845
<!-- Don't change this section unless doing release -->
3946

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/shared/otlp/otlpmetric/oconf/options.go.tmpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
105105
return cfg
106106
}
107107

108-
// cleanPath returns a path with all spaces trimmed and all redundancies
109-
// removed. If urlPath is empty or cleaning it results in an empty string,
108+
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
110109
// defaultPath is returned instead.
111110
func cleanPath(urlPath string, defaultPath string) string {
112-
tmp := path.Clean(strings.TrimSpace(urlPath))
113-
if tmp == "." {
111+
tmp := strings.TrimSpace(urlPath)
112+
if tmp == "" || tmp == "." {
114113
return defaultPath
115114
}
116115
if !path.IsAbs(tmp) {

internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ func TestCleanPath(t *testing.T) {
627627
{
628628
name: "clean traces path",
629629
args: args{
630-
urlPath: "https://env_endpoint",
630+
urlPath: "https://env_endpoint/ ",
631631
defaultPath: "DefaultTracesPath",
632632
},
633-
want: "/https:/env_endpoint",
633+
want: "/https://env_endpoint/",
634634
},
635635
{
636636
name: "spaces trimmed",
@@ -639,14 +639,6 @@ func TestCleanPath(t *testing.T) {
639639
},
640640
want: "/dir",
641641
},
642-
{
643-
name: "clean path empty",
644-
args: args{
645-
urlPath: "dir/..",
646-
defaultPath: "DefaultTracesPath",
647-
},
648-
want: "DefaultTracesPath",
649-
},
650642
{
651643
name: "make absolute",
652644
args: args{

internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
9292
return cfg
9393
}
9494

95-
// cleanPath returns a path with all spaces trimmed and all redundancies
96-
// removed. If urlPath is empty or cleaning it results in an empty string,
95+
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
9796
// defaultPath is returned instead.
9897
func cleanPath(urlPath string, defaultPath string) string {
99-
tmp := path.Clean(strings.TrimSpace(urlPath))
100-
if tmp == "." {
98+
tmp := strings.TrimSpace(urlPath)
99+
if tmp == "" || tmp == "." {
101100
return defaultPath
102101
}
103102
if !path.IsAbs(tmp) {

internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ func TestCleanPath(t *testing.T) {
569569
{
570570
name: "clean traces path",
571571
args: args{
572-
urlPath: "https://env_endpoint",
572+
urlPath: "https://env_endpoint/ ",
573573
defaultPath: "DefaultTracesPath",
574574
},
575-
want: "/https:/env_endpoint",
575+
want: "/https://env_endpoint/",
576576
},
577577
{
578578
name: "spaces trimmed",
@@ -581,14 +581,6 @@ func TestCleanPath(t *testing.T) {
581581
},
582582
want: "/dir",
583583
},
584-
{
585-
name: "clean path empty",
586-
args: args{
587-
urlPath: "dir/..",
588-
defaultPath: "DefaultTracesPath",
589-
},
590-
want: "DefaultTracesPath",
591-
},
592584
{
593585
name: "make absolute",
594586
args: args{

0 commit comments

Comments
 (0)