You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-10-08 23:21:56 +02:00
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`](b4b461d050/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.
This commit is contained in:
@@ -34,6 +34,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- The semantic conventions have been upgraded from `v1.26.0` to `v1.34.0` in `go.opentelemetry.io/otel/sdk/trace`. (#6835)
|
||||
- The semantic conventions have been upgraded from `v1.26.0` to `v1.34.0` in `go.opentelemetry.io/otel/trace`. (#6836)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#6710)
|
||||
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#6710)
|
||||
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#6710)
|
||||
- Stop stripping trailing slashes from configured endpoint URL in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#6710)
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
||||
|
@@ -105,12 +105,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// cleanPath returns a path with all spaces trimmed and all redundancies
|
||||
// removed. If urlPath is empty or cleaning it results in an empty string,
|
||||
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
|
||||
// defaultPath is returned instead.
|
||||
func cleanPath(urlPath string, defaultPath string) string {
|
||||
tmp := path.Clean(strings.TrimSpace(urlPath))
|
||||
if tmp == "." {
|
||||
tmp := strings.TrimSpace(urlPath)
|
||||
if tmp == "" || tmp == "." {
|
||||
return defaultPath
|
||||
}
|
||||
if !path.IsAbs(tmp) {
|
||||
|
@@ -627,10 +627,10 @@ func TestCleanPath(t *testing.T) {
|
||||
{
|
||||
name: "clean traces path",
|
||||
args: args{
|
||||
urlPath: "https://env_endpoint",
|
||||
urlPath: "https://env_endpoint/ ",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "/https:/env_endpoint",
|
||||
want: "/https://env_endpoint/",
|
||||
},
|
||||
{
|
||||
name: "spaces trimmed",
|
||||
@@ -639,14 +639,6 @@ func TestCleanPath(t *testing.T) {
|
||||
},
|
||||
want: "/dir",
|
||||
},
|
||||
{
|
||||
name: "clean path empty",
|
||||
args: args{
|
||||
urlPath: "dir/..",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "DefaultTracesPath",
|
||||
},
|
||||
{
|
||||
name: "make absolute",
|
||||
args: args{
|
||||
|
@@ -105,12 +105,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// cleanPath returns a path with all spaces trimmed and all redundancies
|
||||
// removed. If urlPath is empty or cleaning it results in an empty string,
|
||||
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
|
||||
// defaultPath is returned instead.
|
||||
func cleanPath(urlPath string, defaultPath string) string {
|
||||
tmp := path.Clean(strings.TrimSpace(urlPath))
|
||||
if tmp == "." {
|
||||
tmp := strings.TrimSpace(urlPath)
|
||||
if tmp == "" || tmp == "." {
|
||||
return defaultPath
|
||||
}
|
||||
if !path.IsAbs(tmp) {
|
||||
|
@@ -627,10 +627,10 @@ func TestCleanPath(t *testing.T) {
|
||||
{
|
||||
name: "clean traces path",
|
||||
args: args{
|
||||
urlPath: "https://env_endpoint",
|
||||
urlPath: "https://env_endpoint/ ",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "/https:/env_endpoint",
|
||||
want: "/https://env_endpoint/",
|
||||
},
|
||||
{
|
||||
name: "spaces trimmed",
|
||||
@@ -639,14 +639,6 @@ func TestCleanPath(t *testing.T) {
|
||||
},
|
||||
want: "/dir",
|
||||
},
|
||||
{
|
||||
name: "clean path empty",
|
||||
args: args{
|
||||
urlPath: "dir/..",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "DefaultTracesPath",
|
||||
},
|
||||
{
|
||||
name: "make absolute",
|
||||
args: args{
|
||||
|
@@ -92,12 +92,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// cleanPath returns a path with all spaces trimmed and all redundancies
|
||||
// removed. If urlPath is empty or cleaning it results in an empty string,
|
||||
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
|
||||
// defaultPath is returned instead.
|
||||
func cleanPath(urlPath string, defaultPath string) string {
|
||||
tmp := path.Clean(strings.TrimSpace(urlPath))
|
||||
if tmp == "." {
|
||||
tmp := strings.TrimSpace(urlPath)
|
||||
if tmp == "" || tmp == "." {
|
||||
return defaultPath
|
||||
}
|
||||
if !path.IsAbs(tmp) {
|
||||
|
@@ -569,10 +569,10 @@ func TestCleanPath(t *testing.T) {
|
||||
{
|
||||
name: "clean traces path",
|
||||
args: args{
|
||||
urlPath: "https://env_endpoint",
|
||||
urlPath: "https://env_endpoint/ ",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "/https:/env_endpoint",
|
||||
want: "/https://env_endpoint/",
|
||||
},
|
||||
{
|
||||
name: "spaces trimmed",
|
||||
@@ -581,14 +581,6 @@ func TestCleanPath(t *testing.T) {
|
||||
},
|
||||
want: "/dir",
|
||||
},
|
||||
{
|
||||
name: "clean path empty",
|
||||
args: args{
|
||||
urlPath: "dir/..",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "DefaultTracesPath",
|
||||
},
|
||||
{
|
||||
name: "make absolute",
|
||||
args: args{
|
||||
|
@@ -92,12 +92,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// cleanPath returns a path with all spaces trimmed and all redundancies
|
||||
// removed. If urlPath is empty or cleaning it results in an empty string,
|
||||
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
|
||||
// defaultPath is returned instead.
|
||||
func cleanPath(urlPath string, defaultPath string) string {
|
||||
tmp := path.Clean(strings.TrimSpace(urlPath))
|
||||
if tmp == "." {
|
||||
tmp := strings.TrimSpace(urlPath)
|
||||
if tmp == "" || tmp == "." {
|
||||
return defaultPath
|
||||
}
|
||||
if !path.IsAbs(tmp) {
|
||||
|
@@ -569,10 +569,10 @@ func TestCleanPath(t *testing.T) {
|
||||
{
|
||||
name: "clean traces path",
|
||||
args: args{
|
||||
urlPath: "https://env_endpoint",
|
||||
urlPath: "https://env_endpoint/ ",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "/https:/env_endpoint",
|
||||
want: "/https://env_endpoint/",
|
||||
},
|
||||
{
|
||||
name: "spaces trimmed",
|
||||
@@ -581,14 +581,6 @@ func TestCleanPath(t *testing.T) {
|
||||
},
|
||||
want: "/dir",
|
||||
},
|
||||
{
|
||||
name: "clean path empty",
|
||||
args: args{
|
||||
urlPath: "dir/..",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "DefaultTracesPath",
|
||||
},
|
||||
{
|
||||
name: "make absolute",
|
||||
args: args{
|
||||
|
@@ -105,12 +105,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// cleanPath returns a path with all spaces trimmed and all redundancies
|
||||
// removed. If urlPath is empty or cleaning it results in an empty string,
|
||||
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
|
||||
// defaultPath is returned instead.
|
||||
func cleanPath(urlPath string, defaultPath string) string {
|
||||
tmp := path.Clean(strings.TrimSpace(urlPath))
|
||||
if tmp == "." {
|
||||
tmp := strings.TrimSpace(urlPath)
|
||||
if tmp == "" || tmp == "." {
|
||||
return defaultPath
|
||||
}
|
||||
if !path.IsAbs(tmp) {
|
||||
|
@@ -627,10 +627,10 @@ func TestCleanPath(t *testing.T) {
|
||||
{
|
||||
name: "clean traces path",
|
||||
args: args{
|
||||
urlPath: "https://env_endpoint",
|
||||
urlPath: "https://env_endpoint/ ",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "/https:/env_endpoint",
|
||||
want: "/https://env_endpoint/",
|
||||
},
|
||||
{
|
||||
name: "spaces trimmed",
|
||||
@@ -639,14 +639,6 @@ func TestCleanPath(t *testing.T) {
|
||||
},
|
||||
want: "/dir",
|
||||
},
|
||||
{
|
||||
name: "clean path empty",
|
||||
args: args{
|
||||
urlPath: "dir/..",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "DefaultTracesPath",
|
||||
},
|
||||
{
|
||||
name: "make absolute",
|
||||
args: args{
|
||||
|
@@ -92,12 +92,11 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// cleanPath returns a path with all spaces trimmed and all redundancies
|
||||
// removed. If urlPath is empty or cleaning it results in an empty string,
|
||||
// cleanPath returns a path with all spaces trimmed. If urlPath is empty,
|
||||
// defaultPath is returned instead.
|
||||
func cleanPath(urlPath string, defaultPath string) string {
|
||||
tmp := path.Clean(strings.TrimSpace(urlPath))
|
||||
if tmp == "." {
|
||||
tmp := strings.TrimSpace(urlPath)
|
||||
if tmp == "" || tmp == "." {
|
||||
return defaultPath
|
||||
}
|
||||
if !path.IsAbs(tmp) {
|
||||
|
@@ -569,10 +569,10 @@ func TestCleanPath(t *testing.T) {
|
||||
{
|
||||
name: "clean traces path",
|
||||
args: args{
|
||||
urlPath: "https://env_endpoint",
|
||||
urlPath: "https://env_endpoint/ ",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "/https:/env_endpoint",
|
||||
want: "/https://env_endpoint/",
|
||||
},
|
||||
{
|
||||
name: "spaces trimmed",
|
||||
@@ -581,14 +581,6 @@ func TestCleanPath(t *testing.T) {
|
||||
},
|
||||
want: "/dir",
|
||||
},
|
||||
{
|
||||
name: "clean path empty",
|
||||
args: args{
|
||||
urlPath: "dir/..",
|
||||
defaultPath: "DefaultTracesPath",
|
||||
},
|
||||
want: "DefaultTracesPath",
|
||||
},
|
||||
{
|
||||
name: "make absolute",
|
||||
args: args{
|
||||
|
Reference in New Issue
Block a user