diff --git a/Cargo.toml b/Cargo.toml index 3e72aa0..64d03e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,18 +21,18 @@ actix-http = { version = "3.0", default-features = false, features = ["compress- actix-web = { version = "4.0", default-features = false, features = ["compress-zstd"] } awc = { version = "3.0", optional = true, default-features = false, features = ["compress-zstd"] } futures-util = { version = "0.3", default-features = false, features = ["alloc"] } -opentelemetry = { version = "0.22", default-features = false, features = ["trace"] } -opentelemetry-prometheus = { version = "0.15", optional = true } -opentelemetry-semantic-conventions = "0.14" +opentelemetry = { version = "0.23", default-features = false, features = ["trace"] } +opentelemetry-prometheus = { version = "0.16", optional = true } +opentelemetry-semantic-conventions = "0.15" prometheus = { version = "0.13", default-features = false, optional = true } serde = "1.0" [dev-dependencies] actix-web = { version = "4.0", features = ["macros"] } actix-web-opentelemetry = { path = ".", features = ["metrics-prometheus", "sync-middleware", "awc"] } -opentelemetry_sdk = { version = "0.22", features = ["metrics", "rt-tokio-current-thread"] } -opentelemetry-jaeger = { version = "0.21", features = ["rt-tokio-current-thread"] } -opentelemetry-stdout = { version = "0.3", features = ["trace", "metrics"] } +opentelemetry_sdk = { version = "0.23", features = ["metrics", "rt-tokio-current-thread"] } +opentelemetry-otlp = "0.16" +opentelemetry-stdout = { version = "0.4", features = ["trace", "metrics"] } [package.metadata.docs.rs] all-features = true diff --git a/examples/client.rs b/examples/client.rs index 647e4ec..99636d4 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,8 +1,11 @@ use actix_web_opentelemetry::ClientExt; -use opentelemetry::global; +use opentelemetry::{global, KeyValue}; use opentelemetry_sdk::propagation::TraceContextPropagator; use std::error::Error; use std::io; +use opentelemetry_otlp::TonicExporterBuilder; +use opentelemetry_sdk::{Resource, trace}; +use opentelemetry_sdk::runtime::TokioCurrentThread; async fn execute_request(client: awc::Client) -> io::Result { let mut response = client @@ -24,11 +27,23 @@ async fn execute_request(client: awc::Client) -> io::Result { #[actix_web::main] async fn main() -> Result<(), Box> { - // Start a new jaeger trace pipeline + // Start a new OTLP trace pipeline global::set_text_map_propagator(TraceContextPropagator::new()); - let _tracer = opentelemetry_jaeger::new_agent_pipeline() - .with_service_name("actix_client") - .install_simple()?; + + let service_name_resource = Resource::new(vec![KeyValue::new( + "service.name", + "actix_client" + )]); + + let _tracer = opentelemetry_otlp::new_pipeline() + .tracing() + .with_exporter(TonicExporterBuilder::default()) + .with_trace_config( + trace::Config::default() + .with_resource(service_name_resource) + ) + .install_batch(TokioCurrentThread) + .expect("pipeline install error"); let client = awc::Client::new(); let response = execute_request(client).await?; diff --git a/examples/server.rs b/examples/server.rs index c435832..58cbe4f 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -1,12 +1,8 @@ use actix_web::{web, App, HttpRequest, HttpServer}; use actix_web_opentelemetry::{PrometheusMetricsHandler, RequestMetrics, RequestTracing}; use opentelemetry::{global, KeyValue}; -use opentelemetry_sdk::{ - metrics::{Aggregation, Instrument, SdkMeterProvider, Stream}, - propagation::TraceContextPropagator, - runtime::TokioCurrentThread, - Resource, -}; +use opentelemetry_otlp::{TonicExporterBuilder, WithExportConfig}; +use opentelemetry_sdk::{metrics::{Aggregation, Instrument, SdkMeterProvider, Stream}, propagation::TraceContextPropagator, runtime::TokioCurrentThread, Resource, trace}; async fn index(_req: HttpRequest, _path: actix_web::web::Path) -> &'static str { "Hello world!" @@ -14,10 +10,21 @@ async fn index(_req: HttpRequest, _path: actix_web::web::Path) -> &'stat #[actix_web::main] async fn main() -> Result<(), Box> { - // Start a new jaeger trace pipeline + // Start a new OTLP trace pipeline global::set_text_map_propagator(TraceContextPropagator::new()); - let _tracer = opentelemetry_jaeger::new_agent_pipeline() - .with_service_name("actix_server") + + let service_name_resource = Resource::new(vec![KeyValue::new( + "service.name", + "actix_server" + )]); + + let _tracer = opentelemetry_otlp::new_pipeline() + .tracing() + .with_exporter(TonicExporterBuilder::default().with_endpoint("http://127.0.0.1:6565")) + .with_trace_config( + trace::Config::default() + .with_resource(service_name_resource) + ) .install_batch(TokioCurrentThread) .expect("pipeline install error"); diff --git a/src/client.rs b/src/client.rs index 5e2a98c..4e0b710 100644 --- a/src/client.rs +++ b/src/client.rs @@ -165,12 +165,11 @@ impl InstrumentedClientRequest { F: FnOnce(ClientRequest) -> R, R: Future, { - let tracer = global::tracer_provider().versioned_tracer( - "actix-web-opentelemetry", - Some(env!("CARGO_PKG_VERSION")), - Some(opentelemetry_semantic_conventions::SCHEMA_URL), - None, - ); + let tracer = global::tracer_provider().tracer_builder("actix-web-opentelemetry") + .with_version(env!("CARGO_PKG_VERSION")) + .with_schema_url(opentelemetry_semantic_conventions::SCHEMA_URL) + .build(); + // Client attributes // https://github.com/open-telemetry/semantic-conventions/blob/v1.21.0/docs/http/http-spans.md#http-client self.attrs.extend( diff --git a/src/middleware/trace.rs b/src/middleware/trace.rs index 8ef9af4..87824af 100644 --- a/src/middleware/trace.rs +++ b/src/middleware/trace.rs @@ -121,12 +121,10 @@ where fn new_transform(&self, service: S) -> Self::Future { ok(RequestTracingMiddleware::new( - global::tracer_provider().versioned_tracer( - "actix-web-opentelemetry", - Some(env!("CARGO_PKG_VERSION")), - Some(opentelemetry_semantic_conventions::SCHEMA_URL), - None, - ), + global::tracer_provider().tracer_builder("actix-web-opentelemetry") + .with_version(env!("CARGO_PKG_VERSION")) + .with_schema_url(opentelemetry_semantic_conventions::SCHEMA_URL) + .build(), service, self.route_formatter.clone(), )) diff --git a/src/util.rs b/src/util.rs index 61570a8..1c03bcf 100644 --- a/src/util.rs +++ b/src/util.rs @@ -5,7 +5,7 @@ use actix_web::{ }; use opentelemetry::{KeyValue, Value}; use opentelemetry_semantic_conventions::trace::{ - CLIENT_ADDRESS, CLIENT_SOCKET_ADDRESS, HTTP_REQUEST_BODY_SIZE, HTTP_REQUEST_METHOD, HTTP_ROUTE, + CLIENT_ADDRESS, NETWORK_PEER_ADDRESS, HTTP_REQUEST_BODY_SIZE, HTTP_REQUEST_METHOD, HTTP_ROUTE, NETWORK_PROTOCOL_VERSION, SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_QUERY, URL_SCHEME, USER_AGENT_ORIGINAL, }; @@ -85,7 +85,7 @@ pub(super) fn trace_attributes_from_request( if let Some(peer_addr) = req.peer_addr().map(|socket| socket.ip().to_string()) { if Some(peer_addr.as_str()) != remote_addr { // Client is going through a proxy - attributes.push(KeyValue::new(CLIENT_SOCKET_ADDRESS, peer_addr)); + attributes.push(KeyValue::new(NETWORK_PEER_ADDRESS, peer_addr)); } } let mut host_parts = conn_info.host().split_terminator(':');