Skip to content

Commit

Permalink
Add MetricCollector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NooNameR committed Aug 21, 2024
1 parent 942b7dd commit 0b5cf47
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 81 deletions.
6 changes: 5 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" Condition="'$(TargetFramework)' != 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics" Version="8.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.1" Condition="'$(TargetFramework)' != 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.8.0"/>
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" Condition="'$(TargetFramework)' != 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="6.0.0" Condition="'$(TargetFramework)' != 'net8.0'" />
Expand All @@ -78,8 +80,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.9.0"/>
<PackageVersion Include="OpenTelemetry.Exporter.Jaeger" Version="1.5.1" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0"/>
<PackageVersion Include="prometheus-net" Version="6.0.0" />
<PackageVersion Include="Quartz" Version="3.12.0" />
<PackageVersion Include="Quartz.Extensions.Hosting" Version="3.12.0" />
Expand All @@ -103,4 +107,4 @@
<GlobalPackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting"/>
<PackageReference Include="SharpZipLib" />
<ProjectReference Include="..\..\src\MassTransit.TestFramework\MassTransit.TestFramework.csproj" />
<ProjectReference Include="..\..\src\MassTransit\MassTransit.csproj" />
Expand Down
50 changes: 25 additions & 25 deletions tests/MassTransit.ActiveMqTransport.Tests/OpenTelemetry_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace MassTransit.ActiveMqTransport.Tests
using System.Diagnostics;
using System.Threading.Tasks;
using HarnessContracts;
using Logging;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using OpenTelemetry;
Expand Down Expand Up @@ -38,32 +39,31 @@ public class OpenTelemetry_Specs
[Test]
public async Task Should_report_telemetry_to_jaeger()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("order-api"))
.AddSource("MassTransit")
.AddJaegerExporter(o =>
{
o.AgentHost = "localhost";
o.AgentPort = 6831;

// Examples for the rest of the options, defaults unless otherwise specified
// Omitting Process Tags example as Resource API is recommended for additional tags
o.MaxPayloadSizeInBytes = 4096;

// Using Batch Exporter (which is default)
// The other option is ExportProcessorType.Simple
o.ExportProcessorType = ExportProcessorType.Batch;
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<Activity>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512,
};
})
.Build();

var services = new ServiceCollection();
services.AddOpenTelemetry()
.WithTracing(t => t.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("order-api"))
.AddSource(DiagnosticHeaders.DefaultListenerName)
.AddJaegerExporter(o =>
{
o.AgentHost = "localhost";
o.AgentPort = 6831;

// Examples for the rest of the options, defaults unless otherwise specified
// Omitting Process Tags example as Resource API is recommended for additional tags
o.MaxPayloadSizeInBytes = 4096;

// Using Batch Exporter (which is default)
// The other option is ExportProcessorType.Simple
o.ExportProcessorType = ExportProcessorType.Batch;
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<Activity>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512
};
})
.Build());

await using var provider = services
.AddMassTransitTestHarness(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting"/>
<ProjectReference Include="..\..\src\MassTransit.Newtonsoft\MassTransit.Newtonsoft.csproj" />
<ProjectReference Include="..\..\src\MassTransit.TestFramework\MassTransit.TestFramework.csproj" />
<ProjectReference Include="..\..\src\MassTransit\MassTransit.csproj" />
Expand Down
50 changes: 25 additions & 25 deletions tests/MassTransit.AmazonSqsTransport.Tests/OpenTelemetry_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace MassTransit.AmazonSqsTransport.Tests
using System.Diagnostics;
using System.Threading.Tasks;
using HarnessContracts;
using Logging;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using OpenTelemetry;
Expand Down Expand Up @@ -38,32 +39,31 @@ public class OpenTelemetry_Specs
[Test]
public async Task Should_report_telemetry_to_jaeger()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("order-api"))
.AddSource("MassTransit")
.AddJaegerExporter(o =>
{
o.AgentHost = "localhost";
o.AgentPort = 6831;

// Examples for the rest of the options, defaults unless otherwise specified
// Omitting Process Tags example as Resource API is recommended for additional tags
o.MaxPayloadSizeInBytes = 4096;

// Using Batch Exporter (which is default)
// The other option is ExportProcessorType.Simple
o.ExportProcessorType = ExportProcessorType.Batch;
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<Activity>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512,
};
})
.Build();

var services = new ServiceCollection();
services.AddOpenTelemetry()
.WithTracing(t => t.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("order-api"))
.AddSource(DiagnosticHeaders.DefaultListenerName)
.AddJaegerExporter(o =>
{
o.AgentHost = "localhost";
o.AgentPort = 6831;

// Examples for the rest of the options, defaults unless otherwise specified
// Omitting Process Tags example as Resource API is recommended for additional tags
o.MaxPayloadSizeInBytes = 4096;

// Using Batch Exporter (which is default)
// The other option is ExportProcessorType.Simple
o.ExportProcessorType = ExportProcessorType.Batch;
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<Activity>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512
};
})
.Build());

await using var provider = services
.AddMassTransitTestHarness(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting"/>
<ProjectReference Include="..\..\src\MassTransit.Newtonsoft\MassTransit.Newtonsoft.csproj" />
<ProjectReference Include="..\..\src\MassTransit.TestFramework\MassTransit.TestFramework.csproj" />
<ProjectReference Include="..\..\src\MassTransit\MassTransit.csproj" />
Expand Down
56 changes: 26 additions & 30 deletions tests/MassTransit.RabbitMqTransport.Tests/OpenTelemetry_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class OpenTelemetry_Specs
[Test]
public async Task Should_carry_the_baggage_with_newtonsoft()
{
using var tracerProvider = CreateTraceProvider("order-api");

var services = new ServiceCollection();
AddTraceListener(services, "order-api");

await using var provider = services
.AddMassTransitTestHarness(x =>
Expand Down Expand Up @@ -76,9 +75,8 @@ await Assert.MultipleAsync(async () =>
[Test]
public async Task Should_report_telemetry_to_jaeger()
{
using var tracerProvider = CreateTraceProvider("order-api");

var services = new ServiceCollection();
AddTraceListener(services, "order-api");

await using var provider = services
.AddMassTransitTestHarness(x =>
Expand Down Expand Up @@ -125,9 +123,8 @@ await Assert.MultipleAsync(async () =>
[Test]
public async Task Should_report_telemetry_to_jaeger_for_batch_consumer()
{
using var tracerProvider = CreateTraceProvider("order-api");

var services = new ServiceCollection();
AddTraceListener(services, "order-api");

await using var provider = services
.AddMassTransitTestHarness(x =>
Expand Down Expand Up @@ -169,9 +166,8 @@ await harness.Bus.Publish<OrderSubmitted>(new
[Test]
public async Task Should_report_telemetry_to_jaeger_for_routing_slip()
{
using var tracerProvider = CreateTraceProvider("routing-api");

var services = new ServiceCollection();
AddTraceListener(services, "routing-api");

await using var provider = services
.AddMassTransitTestHarness(x =>
Expand Down Expand Up @@ -210,9 +206,8 @@ public async Task Should_report_telemetry_to_jaeger_for_routing_slip()
[Test]
public async Task Should_report_telemetry_to_jaeger_from_mediator()
{
using var tracerProvider = CreateTraceProvider("mediator");

var services = new ServiceCollection();
AddTraceListener(services, "mediator");

await using var provider = services
.AddMediator(x =>
Expand All @@ -238,9 +233,10 @@ await client.GetResponse<OrderSubmitted>(new
[Test]
public async Task Should_support_the_saga_harness()
{
using var tracerProvider = CreateTraceProvider("saga-api");
var services = new ServiceCollection();
AddTraceListener(services, "saga-api");

await using var provider = new ServiceCollection()
await using var provider = services
.AddMassTransitTestHarness(x =>
{
x.SetKebabCaseEndpointNameFormatter();
Expand Down Expand Up @@ -287,26 +283,26 @@ await Assert.MultipleAsync(async () =>
});
}

static TracerProvider CreateTraceProvider(string serviceName)
static void AddTraceListener(IServiceCollection services, string serviceName)
{
return Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName))
.AddSource("MassTransit")
.AddJaegerExporter(o =>
{
o.AgentHost = "localhost";
o.AgentPort = 6831;
o.MaxPayloadSizeInBytes = 4096;
o.ExportProcessorType = ExportProcessorType.Batch;
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<System.Diagnostics.Activity>
services.AddOpenTelemetry()
.WithTracing(t => t.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName))
.AddSource(DiagnosticHeaders.DefaultListenerName)
.AddJaegerExporter(o =>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512,
};
})
.Build();
o.AgentHost = "localhost";
o.AgentPort = 6831;
o.MaxPayloadSizeInBytes = 4096;
o.ExportProcessorType = ExportProcessorType.Batch;
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<System.Diagnostics.Activity>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512
};
})
.Build());
}


Expand Down
Loading

0 comments on commit 0b5cf47

Please sign in to comment.