Skip to content

Commit

Permalink
Bump the otel group across 1 directory with 5 updates (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Jul 2, 2024
1 parent 757be0d commit 732afff
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Updated

- Bumped opentelemetry version to 0.23

---

## [0.9.4] - 2024-05-20
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ required-features = ["json-logger"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
opentelemetry = {version = "0.22", optional = true}
opentelemetry-otlp = {version = "0.15", features = ["http-proto", "reqwest-client"], default-features = false, optional = true}
opentelemetry_sdk = {version = "0.22", features = ["rt-tokio"], optional = true}
opentelemetry = {version = "0.23", optional = true}
opentelemetry-otlp = {version = "0.16", features = ["http-proto", "reqwest-client"], default-features = false, optional = true}
opentelemetry_sdk = {version = "0.23", features = ["rt-tokio"], optional = true}
tracing = {version = "0.1", features = ["max_level_debug", "release_max_level_info"]}
tracing-log = {version = "0.2"}
tracing-opentelemetry = {version = "0.23", optional = true}
tracing-opentelemetry = {version = "0.24", optional = true}
tracing-subscriber = {version = "0.3", features = ["env-filter"]}

# serialization/deserialization
Expand All @@ -56,7 +56,7 @@ url = "2.5.0"

[dev-dependencies]
actix-web = "4.0.1"
opentelemetry-jaeger = {version = "0.21", features = ["integration_test"]}
opentelemetry-jaeger = {version = "0.22", features = ["integration_test"]}
prima_bridge = "0.16"
tokio = {version = "1.17", features = ["rt", "macros", "rt-multi-thread"]}
tracing-actix-web = {version = "0.7.0", features = ["opentelemetry_0_21"]}
56 changes: 43 additions & 13 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ use opentelemetry_sdk::{

use crate::SubscriberConfig;

fn normalize_collector_url(collector_url: &str) -> String {
// OTLP before version 0.15 didn't append a /v1/traces suffix, but started doing so there.
// For backwards compatibility we strip it from configurations that do have it.
let collector_url = collector_url
// In case of a trailing slash strip it
.strip_suffix('/')
.unwrap_or(collector_url)
.strip_suffix("/v1/traces")
.unwrap_or(collector_url);

// Backport https://github.com/open-telemetry/opentelemetry-rust/pull/1553
let collector_url = collector_url.strip_suffix('/').unwrap_or(collector_url);

// And now starting from version 0.23 opentelemetry randomly stopped appending
// the url suffix, so we need to do it ourselves.
// This was not announced in the changelogs 🙃
collector_url.to_string() + "/v1/traces"
}

pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
let telemetry = config
.telemetry
Expand All @@ -24,22 +43,11 @@ pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
}
};

let collector_url = telemetry.collector_url.as_str();
// OTLP before version 0.15 didn't append a /v1/traces suffix, but started doing so there.
// For backwards compatibility we strip it from configurations that do have it
let collector_url = collector_url
// In case of a trailing slash strip it
.strip_suffix('/')
.unwrap_or(collector_url)
.strip_suffix("/v1/traces")
.unwrap_or(collector_url);

// Backport https://github.com/open-telemetry/opentelemetry-rust/pull/1553
let collector_url = collector_url.strip_suffix('/').unwrap_or(collector_url);
let collector_url = normalize_collector_url(&telemetry.collector_url);

let otlp_exporter = opentelemetry_otlp::new_exporter()
.http()
.with_endpoint(collector_url.to_string());
.with_endpoint(collector_url);

let resource = Resource::new(vec![
KeyValue::new("environment", config.env.to_string()),
Expand All @@ -54,3 +62,25 @@ pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
.install_batch(runtime)
.expect("Failed to configure the OpenTelemetry tracer")
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn normalize_collector_url_test() {
let base = "http://localhost:8080";
let expected = "http://localhost:8080/v1/traces";

assert_eq!(normalize_collector_url(base), expected);

let with_trailing_slash = format!("{}/", base);
assert_eq!(
normalize_collector_url(with_trailing_slash.as_str()),
expected
);

let complete = format!("{}/v1/traces", base);
assert_eq!(normalize_collector_url(complete.as_str()), expected);
}
}

0 comments on commit 732afff

Please sign in to comment.