Skip to content

Commit

Permalink
netstandard 2.0 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gábor Zavarkó committed May 11, 2024
1 parent 67a85e7 commit 31433b9
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions projects/RabbitMQ.Client/client/impl/RabbitMQActivitySource.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using RabbitMQ.Client.Events;
using RabbitMQ.Client.Impl;
Expand Down Expand Up @@ -110,6 +112,23 @@ internal static Activity ReceiveEmpty(string queue)
return activity;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string GetString(ReadOnlySpan<byte> span)
{
#if NETSTANDARD
unsafe
{
fixed (byte* bytesPtr = span)
{
return Encoding.UTF8.GetString(bytesPtr, span.Length);
}
}
#else
return Encoding.UTF8.GetString(span);
#endif
}


internal static Activity Deliver(BasicDeliverEventArgs deliverEventArgs)
{
if (!s_subscriberSource.HasListeners())
Expand All @@ -123,17 +142,17 @@ internal static Activity Deliver(BasicDeliverEventArgs deliverEventArgs)

ActivityContext.TryParse(traceparent, traceState, out ActivityContext parentContext);

string routingKey = UseRoutingKeyAsOperationName ? Encoding.UTF8.GetString(deliverEventArgs.RoutingKey.Span) : null;
string routingKey = UseRoutingKeyAsOperationName ? GetString(deliverEventArgs.RoutingKey.Span) : null;
Activity activity = s_subscriberSource.StartLinkedRabbitMQActivity(
UseRoutingKeyAsOperationName ? $"{routingKey} deliver" : "deliver",
ActivityKind.Consumer, parentContext);

if (activity != null && activity.IsAllDataRequested)
{
string exchange = Encoding.UTF8.GetString(deliverEventArgs.Exchange.Span);
string exchange = GetString(deliverEventArgs.Exchange.Span);
if (routingKey == null)
{
routingKey = Encoding.UTF8.GetString(deliverEventArgs.RoutingKey.Span);
routingKey = GetString(deliverEventArgs.RoutingKey.Span);
}

PopulateMessagingTags("deliver",
Expand Down

0 comments on commit 31433b9

Please sign in to comment.