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

Bump the otel group with 4 updates #124

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
rust = "1.76"
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.26", optional = true}
opentelemetry-otlp = {version = "0.26", features = ["http-proto", "reqwest-client"], default-features = false, optional = true}
opentelemetry_sdk = {version = "0.26", features = ["rt-tokio"], optional = true}
opentelemetry = {version = "0.27", optional = true}
opentelemetry-otlp = {version = "0.27", features = ["http-proto", "reqwest-client"], default-features = false, optional = true}
opentelemetry_sdk = {version = "0.27", 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.27", optional = true}
tracing-opentelemetry = {version = "0.28", optional = true}
tracing-subscriber = {version = "0.3", features = ["env-filter"]}

# serialization/deserialization
Expand All @@ -60,5 +60,5 @@ actix-web = "4.0.1"
opentelemetry-jaeger = {version = "0.22", features = ["integration_test"]}
prima_bridge = "0.18"
tokio = {version = "1.17", features = ["rt", "macros", "rt-multi-thread"]}
tracing-actix-web = {version = "0.7.11", features = ["opentelemetry_0_23"]}
tracing-actix-web = {version = "0.7.11", features = ["opentelemetry_0_27"]}
uuid = {version = "1.10", features = ["v4"]}
42 changes: 19 additions & 23 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use once_cell::sync::Lazy;
use opentelemetry::global;
use opentelemetry::trace::TracerProvider;
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{
trace::{self, Tracer},
Resource,
};
use opentelemetry::{global, trace::TracerProvider, InstrumentationScope, KeyValue};
use opentelemetry_otlp::{SpanExporter, WithExportConfig};
use opentelemetry_sdk::{trace as sdktrace, Resource};
use std::mem;
use std::sync::Mutex;

Expand All @@ -31,7 +26,7 @@ fn normalize_collector_url(collector_url: &str) -> String {
collector_url.to_string() + "/v1/traces"
}

pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
pub fn configure<T>(config: &SubscriberConfig<T>) -> sdktrace::Tracer {
let telemetry = config
.telemetry
.as_ref()
Expand All @@ -50,35 +45,36 @@ pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {

let collector_url = normalize_collector_url(&telemetry.collector_url);

let otlp_exporter = opentelemetry_otlp::new_exporter()
.http()
.with_endpoint(collector_url);
let otlp_exporter = SpanExporter::builder()
.with_http()
.with_endpoint(collector_url)
.build()
.expect("Failed to configure the OpenTelemetry OTLP span exporter");

let resource = Resource::new(vec![
KeyValue::new("environment", config.env.to_string()),
KeyValue::new("country", config.country.to_string()),
KeyValue::new("service.name", telemetry.service_name.clone()),
]);

let tracer_provider = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(otlp_exporter)
.with_trace_config(trace::Config::default().with_resource(resource))
.install_batch(runtime)
.expect("Failed to configure the OpenTelemetry tracer provider");
let tracer_provider = sdktrace::TracerProvider::builder()
.with_batch_exporter(otlp_exporter, runtime)
.with_resource(resource)
.build();

set_tracer_provider(tracer_provider.clone());

tracer_provider
.tracer_builder("prima-tracing")
let scope = InstrumentationScope::builder("prima-tracing")
.with_version(env!("CARGO_PKG_VERSION"))
.build()
.build();

tracer_provider.tracer_with_scope(scope)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a scope? I think that a scope is supposed to start at an entrypoint(eg. Http call). I think this will create a global scope, encompassing everything that happens to the application

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this is how they ported it in their PR 🤷‍♂️

We may not need to do it at all, but I think this was a "problem" before too

}

// Consider to remove this wrapper when https://github.com/open-telemetry/opentelemetry-rust/issues/1961 is resolved
static TRACER_PROVIDER: Lazy<Mutex<Option<trace::TracerProvider>>> = Lazy::new(Default::default);
static TRACER_PROVIDER: Lazy<Mutex<Option<sdktrace::TracerProvider>>> = Lazy::new(Default::default);

fn set_tracer_provider(new_provider: trace::TracerProvider) {
fn set_tracer_provider(new_provider: sdktrace::TracerProvider) {
global::set_tracer_provider(new_provider.clone());

let mut tracer_provider = TRACER_PROVIDER
Expand Down
Loading