Skip to content

Commit 848ff7f

Browse files
Fixes telemetry via http (#191)
Between opentelemetry-otlp v0.15 and 0.16 a breaking change landed. - https://github.com/pitoniak32/opentelemetry-rust/blob/main/opentelemetry-otlp/CHANGELOG.md#v0160 - open-telemetry/opentelemetry-rust#1706 So when we upgraded to 0.27 (#186), we inadvertantly broke people using `SCOPE_OTEL_PROTOCOL=http`. It did not affect people using `grpc`. To maintain consistency with grpc (and compatibility with version prior to PR #186), we append `v1/traces` to the `SCOPE_OTEL_ENDPOINT` when the protocol is set to `http`.
1 parent b85b30a commit 848ff7f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

scope/src/shared/logging.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use opentelemetry_sdk::{
1414
trace::{RandomIdGenerator, Sampler, TracerProvider},
1515
Resource,
1616
};
17+
use url::Url;
1718

1819
use std::env;
1920
use std::fs::File;
@@ -222,11 +223,21 @@ impl LoggingOpts {
222223
.with_timeout(*timeout)
223224
.with_metadata(metadata_map.clone())
224225
.build(),
225-
OtelProtocol::Http => SpanExporter::builder()
226-
.with_http()
227-
.with_endpoint(endpoint)
228-
.with_timeout(*timeout)
229-
.build(),
226+
OtelProtocol::Http => {
227+
// with_endpoint() is _roughly_ equivalent to using the OTEL_EXPORTER_OTLP_TRACES_ENDPOINT env var
228+
// So we have to append the `v1/traces` to the base URL when using http
229+
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_traces_endpoint
230+
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp
231+
let url = Url::parse(endpoint)
232+
.expect("Expected a valid URI")
233+
.join("v1/traces")
234+
.unwrap();
235+
SpanExporter::builder()
236+
.with_http()
237+
.with_endpoint(url)
238+
.with_timeout(*timeout)
239+
.build()
240+
}
230241
};
231242

232243
let tracer = TracerProvider::builder()

0 commit comments

Comments
 (0)