Skip to content

Commit d34160b

Browse files
stebetlukebakken
authored andcommitted
First implementation of adding ActivitySource to common operations to enable OpenTelemetry scenarios.
Linking existing context for publish if one exists dotnet format Adding standard tags without allocating. Updating code after comments Moving ActivitySource tests to Integration
1 parent 52add14 commit d34160b

17 files changed

+827
-31
lines changed

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.orig
12
*.log
23
_site/
34

@@ -28,6 +29,11 @@ test.sh
2829
test-output.log
2930
InternalTrace*
3031
nunit-agent*
32+
#################
33+
## JetBrains Rider
34+
#################
35+
.idea/
36+
3137
#################
3238
## Visual Studio
3339
#################

Diff for: RabbitMQDotNetClient.sln

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{34486CC0-D61E-46BA-9E5E-6E8EFA7C34B5}"
66
ProjectSection(SolutionItems) = preProject
77
.editorconfig = .editorconfig
8+
.gitignore = .gitignore
89
EndProjectSection
910
EndProject
1011
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitMQ.Client", "projects\RabbitMQ.Client\RabbitMQ.Client.csproj", "{8C554257-5ECC-45DB-873D-560BFBB74EC8}"

Diff for: projects/RabbitMQ.Client/PublicAPI.Unshipped.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ RabbitMQ.Client.IChannel.BasicAcks -> System.EventHandler<RabbitMQ.Client.Events
481481
RabbitMQ.Client.IChannel.BasicGetAsync(string queue, bool autoAck) -> System.Threading.Tasks.ValueTask<RabbitMQ.Client.BasicGetResult>
482482
RabbitMQ.Client.IChannel.BasicNackAsync(ulong deliveryTag, bool multiple, bool requeue) -> System.Threading.Tasks.ValueTask
483483
RabbitMQ.Client.IChannel.BasicNacks -> System.EventHandler<RabbitMQ.Client.Events.BasicNackEventArgs>
484-
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(RabbitMQ.Client.CachedString exchange, RabbitMQ.Client.CachedString routingKey, in TProperties basicProperties, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false) -> System.Threading.Tasks.ValueTask
485-
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(string exchange, string routingKey, in TProperties basicProperties, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false) -> System.Threading.Tasks.ValueTask
484+
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(RabbitMQ.Client.CachedString exchange, RabbitMQ.Client.CachedString routingKey, TProperties basicProperties, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false) -> System.Threading.Tasks.ValueTask
485+
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(string exchange, string routingKey, TProperties basicProperties, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false) -> System.Threading.Tasks.ValueTask
486486
RabbitMQ.Client.IChannel.BasicReturn -> System.EventHandler<RabbitMQ.Client.Events.BasicReturnEventArgs>
487487
RabbitMQ.Client.IChannel.CallbackException -> System.EventHandler<RabbitMQ.Client.Events.CallbackExceptionEventArgs>
488488
RabbitMQ.Client.IChannel.ChannelNumber.get -> int
@@ -658,6 +658,7 @@ RabbitMQ.Client.PublicationAddress
658658
RabbitMQ.Client.PublicationAddress.PublicationAddress(string exchangeType, string exchangeName, string routingKey) -> void
659659
RabbitMQ.Client.QueueDeclareOk
660660
RabbitMQ.Client.QueueDeclareOk.QueueDeclareOk(string queueName, uint messageCount, uint consumerCount) -> void
661+
RabbitMQ.Client.RabbitMQActivitySource
661662
RabbitMQ.Client.ReadOnlyBasicProperties
662663
RabbitMQ.Client.ReadOnlyBasicProperties.AppId.get -> string
663664
RabbitMQ.Client.ReadOnlyBasicProperties.ClusterId.get -> string
@@ -851,6 +852,8 @@ static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync<T>(this RabbitMQ.Cli
851852
static RabbitMQ.Client.PublicationAddress.Parse(string uriLikeString) -> RabbitMQ.Client.PublicationAddress
852853
static RabbitMQ.Client.PublicationAddress.TryParse(string uriLikeString, out RabbitMQ.Client.PublicationAddress result) -> bool
853854
static RabbitMQ.Client.QueueDeclareOk.implicit operator string(RabbitMQ.Client.QueueDeclareOk declareOk) -> string
855+
static RabbitMQ.Client.RabbitMQActivitySource.UseRoutingKeyAsOperationName.get -> bool
856+
static RabbitMQ.Client.RabbitMQActivitySource.UseRoutingKeyAsOperationName.set -> void
854857
static RabbitMQ.Client.TcpClientAdapter.GetMatchingHost(System.Collections.Generic.IReadOnlyCollection<System.Net.IPAddress> addresses, System.Net.Sockets.AddressFamily addressFamily) -> System.Net.IPAddress
855858
static RabbitMQ.Client.TimerBasedCredentialRefresherEventSource.Log.get -> RabbitMQ.Client.TimerBasedCredentialRefresherEventSource
856859
static readonly RabbitMQ.Client.CachedString.Empty -> RabbitMQ.Client.CachedString
@@ -881,6 +884,8 @@ virtual RabbitMQ.Client.TcpClientAdapter.Dispose(bool disposing) -> void
881884
virtual RabbitMQ.Client.TcpClientAdapter.GetStream() -> System.Net.Sockets.NetworkStream
882885
virtual RabbitMQ.Client.TcpClientAdapter.ReceiveTimeout.get -> System.TimeSpan
883886
virtual RabbitMQ.Client.TcpClientAdapter.ReceiveTimeout.set -> void
887+
~const RabbitMQ.Client.RabbitMQActivitySource.PublisherSourceName = "RabbitMQ.Client.Publisher" -> string
888+
~const RabbitMQ.Client.RabbitMQActivitySource.SubscriberSourceName = "RabbitMQ.Client.Subscriber" -> string
884889
~override RabbitMQ.Client.Events.EventingBasicConsumer.HandleBasicDeliverAsync(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory<byte> body) -> System.Threading.Tasks.Task
885890
~RabbitMQ.Client.ConnectionFactory.CreateConnectionAsync(RabbitMQ.Client.IEndpointResolver endpointResolver, string clientProvidedName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<RabbitMQ.Client.IConnection>
886891
~RabbitMQ.Client.ConnectionFactory.CreateConnectionAsync(string clientProvidedName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<RabbitMQ.Client.IConnection>

Diff for: projects/RabbitMQ.Client/RabbitMQ.Client.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,7 @@
8080
<PackageReference Include="System.IO.Pipelines" Version="8.0.0" />
8181
</ItemGroup>
8282

83+
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
84+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
85+
</ItemGroup>
8386
</Project>

Diff for: projects/RabbitMQ.Client/client/api/IChannel.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public interface IChannel : IDisposable
192192
/// Routing key must be shorter than 255 bytes.
193193
/// </para>
194194
/// </remarks>
195-
ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body = default, bool mandatory = false)
195+
ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, TProperties basicProperties, ReadOnlyMemory<byte> body = default, bool mandatory = false)
196196
where TProperties : IReadOnlyBasicProperties, IAmqpHeader;
197197

198198
/// <summary>
@@ -203,7 +203,7 @@ ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, in
203203
/// Routing key must be shorter than 255 bytes.
204204
/// </para>
205205
/// </remarks>
206-
ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body = default, bool mandatory = false)
206+
ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, TProperties basicProperties, ReadOnlyMemory<byte> body = default, bool mandatory = false)
207207
where TProperties : IReadOnlyBasicProperties, IAmqpHeader;
208208

209209
#nullable disable

Diff for: projects/RabbitMQ.Client/client/api/IChannelExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public static Task<string> BasicConsumeAsync(this IChannel channel, string queue
8989
public static ValueTask BasicPublishAsync<T>(this IChannel channel, PublicationAddress addr, in T basicProperties, ReadOnlyMemory<byte> body)
9090
where T : IReadOnlyBasicProperties, IAmqpHeader
9191
{
92-
return channel.BasicPublishAsync(addr.ExchangeName, addr.RoutingKey, in basicProperties, body);
92+
return channel.BasicPublishAsync(addr.ExchangeName, addr.RoutingKey, basicProperties, body);
9393
}
9494

9595
public static ValueTask BasicPublishAsync(this IChannel channel, string exchange, string routingKey, ReadOnlyMemory<byte> body = default, bool mandatory = false)
96-
=> channel.BasicPublishAsync(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory);
96+
=> channel.BasicPublishAsync(exchange, routingKey, EmptyBasicProperty.Empty, body, mandatory);
9797

9898
public static ValueTask BasicPublishAsync(this IChannel channel, CachedString exchange, CachedString routingKey, ReadOnlyMemory<byte> body = default, bool mandatory = false)
99-
=> channel.BasicPublishAsync(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory);
99+
=> channel.BasicPublishAsync(exchange, routingKey, EmptyBasicProperty.Empty, body, mandatory);
100100

101101
#nullable disable
102102

Diff for: projects/RabbitMQ.Client/client/events/AsyncEventingBasicConsumer.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Threading.Tasks;
34
using RabbitMQ.Client.Impl;
45

@@ -78,8 +79,9 @@ await base.HandleBasicConsumeOk(consumerTag)
7879
public override Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
7980
in ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
8081
{
82+
var deliverEventArgs = new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
8183
// No need to call base, it's empty.
82-
return _receivedWrapper.InvokeAsync(this, new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body));
84+
return BasicDeliverWrapper(deliverEventArgs);
8385
}
8486

8587
///<summary>Fires the Shutdown event.</summary>
@@ -93,5 +95,13 @@ await _shutdownWrapper.InvokeAsync(this, reason)
9395
.ConfigureAwait(false);
9496
}
9597
}
98+
99+
private async Task BasicDeliverWrapper(BasicDeliverEventArgs eventArgs)
100+
{
101+
using (Activity activity = RabbitMQActivitySource.Deliver(eventArgs))
102+
{
103+
await _receivedWrapper.InvokeAsync(this, eventArgs).ConfigureAwait(false);
104+
}
105+
}
96106
}
97107
}

Diff for: projects/RabbitMQ.Client/client/events/EventingBasicConsumer.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33+
using System.Diagnostics;
3334
using System.Threading.Tasks;
3435

3536
namespace RabbitMQ.Client.Events
@@ -88,10 +89,12 @@ public override void HandleBasicConsumeOk(string consumerTag)
8889
public override async Task HandleBasicDeliverAsync(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
8990
ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
9091
{
91-
await base.HandleBasicDeliverAsync(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
92-
Received?.Invoke(
93-
this,
94-
new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body));
92+
BasicDeliverEventArgs eventArgs = new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
93+
using (Activity activity = RabbitMQActivitySource.SubscriberHasListeners ? RabbitMQActivitySource.Deliver(eventArgs) : default)
94+
{
95+
await base.HandleBasicDeliverAsync(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
96+
Received?.Invoke(this, eventArgs);
97+
}
9598
}
9699

97100
///<summary>Fires the Shutdown event.</summary>

Diff for: projects/RabbitMQ.Client/client/impl/AsyncRpcContinuations.cs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout)
7272
_tcsConfiguredTaskAwaitable = _tcs.Task.ConfigureAwait(false);
7373
}
7474

75+
internal DateTime StartTime { get; } = DateTime.UtcNow;
76+
7577
public ConfiguredTaskAwaitable<T>.ConfiguredTaskAwaiter GetAwaiter()
7678
{
7779
return _tcsConfiguredTaskAwaitable.GetAwaiter();

Diff for: projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ public ValueTask<BasicGetResult> BasicGetAsync(string queue, bool autoAck)
290290
public ValueTask BasicNackAsync(ulong deliveryTag, bool multiple, bool requeue)
291291
=> InnerChannel.BasicNackAsync(deliveryTag, multiple, requeue);
292292

293-
public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
293+
public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
294294
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
295-
=> InnerChannel.BasicPublishAsync(exchange, routingKey, in basicProperties, body, mandatory);
295+
=> InnerChannel.BasicPublishAsync(exchange, routingKey, basicProperties, body, mandatory);
296296

297-
public ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
297+
public ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
298298
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
299-
=> InnerChannel.BasicPublishAsync(exchange, routingKey, in basicProperties, body, mandatory);
299+
=> InnerChannel.BasicPublishAsync(exchange, routingKey, basicProperties, body, mandatory);
300300

301301
public Task BasicQosAsync(uint prefetchSize, ushort prefetchCount, bool global)
302302
{

0 commit comments

Comments
 (0)