1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Diagnostics ;
3
4
using System . Net ;
4
5
using System . Net . Sockets ;
5
6
using System . Reflection ;
7
+ using System . Runtime . CompilerServices ;
6
8
using System . Text ;
7
9
using RabbitMQ . Client . Events ;
8
10
using RabbitMQ . Client . Impl ;
@@ -110,6 +112,23 @@ internal static Activity Receive(string routingKey, string exchange, ulong deliv
110
112
return activity ;
111
113
}
112
114
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
+
113
132
internal static Activity Deliver ( BasicDeliverEventArgs deliverEventArgs )
114
133
{
115
134
if ( ! s_subscriberSource . HasListeners ( ) )
@@ -123,17 +142,17 @@ internal static Activity Deliver(BasicDeliverEventArgs deliverEventArgs)
123
142
124
143
ActivityContext . TryParse ( traceparent , traceState , out ActivityContext parentContext ) ;
125
144
126
- string routingKey = UseRoutingKeyAsOperationName ? Encoding . UTF8 . GetString ( deliverEventArgs . RoutingKey . Span ) : null ;
145
+ string routingKey = UseRoutingKeyAsOperationName ? GetString ( deliverEventArgs . RoutingKey . Span ) : null ;
127
146
Activity activity = s_subscriberSource . StartLinkedRabbitMQActivity (
128
147
UseRoutingKeyAsOperationName ? $ "{ routingKey } deliver" : "deliver" ,
129
148
ActivityKind . Consumer , parentContext ) ;
130
149
131
150
if ( activity != null && activity . IsAllDataRequested )
132
151
{
133
- string exchange = Encoding . UTF8 . GetString ( deliverEventArgs . Exchange . Span ) ;
152
+ string exchange = GetString ( deliverEventArgs . Exchange . Span ) ;
134
153
if ( routingKey == null )
135
154
{
136
- routingKey = Encoding . UTF8 . GetString ( deliverEventArgs . RoutingKey . Span ) ;
155
+ routingKey = GetString ( deliverEventArgs . RoutingKey . Span ) ;
137
156
}
138
157
139
158
PopulateMessagingTags ( "deliver" ,
0 commit comments