diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index e84973d95d..b532ec3813 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -70,3 +70,11 @@ nym-client-websocket-requests = { path = "websocket-requests" } nym-id = { path = "../../common/nym-id" } [dev-dependencies] + +[features] +default = [] +otel = [ + "nym-client-core/otel", + "nym-bin-common/otel", + "nym-gateway-requests/otel", +] \ No newline at end of file diff --git a/clients/native/src/websocket/handler.rs b/clients/native/src/websocket/handler.rs index c0ba1343b1..3e0091670a 100644 --- a/clients/native/src/websocket/handler.rs +++ b/clients/native/src/websocket/handler.rs @@ -184,7 +184,14 @@ impl Handler { }); // the ack control is now responsible for chunking, etc. - let input_msg = InputMessage::new_regular(recipient, message, lane, self.packet_type, None); + let input_msg = InputMessage::new_regular( + recipient, + message, + lane, + self.packet_type, + #[cfg(feature = "otel")] + None, + ); if let Err(err) = self.msg_input.send(input_msg).await { if !self.shutdown_token.is_cancelled() { error!("Failed to send message to the input buffer: {err}"); @@ -222,6 +229,7 @@ impl Handler { reply_surbs, lane, self.packet_type, + #[cfg(feature = "otel")] None, ); if let Err(err) = self.msg_input.send(input_msg).await { diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index d4af6c8c6d..f9cc3f5e41 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -53,3 +53,7 @@ nym-validator-client = { path = "../../common/client-libs/validator-client", fea [features] default = [] eth = [] +otel = [ + "nym-socks5-client-core/otel", + "nym-bin-common/otel", +] \ No newline at end of file diff --git a/common/client-core/src/client/base_client/mod.rs b/common/client-core/src/client/base_client/mod.rs index 51610cf9fe..f95b1e2937 100644 --- a/common/client-core/src/client/base_client/mod.rs +++ b/common/client-core/src/client/base_client/mod.rs @@ -386,6 +386,7 @@ where } #[allow(clippy::too_many_arguments)] + #[instrument(skip_all)] fn start_real_traffic_controller( controller_config: real_messages_control::Config, key_rotation_config: KeyRotationConfig, diff --git a/common/client-core/src/client/inbound_messages.rs b/common/client-core/src/client/inbound_messages.rs index 64fb828456..c79a321dbd 100644 --- a/common/client-core/src/client/inbound_messages.rs +++ b/common/client-core/src/client/inbound_messages.rs @@ -29,7 +29,7 @@ pub enum InputMessage { data: Vec, lane: TransmissionLane, max_retransmissions: Option, - // add trace_id for optional tracing of individual messages in debug mode + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, }, @@ -47,6 +47,7 @@ pub enum InputMessage { reply_surbs: u32, lane: TransmissionLane, max_retransmissions: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, }, @@ -93,6 +94,7 @@ impl InputMessage { data: Vec, lane: TransmissionLane, packet_type: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Self { let message = InputMessage::Regular { @@ -100,6 +102,7 @@ impl InputMessage { data, lane, max_retransmissions: None, + #[cfg(feature = "otel")] trace_id, }; if let Some(packet_type) = packet_type { @@ -115,6 +118,7 @@ impl InputMessage { reply_surbs: u32, lane: TransmissionLane, packet_type: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Self { let message = InputMessage::Anonymous { @@ -123,6 +127,7 @@ impl InputMessage { reply_surbs, lane, max_retransmissions: None, + #[cfg(feature = "otel")] trace_id, }; if let Some(packet_type) = packet_type { @@ -193,6 +198,7 @@ impl InputMessage { self } + #[cfg(feature = "otel")] pub fn trace_id(&self) -> Option<[u8; 12]> { match self { InputMessage::Regular { trace_id, .. } => *trace_id, diff --git a/common/client-core/src/client/real_messages_control/acknowledgement_control/input_message_listener.rs b/common/client-core/src/client/real_messages_control/acknowledgement_control/input_message_listener.rs index f0833ebb5c..6e7e5d6e8e 100644 --- a/common/client-core/src/client/real_messages_control/acknowledgement_control/input_message_listener.rs +++ b/common/client-core/src/client/real_messages_control/acknowledgement_control/input_message_listener.rs @@ -78,6 +78,7 @@ where lane: TransmissionLane, packet_type: PacketType, max_retransmissions: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) { if let Err(err) = self @@ -88,6 +89,7 @@ where lane, packet_type, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await @@ -105,6 +107,7 @@ where lane: TransmissionLane, packet_type: PacketType, max_retransmissions: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) { if let Err(err) = self @@ -116,6 +119,7 @@ where lane, packet_type, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await @@ -127,9 +131,11 @@ where #[allow(clippy::panic)] #[instrument(skip_all)] async fn on_input_message(&mut self, msg: InputMessage) { + #[cfg(feature = "otel")] let trace_id = msg.trace_id(); + #[cfg(feature = "otel")] if let Some(tid) = trace_id { - tracing::warn!("Processing input message with trace_id: {:?}", tid); + tracing::info!("Processing input message with trace_id: {:?}", tid); } match msg { @@ -140,7 +146,8 @@ where max_retransmissions, .. } => { - warn!( + #[cfg(feature = "otel")] + info!( "Handling regular input message with trace_id: {:?}", trace_id ); @@ -150,6 +157,7 @@ where lane, PacketType::Mix, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await @@ -162,7 +170,8 @@ where max_retransmissions, .. } => { - warn!( + #[cfg(feature = "otel")] + tracing::info!( "Handling anonymous input message with trace_id: {:?}", trace_id ); @@ -173,6 +182,7 @@ where lane, PacketType::Mix, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await @@ -183,7 +193,8 @@ where lane, max_retransmissions, } => { - warn!("Handling reply input message with trace_id: {:?}", trace_id); + #[cfg(feature = "otel")] + info!("Handling reply input message with trace_id: {:?}", trace_id); self.handle_reply(recipient_tag, data, lane, max_retransmissions) .await; } @@ -199,7 +210,8 @@ where max_retransmissions, .. } => { - tracing::warn!( + #[cfg(feature = "otel")] + tracing::info!( "Handling regular input message with trace_id: {:?}", trace_id ); @@ -209,6 +221,7 @@ where lane, packet_type, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await @@ -228,6 +241,7 @@ where lane, packet_type, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await diff --git a/common/client-core/src/client/real_messages_control/acknowledgement_control/retransmission_request_listener.rs b/common/client-core/src/client/real_messages_control/acknowledgement_control/retransmission_request_listener.rs index 71a550e42c..c664b8e62f 100644 --- a/common/client-core/src/client/real_messages_control/acknowledgement_control/retransmission_request_listener.rs +++ b/common/client-core/src/client/real_messages_control/acknowledgement_control/retransmission_request_listener.rs @@ -60,7 +60,13 @@ where // TODO: Figure out retransmission packet type signaling self.message_handler - .try_prepare_single_chunk_for_sending(packet_recipient, chunk_data, packet_type, None) + .try_prepare_single_chunk_for_sending( + packet_recipient, + chunk_data, + packet_type, + #[cfg(feature = "otel")] + None + ) .await } diff --git a/common/client-core/src/client/real_messages_control/message_handler.rs b/common/client-core/src/client/real_messages_control/message_handler.rs index 992d68e3c3..bb87a5ae03 100644 --- a/common/client-core/src/client/real_messages_control/message_handler.rs +++ b/common/client-core/src/client/real_messages_control/message_handler.rs @@ -484,6 +484,7 @@ where lane: TransmissionLane, packet_type: PacketType, max_retransmissions: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Result<(), PreparationError> { let message = NymMessage::new_plain(message); @@ -493,6 +494,7 @@ where lane, packet_type, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await @@ -506,6 +508,7 @@ where lane: TransmissionLane, packet_type: PacketType, max_retransmissions: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Result<(), PreparationError> { debug!("Sending non-reply message with packet type {packet_type}"); @@ -539,6 +542,7 @@ where &self.config.ack_key, &recipient, packet_type, + #[cfg(feature = "otel")] trace_id, )?; @@ -591,6 +595,7 @@ where TransmissionLane::AdditionalReplySurbs, packet_type, max_retransmissions, + #[cfg(feature = "otel")] None, ) .await?; @@ -609,6 +614,7 @@ where lane: TransmissionLane, packet_type: PacketType, max_retransmissions: Option, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Result<(), SurbWrappedPreparationError> { debug!("Sending message with reply SURBs with packet type {packet_type}"); @@ -633,6 +639,7 @@ where lane, packet_type, max_retransmissions, + #[cfg(feature = "otel")] trace_id, ) .await?; @@ -648,6 +655,7 @@ where recipient: Recipient, chunk: Fragment, packet_type: PacketType, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Result { debug!("Sending single chunk with packet type {packet_type}"); @@ -660,6 +668,7 @@ where &self.config.ack_key, &recipient, packet_type, + #[cfg(feature = "otel")] trace_id, )?; diff --git a/common/client-core/src/client/statistics_control.rs b/common/client-core/src/client/statistics_control.rs index 5ff60816f6..7f0d201551 100644 --- a/common/client-core/src/client/statistics_control.rs +++ b/common/client-core/src/client/statistics_control.rs @@ -80,6 +80,7 @@ impl StatisticsControl { stats_report.into(), TransmissionLane::General, None, + #[cfg(feature = "otel")] None, ); if let Err(err) = self.report_tx.send(report_message).await { diff --git a/common/client-libs/mixnet-client/src/client.rs b/common/client-libs/mixnet-client/src/client.rs index 5f001810bd..5611ed497c 100644 --- a/common/client-libs/mixnet-client/src/client.rs +++ b/common/client-libs/mixnet-client/src/client.rs @@ -267,6 +267,7 @@ impl Client { } impl SendWithoutResponse for Client { + #[instrument(skip(self, packet))] fn send_without_response(&self, packet: MixPacket) -> io::Result<()> { let address = packet.next_hop_address(); trace!("Sending packet to {address}"); diff --git a/common/gateway-requests/src/types/text_request/mod.rs b/common/gateway-requests/src/types/text_request/mod.rs index 282c4697cc..8044f422d3 100644 --- a/common/gateway-requests/src/types/text_request/mod.rs +++ b/common/gateway-requests/src/types/text_request/mod.rs @@ -153,7 +153,7 @@ impl ClientControlRequest { }) } - #[instrument] + #[instrument(skip_all)] pub fn new_authenticate_v2( shared_key: &SharedGatewayKey, identity_keys: &ed25519::KeyPair, @@ -164,8 +164,6 @@ impl ClientControlRequest { #[cfg(feature = "otel")] let context_carrier = { use nym_bin_common::opentelemetry::context::extract_trace_id_from_tracing_cx; - let trace_id = extract_trace_id_from_tracing_cx(); - use tracing_opentelemetry::OpenTelemetrySpanExt; let current_span = tracing::Span::current(); diff --git a/common/node-tester-utils/Cargo.toml b/common/node-tester-utils/Cargo.toml index 89e4043ad3..af47b169a7 100644 --- a/common/node-tester-utils/Cargo.toml +++ b/common/node-tester-utils/Cargo.toml @@ -30,3 +30,7 @@ workspace = true ## wasm-only dependencies [target."cfg(target_arch = \"wasm32\")".dependencies.wasm-utils] path = "../wasm/utils" + +[ features ] +default = [] +otel = ["nym-sphinx/otel"] \ No newline at end of file diff --git a/common/node-tester-utils/src/tester.rs b/common/node-tester-utils/src/tester.rs index 553130bfa3..ce8b6eb075 100644 --- a/common/node-tester-utils/src/tester.rs +++ b/common/node-tester-utils/src/tester.rs @@ -231,6 +231,7 @@ where &address, &address, PacketType::Mix, + #[cfg(feature = "otel")] None, )?) } diff --git a/common/nym-connection-monitor/src/icmp_beacon.rs b/common/nym-connection-monitor/src/icmp_beacon.rs index f98a1d6a47..07dd8df059 100644 --- a/common/nym-connection-monitor/src/icmp_beacon.rs +++ b/common/nym-connection-monitor/src/icmp_beacon.rs @@ -182,7 +182,6 @@ fn wrap_in_mixnet_message(recipient: Recipient, bundled_packets: Bytes) -> Resul surbs, TransmissionLane::General, None, - None, ) .with_max_retransmissions(0); Ok(mixnet_message) diff --git a/common/nym-connection-monitor/src/mixnet_beacon.rs b/common/nym-connection-monitor/src/mixnet_beacon.rs index 3e5e7f7726..021519ef17 100644 --- a/common/nym-connection-monitor/src/mixnet_beacon.rs +++ b/common/nym-connection-monitor/src/mixnet_beacon.rs @@ -85,7 +85,6 @@ pub fn create_self_ping(our_address: Recipient) -> (InputMessage, u64) { request.to_bytes().unwrap(), TransmissionLane::General, None, - None, ), request_id, ) diff --git a/common/nymsphinx/Cargo.toml b/common/nymsphinx/Cargo.toml index b37c5c613c..a8bbb706b5 100644 --- a/common/nymsphinx/Cargo.toml +++ b/common/nymsphinx/Cargo.toml @@ -60,4 +60,8 @@ outfox = [ otel = [ "nym-bin-common/otel", + "nym-sphinx-acknowledgements/otel", + "nym-sphinx-addressing/otel", + "nym-sphinx-cover/otel", + "nym-sphinx-anonymous-replies/otel", ] \ No newline at end of file diff --git a/common/nymsphinx/acknowledgements/Cargo.toml b/common/nymsphinx/acknowledgements/Cargo.toml index 117bc6b7d5..051bccc70e 100644 --- a/common/nymsphinx/acknowledgements/Cargo.toml +++ b/common/nymsphinx/acknowledgements/Cargo.toml @@ -24,3 +24,4 @@ nym-topology = { path = "../../topology" } [features] serde = ["dep:serde", "generic-array"] +otel = ["nym-sphinx-addressing/otel"] diff --git a/common/nymsphinx/acknowledgements/src/surb_ack.rs b/common/nymsphinx/acknowledgements/src/surb_ack.rs index 214830cc41..780fb8a283 100644 --- a/common/nymsphinx/acknowledgements/src/surb_ack.rs +++ b/common/nymsphinx/acknowledgements/src/surb_ack.rs @@ -61,6 +61,9 @@ impl SurbAck { }; let delays = nym_sphinx_routing::generate_hop_delays(average_delay, route.len()); + #[cfg(not(feature = "otel"))] + let destination = recipient.as_sphinx_destination(); + #[cfg(feature = "otel")] let destination = recipient.as_sphinx_destination(None); let surb_ack_payload = prepare_identifier(rng, ack_key, marshaled_fragment_id); diff --git a/common/nymsphinx/addressing/src/clients.rs b/common/nymsphinx/addressing/src/clients.rs index ee6a6dc9fd..5c843baa86 100644 --- a/common/nymsphinx/addressing/src/clients.rs +++ b/common/nymsphinx/addressing/src/clients.rs @@ -153,7 +153,11 @@ impl Recipient { // TODO: Currently the `DestinationAddress` is equivalent to `ClientIdentity`, but perhaps // it shouldn't be? Maybe it should be (for example) H(`ClientIdentity || ClientEncryptionKey`) // instead? That is an open question. - pub fn as_sphinx_destination(&self, trace_id: Option<[u8; 12]>) -> Destination { + pub fn as_sphinx_destination( + &self, + #[cfg(feature = "otel")] + trace_id: Option<[u8; 12]> + ) -> Destination { #[cfg(feature = "otel")] use nym_bin_common::opentelemetry::compact_id_generator::decompress_trace_id; #[cfg(feature = "otel")] @@ -162,17 +166,15 @@ impl Recipient { } else { decompress_trace_id(&[0u8; 12]) }; - #[cfg(not(feature = "otel"))] - let trace_id_16 = { - _ = trace_id; - [0u8; 16] - }; // since the nym mix network differs slightly in design from loopix, we do not care // about "surb_id" field at all and just use the default value. Destination::new( self.client_identity.derive_destination_address(), - trace_id_16, + #[cfg(not(feature = "otel"))] + [0u8; 16], + #[cfg(feature = "otel")] + trace_id_16 ) } diff --git a/common/nymsphinx/anonymous-replies/Cargo.toml b/common/nymsphinx/anonymous-replies/Cargo.toml index ef9c74b73d..2e1655c9b2 100644 --- a/common/nymsphinx/anonymous-replies/Cargo.toml +++ b/common/nymsphinx/anonymous-replies/Cargo.toml @@ -25,3 +25,7 @@ workspace = true [dev-dependencies] rand_chacha = { workspace = true } + +[ features ] +default = [] +otel = ["nym-sphinx-addressing/otel"] \ No newline at end of file diff --git a/common/nymsphinx/anonymous-replies/src/reply_surb.rs b/common/nymsphinx/anonymous-replies/src/reply_surb.rs index 60d09fd6be..919b0dcc64 100644 --- a/common/nymsphinx/anonymous-replies/src/reply_surb.rs +++ b/common/nymsphinx/anonymous-replies/src/reply_surb.rs @@ -82,7 +82,10 @@ impl ReplySurb { topology.random_route_to_egress(rng, recipient.gateway())? }; let delays = nym_sphinx_routing::generate_hop_delays(average_delay, route.len()); + #[cfg(feature = "otel")] let destination = recipient.as_sphinx_destination(None); + #[cfg(not(feature = "otel"))] + let destination = recipient.as_sphinx_destination(); let mut surb_material = SURBMaterial::new(route, delays, destination); if use_legacy_surb_format && !disable_mix_hops { diff --git a/common/nymsphinx/cover/Cargo.toml b/common/nymsphinx/cover/Cargo.toml index 59710923d1..639fe62e39 100644 --- a/common/nymsphinx/cover/Cargo.toml +++ b/common/nymsphinx/cover/Cargo.toml @@ -20,3 +20,6 @@ nym-sphinx-params = { path = "../params" } nym-sphinx-routing = { path = "../routing" } nym-sphinx-types = { path = "../types" } nym-topology = { path = "../../topology" } + +[features] +otel = ["nym-sphinx-addressing/otel"] \ No newline at end of file diff --git a/common/nymsphinx/cover/src/lib.rs b/common/nymsphinx/cover/src/lib.rs index 4da2bfe1cd..afb3a33089 100644 --- a/common/nymsphinx/cover/src/lib.rs +++ b/common/nymsphinx/cover/src/lib.rs @@ -125,6 +125,9 @@ where let route = topology.random_route_to_egress(rng, full_address.gateway())?; let delays = nym_sphinx_routing::generate_hop_delays(average_packet_delay, route.len()); + #[cfg(not(feature = "otel"))] + let destination = full_address.as_sphinx_destination(); + #[cfg(feature = "otel")] let destination = full_address.as_sphinx_destination(None); let rotation_id = topology.current_key_rotation(); diff --git a/common/nymsphinx/framing/src/processing.rs b/common/nymsphinx/framing/src/processing.rs index 0d82b10c55..a4bc50d05a 100644 --- a/common/nymsphinx/framing/src/processing.rs +++ b/common/nymsphinx/framing/src/processing.rs @@ -161,6 +161,7 @@ impl PartiallyUnwrappedPacket { }) } + #[instrument(skip_all)] pub fn finalise_unwrapping(self) -> Result { let packet_size = self.received_data.packet_size(); let packet_type = self.received_data.packet_type(); @@ -281,10 +282,10 @@ fn wrap_processed_sphinx_packet( opentelemetry::trace::TraceId::from_bytes(full_trace_id_bytes); let context_propagator = ManualContextPropagator::new_from_tid("final_hop", full_trace_id); - info_span!(parent: &context_propagator.root_span, "final_hop_processing", trace_id=%full_trace_id) + tracing::info_span!(parent: &context_propagator.root_span, "final_hop_processing", trace_id=%full_trace_id) } _ => { - debug_span!("final_hop_processing") + tracing::debug_span!("final_hop_processing") } }; #[cfg(feature = "otel")] @@ -343,6 +344,7 @@ fn wrap_processed_outfox_packet( } } +#[instrument(skip_all)] fn perform_final_processing( packet: NymProcessedPacket, packet_size: PacketSize, diff --git a/common/nymsphinx/src/preparer/mod.rs b/common/nymsphinx/src/preparer/mod.rs index ee439dbebd..aad79dbcdf 100644 --- a/common/nymsphinx/src/preparer/mod.rs +++ b/common/nymsphinx/src/preparer/mod.rs @@ -176,6 +176,7 @@ pub trait FragmentPreparer { packet_sender: &Recipient, packet_recipient: &Recipient, packet_type: PacketType, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Result { debug!("Preparing chunk for sending"); @@ -237,11 +238,17 @@ pub trait FragmentPreparer { topology.random_route_to_egress(&mut rng, destination)? }; + #[cfg(feature = "otel")] let destination = packet_recipient.as_sphinx_destination(trace_id); - tracing::warn!( + + #[cfg(feature = "otel")] + tracing::info!( "Packet destination with trace id: {:?}", &destination.identifier ); + + #[cfg(not(feature = "otel"))] + let destination = packet_recipient.as_sphinx_destination(); // including set of delays let delays = @@ -421,6 +428,7 @@ where ack_key: &AckKey, packet_recipient: &Recipient, packet_type: PacketType, + #[cfg(feature = "otel")] trace_id: Option<[u8; 12]>, ) -> Result { let sender = self.sender_address; @@ -433,6 +441,7 @@ where &sender, packet_recipient, packet_type, + #[cfg(feature = "otel")] trace_id, ) } diff --git a/common/socks5-client-core/Cargo.toml b/common/socks5-client-core/Cargo.toml index ce8421f3d7..d0fa080bd0 100644 --- a/common/socks5-client-core/Cargo.toml +++ b/common/socks5-client-core/Cargo.toml @@ -37,3 +37,4 @@ nym-validator-client = { path = "../client-libs/validator-client" } [features] default = [] +otel = ["nym-sphinx/otel"] diff --git a/common/socks5-client-core/src/socks/client.rs b/common/socks5-client-core/src/socks/client.rs index f86e7daa13..2252e0a203 100644 --- a/common/socks5-client-core/src/socks/client.rs +++ b/common/socks5-client-core/src/socks/client.rs @@ -350,6 +350,7 @@ impl SocksClient { self.config.connection_start_surbs, TransmissionLane::ConnectionId(self.connection_id), self.packet_type, + #[cfg(feature = "otel")] None, ); self.input_sender @@ -374,6 +375,7 @@ impl SocksClient { msg.into_bytes(), TransmissionLane::ConnectionId(self.connection_id), self.packet_type, + #[cfg(feature = "otel")] None, ); self.input_sender @@ -441,6 +443,7 @@ impl SocksClient { per_request_surbs, lane, packet_type, + #[cfg(feature = "otel")] None, ) } else { @@ -449,6 +452,7 @@ impl SocksClient { provider_message.into_bytes(), lane, packet_type, + #[cfg(feature = "otel")] None, ) } diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 26492d860d..ddebfaa4bd 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -100,6 +100,7 @@ otel = [ "nym-client-core/otel", "nym-gateway-requests/otel", "nym-sphinx/otel", + "nym-sdk/otel", "opentelemetry", "opentelemetry_sdk", "tracing-opentelemetry", diff --git a/gateway/src/node/client_handling/websocket/connection_handler/authenticated.rs b/gateway/src/node/client_handling/websocket/connection_handler/authenticated.rs index c506827929..4bde8878d0 100644 --- a/gateway/src/node/client_handling/websocket/connection_handler/authenticated.rs +++ b/gateway/src/node/client_handling/websocket/connection_handler/authenticated.rs @@ -344,6 +344,7 @@ impl AuthenticatedHandler { let remaining_bandwidth = self .bandwidth_storage_manager .try_use_bandwidth(required_bandwidth) + .in_current_span() .await?; self.forward_packet(mix_packet); @@ -383,7 +384,7 @@ impl AuthenticatedHandler { // currently only a single type exists BinaryRequest::ForwardSphinx { packet } | BinaryRequest::ForwardSphinxV2 { packet } => { - self.handle_forward_sphinx(packet).await.into_ws_message() + self.handle_forward_sphinx(packet).in_current_span().await.into_ws_message() } _ => RequestHandlingError::UnknownBinaryRequest.into_error_message(), }, diff --git a/gateway/src/node/client_handling/websocket/connection_handler/fresh.rs b/gateway/src/node/client_handling/websocket/connection_handler/fresh.rs index 2e0abb07bc..6cb2fc321c 100644 --- a/gateway/src/node/client_handling/websocket/connection_handler/fresh.rs +++ b/gateway/src/node/client_handling/websocket/connection_handler/fresh.rs @@ -338,6 +338,7 @@ impl FreshHandler { /// /// * `client_address`: address of the client that is going to receive the messages. /// * `shared_keys`: shared keys derived between the client and the gateway used to encrypt and tag the messages. + #[instrument(skip_all)] async fn push_stored_messages_to_client( &mut self, client_address: DestinationAddressBytes, diff --git a/gateway/src/node/client_handling/websocket/connection_handler/mod.rs b/gateway/src/node/client_handling/websocket/connection_handler/mod.rs index 3c567be156..b348eadb46 100644 --- a/gateway/src/node/client_handling/websocket/connection_handler/mod.rs +++ b/gateway/src/node/client_handling/websocket/connection_handler/mod.rs @@ -13,7 +13,6 @@ use std::time::Duration; use time::OffsetDateTime; use tokio::io::{AsyncRead, AsyncWrite}; use tokio_tungstenite::WebSocketStream; -#[cfg(feature = "otel")] use tracing::Instrument; use tracing::{debug, instrument, trace, warn}; @@ -126,7 +125,7 @@ where trace!("managed to perform websocket handshake!"); - if let Some(auth_handle) = handle.handle_until_authenticated_or_failure().await { + if let Some(auth_handle) = handle.handle_until_authenticated_or_failure().in_current_span().await { #[cfg(feature = "otel")] { let from_client_span = { diff --git a/gateway/src/node/internal_service_providers/authenticator/mixnet_listener.rs b/gateway/src/node/internal_service_providers/authenticator/mixnet_listener.rs index 1e7decccfe..25f9181932 100644 --- a/gateway/src/node/internal_service_providers/authenticator/mixnet_listener.rs +++ b/gateway/src/node/internal_service_providers/authenticator/mixnet_listener.rs @@ -977,6 +977,7 @@ fn create_input_message( response_packet, lane, packet_type, + #[cfg(feature = "otel")] None, )) } else { diff --git a/nym-api/Cargo.toml b/nym-api/Cargo.toml index 2188d421b1..fa0ca9ccc5 100644 --- a/nym-api/Cargo.toml +++ b/nym-api/Cargo.toml @@ -110,6 +110,10 @@ nym-ecash-signer-check = { path = "../common/ecash-signer-check" } no-reward = [] v2-performance = [] generate-ts = ["ts-rs"] +otel = [ + "nym-bin-common/otel", + "nym-node-tester-utils/otel", +] [build-dependencies] anyhow = { workspace = true } diff --git a/nym-authenticator-client/src/helpers.rs b/nym-authenticator-client/src/helpers.rs index 700b8870d7..a68bedad13 100644 --- a/nym-authenticator-client/src/helpers.rs +++ b/nym-authenticator-client/src/helpers.rs @@ -15,14 +15,12 @@ pub(crate) fn create_input_message( surbs, TransmissionLane::General, None, - None, ), IncludedSurbs::ExposeSelfAddress => nym_sdk::mixnet::InputMessage::new_regular( recipient, data, TransmissionLane::General, None, - None, ), } } diff --git a/nym-ip-packet-client/src/connect.rs b/nym-ip-packet-client/src/connect.rs index 8f5c56c777..5a37cf6d82 100644 --- a/nym-ip-packet-client/src/connect.rs +++ b/nym-ip-packet-client/src/connect.rs @@ -194,6 +194,5 @@ fn create_input_message( surbs, TransmissionLane::General, None, - None, )) } diff --git a/nym-node/src/node/mixnet/handler.rs b/nym-node/src/node/mixnet/handler.rs index c3f875c545..28e776d6cc 100644 --- a/nym-node/src/node/mixnet/handler.rs +++ b/nym-node/src/node/mixnet/handler.rs @@ -130,6 +130,7 @@ impl ConnectionHandler { Some(now + delay) } + #[instrument(skip_all, level = "debug")] fn handle_forward_packet(&self, now: Instant, mix_packet: MixPacket, delay: Option) { if !self.shared.processing_config.forward_hop_processing_enabled { trace!("this nym-node does not support forward hop packets"); @@ -141,6 +142,7 @@ impl ConnectionHandler { self.shared.forward_mix_packet(mix_packet, forward_instant); } + #[instrument(skip_all, level = "debug")] async fn handle_final_hop(&self, final_hop_data: ProcessedFinalHop) { if !self.shared.processing_config.final_hop_processing_enabled { trace!("this nym-node does not support final hop packets"); @@ -269,6 +271,7 @@ impl ConnectionHandler { } } + #[instrument(skip_all, level = "debug")] async fn handle_received_packet_with_replay_detection( &mut self, now: Instant, @@ -379,6 +382,7 @@ impl ConnectionHandler { true } + #[instrument(skip_all)] async fn handle_pending_packets_batch(&mut self, now: Instant) { let batch = self.pending_packets.reset(now); let replay_tags = self.pending_packets.replay_tags(); diff --git a/nym-node/src/node/mixnet/packet_forwarding/mod.rs b/nym-node/src/node/mixnet/packet_forwarding/mod.rs index 1fb7f6e290..e2a5d13035 100644 --- a/nym-node/src/node/mixnet/packet_forwarding/mod.rs +++ b/nym-node/src/node/mixnet/packet_forwarding/mod.rs @@ -13,7 +13,7 @@ use nym_sphinx_forwarding::packet::MixPacket; use nym_task::ShutdownToken; use std::io; use tokio::time::Instant; -use tracing::{debug, error, instrument, trace, warn}; +use tracing::{debug, error, instrument, Instrument, trace, warn}; pub(crate) mod global; @@ -133,16 +133,16 @@ impl PacketForwarder { loop { tokio::select! { biased; - _ = shutdown_token.cancelled() => { + _ = shutdown_token.cancelled().in_current_span() => { debug!("PacketForwarder: Received shutdown"); break; } - delayed = self.delay_queue.next() => { + delayed = self.delay_queue.next().in_current_span() => { // SAFETY: `stream` implementation of `NonExhaustiveDelayQueue` never returns `None` #[allow(clippy::unwrap_used)] self.handle_done_delaying(delayed.unwrap()); } - new_packet = self.packet_receiver.next() => { + new_packet = self.packet_receiver.next().in_current_span() => { // this one is impossible to ever panic - the struct itself contains a sender // and hence it can't happen that ALL senders are dropped #[allow(clippy::unwrap_used)] diff --git a/nym-node/src/node/mixnet/shared/mod.rs b/nym-node/src/node/mixnet/shared/mod.rs index 787ffb749c..e434b9cf04 100644 --- a/nym-node/src/node/mixnet/shared/mod.rs +++ b/nym-node/src/node/mixnet/shared/mod.rs @@ -186,6 +186,7 @@ impl SharedData { } } + #[instrument(skip_all)] pub(super) fn forward_mix_packet(&self, packet: MixPacket, delay_until: Option) { if self .mixnet_forwarder diff --git a/nym-node/src/node/mod.rs b/nym-node/src/node/mod.rs index 5404c2cd16..33aaa3564f 100644 --- a/nym-node/src/node/mod.rs +++ b/nym-node/src/node/mod.rs @@ -1103,7 +1103,7 @@ impl NymNode { let shutdown_token = self.shutdown_token(); self.shutdown_tracker().try_spawn_named( - async move { packet_forwarder.run(shutdown_token).await }, + async move { packet_forwarder.run(shutdown_token).in_current_span().await }, "PacketForwarder", ); @@ -1242,7 +1242,7 @@ impl NymNode { // ideally we'd also do some cleanup here, but currently there's no easy way to access the handles return Ok(()) } - startup_result = self.start_nym_node_tasks() => { + startup_result = self.start_nym_node_tasks().in_current_span() => { let mut shutdown_manager = startup_result?; shutdown_manager.replace_shutdown_signals(shutdown_signals); shutdown_manager.run_until_shutdown().await; diff --git a/sdk/rust/nym-sdk/Cargo.toml b/sdk/rust/nym-sdk/Cargo.toml index 1b448ca59d..6e668d7de4 100644 --- a/sdk/rust/nym-sdk/Cargo.toml +++ b/sdk/rust/nym-sdk/Cargo.toml @@ -104,6 +104,7 @@ libp2p-vanilla = [] otel = [ "nym-bin-common/otel", "nym-gateway-requests/otel", + "nym-socks5-client-core/otel", "opentelemetry", "opentelemetry_sdk", "opentelemetry-otlp", diff --git a/sdk/rust/nym-sdk/src/mixnet/client.rs b/sdk/rust/nym-sdk/src/mixnet/client.rs index e5cf15129e..34cb6c8722 100644 --- a/sdk/rust/nym-sdk/src/mixnet/client.rs +++ b/sdk/rust/nym-sdk/src/mixnet/client.rs @@ -38,8 +38,7 @@ use std::path::Path; use std::path::PathBuf; #[cfg(unix)] use std::sync::Arc; -use tokio_util::sync::CancellationToken; -use tracing::instrument; +use tracing::{instrument, Instrument}; use url::Url; use zeroize::Zeroizing; @@ -476,6 +475,7 @@ where }) } + #[instrument(skip_all)] fn get_api_endpoints(&self) -> Vec { self.config .network_details @@ -486,6 +486,7 @@ where .collect() } + #[instrument(skip_all)] fn get_nyxd_endpoints(&self) -> Vec { self.config .network_details @@ -496,6 +497,7 @@ where .collect() } + #[instrument(skip_all)] async fn setup_client_keys(&self) -> Result<()> { let mut rng = OsRng; let key_store = self.storage.key_store(); @@ -836,7 +838,7 @@ where if self.socks5_config.is_some() { return Err(Error::Socks5Config { set: true }); } - let (mut started_client, nym_address) = self.connect_to_mixnet_common().await?; + let (mut started_client, nym_address) = self.connect_to_mixnet_common().in_current_span().await?; let client_input = started_client.client_input.register_producer(); let mut client_output = started_client.client_output.register_consumer(); let client_state: nym_client_core::client::base_client::ClientState = diff --git a/sdk/rust/nym-sdk/src/mixnet/sink.rs b/sdk/rust/nym-sdk/src/mixnet/sink.rs index 0c51bbce66..a01359eb14 100644 --- a/sdk/rust/nym-sdk/src/mixnet/sink.rs +++ b/sdk/rust/nym-sdk/src/mixnet/sink.rs @@ -59,6 +59,7 @@ impl MixnetMessageSinkTranslator for DefaultMixnetMessageSinkTranslator { bytes, self.lane, self.packet_type, + #[cfg(feature = "otel")] None, )), IncludedSurbs::Amount(surbs) => Ok(InputMessage::new_anonymous( @@ -67,6 +68,7 @@ impl MixnetMessageSinkTranslator for DefaultMixnetMessageSinkTranslator { *surbs, self.lane, self.packet_type, + #[cfg(feature = "otel")] None, )), }, diff --git a/sdk/rust/nym-sdk/src/mixnet/traits.rs b/sdk/rust/nym-sdk/src/mixnet/traits.rs index 965d90fb58..4a1ab15f0b 100644 --- a/sdk/rust/nym-sdk/src/mixnet/traits.rs +++ b/sdk/rust/nym-sdk/src/mixnet/traits.rs @@ -84,8 +84,6 @@ pub trait MixnetMessageSender { tracing::info!("[DEBUG] Trace id in send_message: {:?}", trace_id); Some(compress_trace_id(&trace_id)) }; - #[cfg(not(feature = "otel"))] - let trace_id = None; let lane = TransmissionLane::General; let input_msg = match surbs { @@ -95,6 +93,7 @@ pub trait MixnetMessageSender { surbs, lane, self.packet_type(), + #[cfg(feature = "otel")] trace_id, ), IncludedSurbs::ExposeSelfAddress => InputMessage::new_regular( @@ -102,6 +101,7 @@ pub trait MixnetMessageSender { message.as_ref().to_vec(), lane, self.packet_type(), + #[cfg(feature = "otel")] trace_id, ), }; diff --git a/service-providers/ip-packet-router/Cargo.toml b/service-providers/ip-packet-router/Cargo.toml index 14cedf7743..765924d5eb 100644 --- a/service-providers/ip-packet-router/Cargo.toml +++ b/service-providers/ip-packet-router/Cargo.toml @@ -50,3 +50,7 @@ tokio-tun.workspace = true [dev-dependencies] async-trait.workspace = true + +[features] +default = [] +otel = ["nym-client-core/otel"] diff --git a/service-providers/ip-packet-router/src/util/create_message.rs b/service-providers/ip-packet-router/src/util/create_message.rs index 178c318b38..2473266a59 100644 --- a/service-providers/ip-packet-router/src/util/create_message.rs +++ b/service-providers/ip-packet-router/src/util/create_message.rs @@ -11,10 +11,22 @@ pub(crate) fn create_input_message( let packet_type = None; match recipient { ConnectedClientId::NymAddress(recipient) => { - InputMessage::new_regular(**recipient, response_packet, lane, packet_type, None) + InputMessage::new_regular( + **recipient, + response_packet, + lane, + packet_type, + #[cfg(feature = "otel")] + None, + ) } ConnectedClientId::AnonymousSenderTag(tag) => { - InputMessage::new_reply(*tag, response_packet, lane, packet_type) + InputMessage::new_reply( + *tag, + response_packet, + lane, + packet_type, + ) } } } diff --git a/service-providers/network-requester/Cargo.toml b/service-providers/network-requester/Cargo.toml index 521d664efe..f2e4ccd72e 100644 --- a/service-providers/network-requester/Cargo.toml +++ b/service-providers/network-requester/Cargo.toml @@ -64,3 +64,12 @@ nym-id = { path = "../../common/nym-id" } [dev-dependencies] tempfile = { workspace = true } + +[features] +default = [] +otel = [ + "nym-client-core/otel", + "nym-sphinx/otel", + "nym-bin-common/otel", + "nym-sdk/otel" +] \ No newline at end of file diff --git a/service-providers/network-requester/src/reply.rs b/service-providers/network-requester/src/reply.rs index 5e60302fc1..f366e757a7 100644 --- a/service-providers/network-requester/src/reply.rs +++ b/service-providers/network-requester/src/reply.rs @@ -192,6 +192,7 @@ impl MixnetAddress { data: message, lane: TransmissionLane::ConnectionId(connection_id), max_retransmissions: None, + #[cfg(feature = "otel")] trace_id: None, }), packet_type,