Round #515
09 May 2026, 20:07· csharp· qwen2.5-coder-7b-instruct· r13-clean-hints
- Complexity
- band 1
- ZP / UO / OBS
- 6 / 10 / 1
- Journey weight
- 1175
- Lightshift ΔL
- +0.25
Prompt
Add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries
Zero-point index (what the engine surfaced)
ZPI-ZPI-0024 | 2026-05-09T20:07:28Z
Add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries
ZERO POINT — 6 entries (structural invariants)
● hsl(337.38, 100%, 21%) IPublishEndpoint [contract]
● hsl(116.66, 100%, 21%) IConsumer<T> [contract]
● hsl(352.98, 100%, 18%) IBus [contract]
● hsl(257.53, 100%, 21%) ActivitySource [contract]
● hsl(329.94, 100%, 21%) Meter [contract]
● hsl(22.09, 100%, 21%) TracerProvider [contract]
UNOBSERVED — 10 entries (implied truths)
○ hsl(27.69, 100%, 50%) async [feature]
○ hsl(9.23, 100%, 50%) interface [feature]
○ hsl(77.54, 100%, 42%) Routing middleware [function]
○ hsl(83.08, 100%, 42%) ILogger of T injection [function]
○ hsl(31.38, 100%, 42%) Scoped registration [function]
○ hsl(348.72, 100%, 30%) IDisposable [feature]
○ hsl(180.92, 100%, 22%) Database health check [function]
○ hsl(144.00, 100%, 42%) Connection resilience [function]
○ hsl(3.75, 100%, 38%) CancellationToken [feature]
○ hsl(216.00, 100%, 24%) Message broker publish [function]
OBSERVED — 1 entries (explicit in request)
◉ hsl(327.18, 100%, 21%) Queue of T [feature]
COMPLEXITY │ 17 entries │ spread: 345° │ band: MEDIUM
Baseline response (no ZPI)
To add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries in a C# application, you'll need to follow these steps:
1. **Install the necessary NuGet packages**:
You'll need to install the OpenTelemetry packages for various components like HTTP, databases (e.g., SQL Server), and queues (e.g., Azure Service Bus).
```sh
dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.SqlClient
dotnet add package OpenTelemetry.Instrumentation.ServiceBus
```
2. **Configure OpenTelemetry in your application**:
You can configure OpenTelemetry using the `Program.cs` file if you're using .NET 6 or later, or `Startup.cs` for earlier versions.
```csharp
// Program.cs (for .NET 6 and later)
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// OpenTelemetry configuration
builder.Services.AddOpenTelemetryTracing(b =>
{
b.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("YourServiceName"));
b.AddAspNetCoreInstrumentation();
b.AddSqlClientInstrumentation();
b.AddServiceBusInstrumentation();
b.AddOtlpExporter(o => o.Endpoint = new Uri("http://localhost:4317")); // Change to your OTLP endpoint
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
```
3. **Instrument your HTTP requests**:
OpenTelemetry will automatically instrument ASP.NET Core requests, but you can also add custom instrumentation if needed.
4. **Instrument database operations**:
For SQL Server, the `OpenTelemetry.Instrumentation.SqlClient` package will automatically instrument database calls.
5. **Instrument queue operations**:
For Azure Service Bus, the `OpenTelemetry.Instrumentation.ServiceBus` package will automatically instrument queue operations.
6. **Export traces to an observability backend**:
In the example above, traces are exported to an OTLP endpoint (`http://localhost:4317`). You can configure this to export to other backends like Jaeger, Zipkin, or Azure Monitor.
### Example of a Custom Instrumentation
If you need custom instrumentation for HTTP requests, you can use middleware:
```csharp
app.Use(async (context, next) =>
{
var activity = new Activity("CustomHttpActivity")
.SetStartTime(DateTime.UtcNow)
.SetTag("http.url", context.Request.GetDisplayUrl())
.SetTag("http.method", context.Request.Method);
using (activity.Start())
{
await next();
}
activity.SetEndTime(DateTime.UtcNow);
});
```
### Example of a Custom Instrumentation for Database
If you need custom instrumentation for database operations, you can use the `ActivitySource`:
```csharp
var sqlClientInstrumentor = new SqlClientInstrumentor();
sqlClientInstrumentor.Initialize();
// Your database operation here
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
using (var command = new SqlCommand("SELECT * FROM YourTable", connection))
{
var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
// Process data
}
}
}
```
### Example of a Custom Instrumentation for Queue
If you need custom instrumentation for queue operations, you can use the `ActivitySource`:
```csharp
var serviceBusInstrumentor = new ServiceBusInstrumentor();
serviceBusInstrumentor.Initialize();
// Your queue operation here
using (var client = new ServiceBusClient(connectionString))
{
var sender = client.CreateSender("YourQueueName");
await sender.SendMessageAsync(new ServiceBusMessage("Hello, World!"));
}
```
By following these steps, you can add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries in your C# application.
Enhanced response (with ZPI)
To add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries in a C# application, we can use the `ActivitySource`, `Meter`, and `TracerProvider` classes provided by the OpenTelemetry library. We will also use dependency injection (DI) to register these components.
Here's how you can implement this:
1. **Install necessary packages**:
```sh
dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Exporter.Console
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.EntityFrameworkCore
dotnet add package OpenTelemetry.Instrumentation.RabbitMQ
```
2. **Configure OpenTelemetry in your application**:
```csharp
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
public static class OpenTelemetryExtensions
{
public static IServiceCollection AddOpenTelemetryTracing(this IServiceCollection services)
{
return services.AddOpenTelemetryTracing(builder =>
{
builder.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyApplication"));
// Configure the tracer provider
builder.ConfigureServices((context, services) =>
{
services.AddSingleton<ActivitySource>(new ActivitySource("MyApplication"));
});
// Add instrumentation for ASP.NET Core
builder.AddAspNetCoreInstrumentation();
// Add instrumentation for Entity Framework Core
builder.AddEntityFrameworkCoreInstrumentation();
// Add instrumentation for RabbitMQ
builder.AddRabbitMQInstrumentation();
// Export traces to the console (for demonstration purposes)
builder.AddConsoleExporter();
});
}
}
```
3. **Register OpenTelemetry in your `Program.cs` or `Startup.cs`**:
```csharp
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Configure OpenTelemetry tracing
builder.Services.AddOpenTelemetryTracing();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
```
### Explanation
1. **Installation of Packages**:
- `OpenTelemetry`: Core library for OpenTelemetry.
- `OpenTelemetry.Exporter.Console`: Export traces to the console for demonstration purposes.
- `OpenTelemetry.Instrumentation.AspNetCore`: Instrumentation for ASP.NET Core applications.
- `OpenTelemetry.Instrumentation.EntityFrameworkCore`: Instrumentation for Entity Framework Core.
- `OpenTelemetry.Instrumentation.RabbitMQ`: Instrumentation for RabbitMQ.
2. **Configuration**:
- We configure the `ActivitySource` with a name "MyApplication".
- We add instrumentation for ASP.NET Core, Entity Framework Core, and RabbitMQ.
- We export traces to the console using `AddConsoleExporter()` for demonstration purposes.
3. **Registration**:
- We register OpenTelemetry tracing in the DI container using `AddOpenTelemetryTracing()`.
- This method configures the tracer provider, sets up instrumentation, and exports traces.
By following these steps, you will have OpenTelemetry tracing instrumentation across HTTP, database (Entity Framework Core), and queue (RabbitMQ) boundaries in your C# application.
Grader chain
Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.
V1samba/Meta-Llama-3.3-70B-Instruct
BetterV4qwen2.5-coder-3b-instruct
BetterV5openrouter/qwen/qwen3-235b-a22b-2507
BetterV7qwen2.5-coder-7b-instruct
BetterV8openai/gpt-4.1
BetterV9anthropic/claude-opus-4-7
WorseV12openai/gpt-4o
BetterComments
Our grader said what it said. What do you say? Comment as a guest below.
No comments yet. Be the first to say what you make of this round.