-
Notifications
You must be signed in to change notification settings - Fork 853
Enable tracing for RabbitMQ Component (v7) #15659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,23 +1,30 @@ | ||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||
|
|
||||||||||||||
| using System.Diagnostics; | ||||||||||||||
| using Aspire.TestUtilities; | ||||||||||||||
| using Aspire.Components.ConformanceTests; | ||||||||||||||
| using Microsoft.Extensions.Configuration; | ||||||||||||||
| using Microsoft.Extensions.DependencyInjection; | ||||||||||||||
| using Microsoft.Extensions.Hosting; | ||||||||||||||
| using Microsoft.Extensions.Logging; | ||||||||||||||
| using OpenTelemetry.Trace; | ||||||||||||||
| using RabbitMQ.Client; | ||||||||||||||
| using Xunit; | ||||||||||||||
|
|
||||||||||||||
| namespace Aspire.RabbitMQ.Client.Tests; | ||||||||||||||
|
|
||||||||||||||
| public class ConformanceTests : ConformanceTests<IConnection, RabbitMQClientSettings>, IClassFixture<RabbitMQContainerFixture> | ||||||||||||||
| { | ||||||||||||||
| private readonly RabbitMQContainerFixture _containerFixture; | ||||||||||||||
| private readonly RabbitMQContainerFixture? _containerFixture; | ||||||||||||||
| private string ConnectionString { get; set; } | ||||||||||||||
|
|
||||||||||||||
| public ConformanceTests(RabbitMQContainerFixture containerFixture, ITestOutputHelper? output = null) : base(output) | ||||||||||||||
| public ConformanceTests(RabbitMQContainerFixture? containerFixture, ITestOutputHelper? output = null) : base(output) | ||||||||||||||
| { | ||||||||||||||
| _containerFixture = containerFixture; | ||||||||||||||
| ConnectionString = (_containerFixture is not null && RequiresFeatureAttribute.IsFeatureSupported(TestFeature.Docker)) | ||||||||||||||
| ? _containerFixture.GetConnectionString() | ||||||||||||||
| : "amqp://localhost:5672"; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| protected override ServiceLifetime ServiceLifetime => ServiceLifetime.Singleton; | ||||||||||||||
|
|
@@ -31,7 +38,11 @@ public ConformanceTests(RabbitMQContainerFixture containerFixture, ITestOutputHe | |||||||||||||
|
|
||||||||||||||
| protected override string[] RequiredLogCategories => Array.Empty<string>(); | ||||||||||||||
|
|
||||||||||||||
| protected override string ActivitySourceName => ""; | ||||||||||||||
| #if RABBITMQ_V6 | ||||||||||||||
| protected override string ActivitySourceName => "Aspire.RabbitMQ.Client"; | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this get used for v6? |
||||||||||||||
| #else | ||||||||||||||
| protected override string ActivitySourceName => "RabbitMQ.Client.Publisher"; | ||||||||||||||
| #endif | ||||||||||||||
|
|
||||||||||||||
| protected override string? ConfigurationSectionName => "Aspire:RabbitMQ:Client"; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -69,15 +80,9 @@ protected override (string json, string error)[] InvalidJsonToErrorMessage => ne | |||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| protected override void PopulateConfiguration(ConfigurationManager configuration, string? key = null) | ||||||||||||||
| { | ||||||||||||||
| var connectionString = RequiresFeatureAttribute.IsFeatureSupported(TestFeature.Docker) ? | ||||||||||||||
eerhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| _containerFixture.GetConnectionString() : | ||||||||||||||
| "amqp://localhost:5672"; | ||||||||||||||
|
|
||||||||||||||
| configuration.AddInMemoryCollection([ | ||||||||||||||
| new(CreateConfigKey("Aspire:RabbitMQ:Client", key, "ConnectionString"), connectionString) | ||||||||||||||
| => configuration.AddInMemoryCollection([ | ||||||||||||||
| new(CreateConfigKey("Aspire:RabbitMQ:Client", key, "ConnectionString"), ConnectionString) | ||||||||||||||
| ]); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| protected override void RegisterComponent(HostApplicationBuilder builder, Action<RabbitMQClientSettings>? configure = null, string? key = null) | ||||||||||||||
| { | ||||||||||||||
|
|
@@ -132,4 +137,48 @@ protected override void SetupConnectionInformationIsDelayValidated() | |||||||||||||
| { | ||||||||||||||
| Assert.Skip("RabbitMQ connects to localhost by default if the connection information isn't available."); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #if !RABBITMQ_V6 | ||||||||||||||
| [Fact] | ||||||||||||||
| [RequiresFeature(TestFeature.Docker)] | ||||||||||||||
| public void TracingEnablesTheRightActivitySource() | ||||||||||||||
| => RemoteInvokeWithLogging(static connectionStringToUse => | ||||||||||||||
| RunWithConnectionString(connectionStringToUse, static obj => obj.RunActivitySourceTest(key: null)), | ||||||||||||||
| ConnectionString, Output); | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| [RequiresFeature(TestFeature.Docker)] | ||||||||||||||
| public void TracingEnablesTheRightActivitySource_Keyed() | ||||||||||||||
| => RemoteInvokeWithLogging(static connectionStringToUse => | ||||||||||||||
| RunWithConnectionString(connectionStringToUse, static obj => obj.RunActivitySourceTest(key: "key")), | ||||||||||||||
| ConnectionString, Output); | ||||||||||||||
|
|
||||||||||||||
| private void RunActivitySourceTest(string? key) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't this call the base test method? aspire/tests/Aspire.Components.Common.TestUtilities/ConformanceTests.cs Lines 488 to 493 in 2916fba
|
||||||||||||||
| { | ||||||||||||||
| HostApplicationBuilder builder = CreateHostBuilder(key: key); | ||||||||||||||
| builder.Logging.AddConsole(); | ||||||||||||||
| RegisterComponent(builder, options => SetTracing(options, true), key); | ||||||||||||||
|
|
||||||||||||||
| List<Activity> exportedActivities = []; | ||||||||||||||
| builder.Services.AddOpenTelemetry().WithTracing(traceBuilder => traceBuilder.AddInMemoryExporter(exportedActivities)); | ||||||||||||||
|
|
||||||||||||||
| using IHost host = builder.Build(); | ||||||||||||||
| host.Start(); | ||||||||||||||
|
|
||||||||||||||
| IConnection service = key is null | ||||||||||||||
| ? host.Services.GetRequiredService<IConnection>() | ||||||||||||||
| : host.Services.GetRequiredKeyedService<IConnection>(key); | ||||||||||||||
|
|
||||||||||||||
| // Clear activities generated during connection establishment (from "Aspire.RabbitMQ.Client" source) | ||||||||||||||
| exportedActivities.Clear(); | ||||||||||||||
|
|
||||||||||||||
| TriggerActivity(service); | ||||||||||||||
|
|
||||||||||||||
| Assert.NotEmpty(exportedActivities); | ||||||||||||||
| Assert.Contains(exportedActivities, activity => activity.Source.Name == ActivitySourceName); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private static void RunWithConnectionString(string connectionString, Action<ConformanceTests> test) | ||||||||||||||
| => test(new ConformanceTests(null) { ConnectionString = connectionString }); | ||||||||||||||
| #endif | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have this section in other READMEs? I don't see it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We track these in https://github.com/microsoft/aspire/blob/main/src/Components/Telemetry.md - which doesn't have the new ones - RabbitMQ.Client.Publisher and Subscriber