Skip to content

Commit

Permalink
Instrumentation RabbitMQ.Client 7.0.0 - traces (#3750)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Nov 8, 2024
1 parent fe0df15 commit 996bdb0
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 109 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

### Added

- Support for [RabbitMQ.Client](https://www.nuget.org/packages/RabbitMQ.Client/)
traces instrumentation for versions `7.0.0`+.

### Changed

#### Dependency updates
Expand All @@ -21,8 +24,6 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

## [1.9.0](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/tag/v1.9.0)

### Added

### Changed

- Musl-based (Alpine) libraries are compiled on Alpine v3.20.
Expand Down Expand Up @@ -55,8 +56,6 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
`OTEL_METRICS_EXPORTER`
`OTEL_LOGS_EXPORTER`.

### Fixed

## [1.8.0](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/tag/v1.8.0)

### Added
Expand Down
17 changes: 9 additions & 8 deletions build/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ public static partial class LibraryVersion
new("3.13.0"),
}
},
{
"TestApplication.RabbitMq",
new List<PackageBuildInfo>
{
new("6.0.0"),
new("6.8.1"),
new("7.0.0"),
}
},
{
"TestApplication.StackExchangeRedis",
new List<PackageBuildInfo>
Expand Down Expand Up @@ -175,13 +184,5 @@ public static partial class LibraryVersion
new("2.5.3"),
}
},
{
"TestApplication.RabbitMq",
new List<PackageBuildInfo>
{
new("6.0.0"),
new("6.8.1"),
}
},
};
}
59 changes: 31 additions & 28 deletions docs/config.md

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions docs/internal/instrumentation-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ submit an issue to request its inclusion.

### Inter-process communication (IPC)

| Library | [Tracing Support](../config.md#instrumented-traces-libraries-and-frameworks) | [Metrics Support](../config.md#instrumented-metrics-libraries-and-frameworks) | Notes |
|-----------------------------------------------------------------------------------|:----------------------------------------------------------------------------:|:-----------------------------------------------------------------------------:|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| [HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) | Yes | Yes | |
| [HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | Yes | Yes | |
| [WCF](https://docs.microsoft.com/dotnet/framework/wcf/whats-wcf) | Yes (Client adn Service side on .NET Framework) | | |
| [CoreWCF](https://github.com/CoreWCF/CoreWCF) | | | |
| [RestSharp](https://restsharp.dev/) | | | This library may be implicitly supported by instrumenting the underlying HttpClient or HttpWebRequest. |
| [gRPC-dotnet](https://github.com/grpc/grpc-dotnet) | Partial[^grpc_client_only] | | Client and service support should be added. |
| [GraphQL](https://www.nuget.org/packages/GraphQL/) | Partial[^not_on_framework] | | |
| [GraphQL Client](https://github.com/graphql-dotnet/graphql-client) | | | |
| [RabbitMQ](https://www.nuget.org/packages/RabbitMQ.Client) | | | These is an [issue in the RabbitMQ repo](https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/776) to add instrumentation directly into RabbitMQ. |
| [Kafka](https://www.nuget.org/packages/Confluent.Kafka) | | | |
| [NServiceBus](https://docs.particular.net/nservicebus/) | Yes | Yes | |
| [MassTransit](https://masstransit-project.com/) | Yes | | |
| Library | [Tracing Support](../config.md#instrumented-traces-libraries-and-frameworks) | [Metrics Support](../config.md#instrumented-metrics-libraries-and-frameworks) | Notes |
|-----------------------------------------------------------------------------------|:----------------------------------------------------------------------------:|:-----------------------------------------------------------------------------:|--------------------------------------------------------------------------------------------------------|
| [HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) | Yes | Yes | |
| [HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | Yes | Yes | |
| [WCF](https://docs.microsoft.com/dotnet/framework/wcf/whats-wcf) | Yes (Client adn Service side on .NET Framework) | | |
| [CoreWCF](https://github.com/CoreWCF/CoreWCF) | | | |
| [RestSharp](https://restsharp.dev/) | | | This library may be implicitly supported by instrumenting the underlying HttpClient or HttpWebRequest. |
| [gRPC-dotnet](https://github.com/grpc/grpc-dotnet) | Partial[^grpc_client_only] | | Client and service support should be added. |
| [GraphQL](https://www.nuget.org/packages/GraphQL/) | Partial[^not_on_framework] | | |
| [GraphQL Client](https://github.com/graphql-dotnet/graphql-client) | | | |
| [RabbitMQ](https://www.nuget.org/packages/RabbitMQ.Client) | Yes | | `RabbitMQ.Client` 7.0.0+ has native support for traces. |
| [Kafka](https://www.nuget.org/packages/Confluent.Kafka) | | | |
| [NServiceBus](https://docs.particular.net/nservicebus/) | Yes | Yes | |
| [MassTransit](https://masstransit-project.com/) | Yes | | |

### Logging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static TracerProviderBuilder UseEnvironmentVariables(
TracerInstrumentation.Azure => Wrappers.AddAzureInstrumentation(builder),
TracerInstrumentation.WcfClient => AddWcfIfNeeded(builder, ref wcfInstrumentationAdded),
TracerInstrumentation.OracleMda => Wrappers.AddOracleMdaInstrumentation(builder, lazyInstrumentationLoader, settings),
TracerInstrumentation.RabbitMq => builder.AddSource("RabbitMQ.Client.Publisher").AddSource("RabbitMQ.Client.Subscriber"),
#if NET6_0_OR_GREATER
TracerInstrumentation.AspNetCore => Wrappers.AddAspNetCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader, settings),
TracerInstrumentation.MassTransit => builder.AddSource("MassTransit"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ internal enum TracerInstrumentation
OracleMda = 21,

/// <summary>
/// RabbitMQ instrumentation
/// RabbitMQ client instrumentation
/// </summary>
RabbitMq = 22
}
4 changes: 2 additions & 2 deletions src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoad
break;
case TracerInstrumentation.Kafka:
break;
case TracerInstrumentation.RabbitMq:
break;
case TracerInstrumentation.OracleMda:
break;
case TracerInstrumentation.RabbitMq:
break;
default:
Logger.Warning($"Configured trace instrumentation type is not supported: {instrumentation}");
if (FailFastSettings.Value.FailFast)
Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageVersion Include="Quartz" Version="3.13.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.13.0" />
<PackageVersion Include="Quartz.Extensions.Hosting" Version="3.13.0" />
<PackageVersion Include="RabbitMQ.Client" Version="6.8.1" />
<PackageVersion Include="RabbitMQ.Client" Version="7.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.8.12" />
<PackageVersion Include="StrongNamer" Version="0.2.5" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
Expand Down
31 changes: 16 additions & 15 deletions test/IntegrationTests/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ public static TheoryData<string> Quartz
#else
theoryData.Add("3.6.0");
theoryData.Add("3.13.0");
#endif
return theoryData;
}
}
public static TheoryData<string> RabbitMq
{
get
{
var theoryData = new TheoryData<string>();
#if DEFAULT_TEST_PACKAGE_VERSIONS
theoryData.Add(string.Empty);
#else
theoryData.Add("6.0.0");
theoryData.Add("6.8.1");
theoryData.Add("7.0.0");
#endif
return theoryData;
}
Expand Down Expand Up @@ -317,20 +332,6 @@ public static TheoryData<string> Kafka_x64
theoryData.Add(string.Empty);
#else
theoryData.Add("1.4.0");
#endif
return theoryData;
}
}
public static TheoryData<string> RabbitMq
{
get
{
var theoryData = new TheoryData<string>();
#if DEFAULT_TEST_PACKAGE_VERSIONS
theoryData.Add(string.Empty);
#else
theoryData.Add("6.0.0");
theoryData.Add("6.8.1");
#endif
return theoryData;
}
Expand All @@ -354,10 +355,10 @@ public static TheoryData<string> RabbitMq
{ "OracleMda", OracleMda },
{ "OracleMdaCore", OracleMdaCore },
{ "Quartz", Quartz },
{ "RabbitMq", RabbitMq },
{ "StackExchangeRedis", StackExchangeRedis },
{ "WCFCoreClient", WCFCoreClient },
{ "Kafka", Kafka },
{ "Kafka_x64", Kafka_x64 },
{ "RabbitMq", RabbitMq },
};
}
66 changes: 47 additions & 19 deletions test/IntegrationTests/RabbitMqTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,14 @@ public void SubmitsTraces(string packageVersion)
// Skip the test if fixture does not support current platform
_rabbitMq.SkipIfUnsupportedPlatform();

using var collector = new MockSpansCollector(Output);
SetExporter(collector);

collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateProducerSpan(span));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateProducerSpan(span));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateProducerSpan(span));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateConsumerSpan(span, "receive"));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateConsumerSpan(span, "deliver"));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateConsumerSpan(span, "deliver"));

collector.ExpectCollected(collected => ValidatePropagation(collected));

EnableBytecodeInstrumentation();
RunTestApplication(new()
if (string.IsNullOrEmpty(packageVersion) || Version.Parse(packageVersion) >= new Version(7, 0, 0))
{
Arguments = $"--rabbitmq {_rabbitMq.Port}",
PackageVersion = packageVersion
});

collector.AssertExpectations();
TestRabbitMq7Plus(packageVersion);
}
else
{
TestRabbitMq6(packageVersion);
}
}

private static bool ValidatePropagation(ICollection<MockSpansCollector.Collected> collected)
Expand Down Expand Up @@ -106,6 +94,46 @@ private static bool ValidateBasicSpanAttributes(IReadOnlyCollection<KeyValue> at
bodySize == 13;
}

private void TestRabbitMq7Plus(string packageVersion)
{
using var collector = new MockSpansCollector(Output);
SetExporter(collector);
collector.Expect("RabbitMQ.Client.Publisher");
collector.Expect("RabbitMQ.Client.Subscriber");

RunTestApplication(new()
{
Arguments = $"--rabbitmq {_rabbitMq.Port}",
PackageVersion = packageVersion
});

collector.AssertExpectations();
}

private void TestRabbitMq6(string packageVersion)
{
using var collector = new MockSpansCollector(Output);
SetExporter(collector);

collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateProducerSpan(span));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateProducerSpan(span));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateProducerSpan(span));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateConsumerSpan(span, "receive"));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateConsumerSpan(span, "deliver"));
collector.Expect("OpenTelemetry.AutoInstrumentation.RabbitMq", span => ValidateConsumerSpan(span, "deliver"));

collector.ExpectCollected(collected => ValidatePropagation(collected));

EnableBytecodeInstrumentation();
RunTestApplication(new()
{
Arguments = $"--rabbitmq {_rabbitMq.Port}",
PackageVersion = packageVersion
});

collector.AssertExpectations();
}

private bool ValidateConsumerSpan(Span span, string operationName)
{
var deliveryTag = span.Attributes.SingleOrDefault(kv => kv.Key == RabbitMqDeliveryTagAttributeName)?.Value.StringValue;
Expand Down
Loading

0 comments on commit 996bdb0

Please sign in to comment.