Skip to content
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

opentelemetry-otlp: '/v1/traces' is not appended to endpoint for http exporter #997

Closed
bouk opened this issue Mar 14, 2023 · 3 comments · Fixed by #1553
Closed

opentelemetry-otlp: '/v1/traces' is not appended to endpoint for http exporter #997

bouk opened this issue Mar 14, 2023 · 3 comments · Fixed by #1553

Comments

@bouk
Copy link
Contributor

bouk commented Mar 14, 2023

The HTTP exporter doesn't add /v1/traces to the 'endpoint' specified in the config:

/// Builds a new span exporter with the given configuration
#[cfg(feature = "http-proto")]
pub fn new_http(config: ExportConfig, http_config: HttpConfig) -> Result<Self, crate::Error> {
let url: Uri = config
.endpoint
.parse()
.map_err::<crate::Error, _>(Into::into)?;
Ok(SpanExporter::Http {
trace_exporter: http_config.client,
timeout: config.timeout,
collector_endpoint: url,
headers: http_config.headers,
})
}
}

This seems like an oversight because this is done in other places:

/// Builds a new span exporter with the given configuration.
#[cfg(feature = "grpc-tonic")]
pub fn new_tonic(
config: ExportConfig,
tonic_config: TonicConfig,
) -> Result<Self, crate::Error> {
let endpoint_str = match std::env::var(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) {
Ok(val) => val,
Err(_) => format!("{}{}", config.endpoint, "/v1/traces"),
};

https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/src/metric.rs#L235-L245

@djc
Copy link
Contributor

djc commented Mar 16, 2023

Thanks for reporting, would you be able to submit a PR to improve on this?

@jaymell
Copy link
Contributor

jaymell commented Jan 23, 2024

I believe this issue was fixed by #1210? As a result, #1056 can probably be closed as well.

I just went on a deep dive looking to see whether this had been addressed in later versions of the crate 😅. Since it has, it might be good to marked it as fixed.

@jaymell
Copy link
Contributor

jaymell commented Feb 16, 2024

Actually to be clear, while this was fixed, we've actually found it to have a significant bug 😭:

    format!("{provided_or_default_endpoint}{signal_endpoint_path}")
        .parse()
        .map_err(From::from)

/v1/traces is just added directly to provided_or_default_endpoint, which, if it originated from a Url or Uri, is going to have a trailing slash on it, resulting in something like http://example.com//v1/traces (notice the double slash on the path), which in most cases will be a 404.

One simple approach here is to strip off the path from provided_or_default_endpoint and re-build the Uri with signal_endpoint_path as the path instead. This would break anybody who supplies a path with the endpoint, but I think that wouldn't comply with spec anyway.

hdost pushed a commit that referenced this issue Feb 18, 2024
Make endpoint Uri construction less fragile by stripping out duplicate slashes.

Fixes #997

The functionality to append the signal path to a user-supplied tracing endpoint is already in place. However, it does so in a way that is likely to break for any user who's passing the string value of a Uri or Url, which will have a trailing slash appended to them. This attempts to fix that issue.

There were other possible changes discussed but ever implemented/merged in #1056. This PR attempts to keep it simple by just changing existing behavior to not break in a common use case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants