1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . Diagnostics ;
34using System . Net ;
45using System . Net . Sockets ;
56using System . Reflection ;
7+ using System . Runtime . CompilerServices ;
68using System . Text ;
79using RabbitMQ . Client . Events ;
810using RabbitMQ . Client . Impl ;
@@ -110,6 +112,23 @@ internal static Activity Receive(string routingKey, string exchange, ulong deliv
110112 return activity ;
111113 }
112114
115+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
116+ private static string GetString ( ReadOnlySpan < byte > span )
117+ {
118+ #if NETSTANDARD
119+ unsafe
120+ {
121+ fixed ( byte * bytesPtr = span )
122+ {
123+ return Encoding . UTF8 . GetString ( bytesPtr , span . Length ) ;
124+ }
125+ }
126+ #else
127+ return Encoding . UTF8 . GetString ( span ) ;
128+ #endif
129+ }
130+
131+
113132 internal static Activity Deliver ( BasicDeliverEventArgs deliverEventArgs )
114133 {
115134 if ( ! s_subscriberSource . HasListeners ( ) )
@@ -123,17 +142,17 @@ internal static Activity Deliver(BasicDeliverEventArgs deliverEventArgs)
123142
124143 ActivityContext . TryParse ( traceparent , traceState , out ActivityContext parentContext ) ;
125144
126- string routingKey = UseRoutingKeyAsOperationName ? Encoding . UTF8 . GetString ( deliverEventArgs . RoutingKey . Span ) : null ;
145+ string routingKey = UseRoutingKeyAsOperationName ? GetString ( deliverEventArgs . RoutingKey . Span ) : null ;
127146 Activity activity = s_subscriberSource . StartLinkedRabbitMQActivity (
128147 UseRoutingKeyAsOperationName ? $ "{ routingKey } deliver" : "deliver" ,
129148 ActivityKind . Consumer , parentContext ) ;
130149
131150 if ( activity != null && activity . IsAllDataRequested )
132151 {
133- string exchange = Encoding . UTF8 . GetString ( deliverEventArgs . Exchange . Span ) ;
152+ string exchange = GetString ( deliverEventArgs . Exchange . Span ) ;
134153 if ( routingKey == null )
135154 {
136- routingKey = Encoding . UTF8 . GetString ( deliverEventArgs . RoutingKey . Span ) ;
155+ routingKey = GetString ( deliverEventArgs . RoutingKey . Span ) ;
137156 }
138157
139158 PopulateMessagingTags ( "deliver" ,
0 commit comments