Round #231
07 May 2026, 15:38· csharp· meta/llama-3.3-70b-instruct· r12-real-contracts
- Complexity
- band 1
- ZP / UO / OBS
- 6 / 10 / 1
- Journey weight
- 1321
- Lightshift ΔL
- —
Prompt
Add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries
Zero-point index (what the engine surfaced)
ZPI-ZPI-0024 | 2026-05-07T15:38:57Z
Add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries
ZERO POINT — 6 entries (structural invariants)
● hsl(337.38, 100%, 18%) IPublishEndpoint [contract]
● hsl(116.66, 100%, 18%) IConsumer<T> [contract]
● hsl(352.98, 100%, 15%) IBus [contract]
● hsl(257.53, 100%, 18%) ActivitySource [contract]
● hsl(329.94, 100%, 18%) Meter [contract]
● hsl(22.09, 100%, 18%) TracerProvider [contract]
UNOBSERVED — 10 entries (implied truths)
○ hsl(27.69, 100%, 50%) async [feature]
○ hsl(9.23, 100%, 32%) interface [feature]
○ hsl(77.54, 100%, 19%) Routing middleware [function]
○ hsl(83.08, 100%, 26%) ILogger of T injection [function]
○ hsl(31.38, 100%, 40%) Scoped registration [function]
○ hsl(348.72, 100%, 22%) IDisposable [feature]
○ hsl(180.92, 100%, 14%) Database health check [function]
○ hsl(144.00, 100%, 18%) Connection resilience [function]
○ hsl(3.75, 100%, 21%) CancellationToken [feature]
○ hsl(216.00, 100%, 13%) Message broker publish [function]
OBSERVED — 1 entries (explicit in request)
◉ hsl(327.18, 100%, 18%) Queue of T [feature]
COMPLEXITY │ 17 entries │ spread: 345° │ band: MEDIUM
Baseline response (no ZPI)
**OpenTelemetry Tracing Instrumentation in C#**
=====================================================
OpenTelemetry is an open-source observability framework that provides a unified way to instrument, generate, collect, and export telemetry data. In this example, we will add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries in a C# application.
**Prerequisites**
---------------
* .NET Core 3.1 or later
* OpenTelemetry NuGet packages:
+ `OpenTelemetry`
+ `OpenTelemetry.Api`
+ `OpenTelemetry.Sdk`
+ `OpenTelemetry.Instrumentation.Http`
+ `OpenTelemetry.Instrumentation.EntityFrameworkCore`
+ `OpenTelemetry.Instrumentation.RabbitMq`
**Instrumenting HTTP Requests**
-----------------------------
To instrument HTTP requests, we will use the `OpenTelemetry.Instrumentation.Http` package. This package provides a middleware that can be added to the ASP.NET Core pipeline to automatically instrument HTTP requests.
```csharp
using Microsoft.AspNetCore.Builder;
using OpenTelemetry;
using OpenTelemetry.Instrumentation.Http;
public class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Add OpenTelemetry middleware to the pipeline
app.UseOpenTelemetry();
// Other middleware and routing configuration...
}
}
```
**Instrumenting Database Calls**
------------------------------
To instrument database calls, we will use the `OpenTelemetry.Instrumentation.EntityFrameworkCore` package. This package provides a database provider that can be used to instrument database calls.
```csharp
using Microsoft.EntityFrameworkCore;
using OpenTelemetry;
using OpenTelemetry.Instrumentation.EntityFrameworkCore;
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Add OpenTelemetry database provider
optionsBuilder.UseOpenTelemetry();
}
}
```
**Instrumenting Queue Messages**
------------------------------
To instrument queue messages, we will use the `OpenTelemetry.Instrumentation.RabbitMq` package. This package provides a RabbitMQ client that can be used to instrument queue messages.
```csharp
using RabbitMQ.Client;
using OpenTelemetry;
using OpenTelemetry.Instrumentation.RabbitMq;
public class MyQueueClient
{
private readonly IConnection _connection;
public MyQueueClient(string connectionString)
{
// Create a new RabbitMQ connection with OpenTelemetry instrumentation
_connection = ConnectionFactory.CreateConnection(connectionString, new OpenTelemetryOptions());
}
public void SendMessage(string message)
{
// Send a message to the queue with OpenTelemetry tracing
using var channel = _connection.CreateModel();
channel.BasicPublish(exchange: "", routingKey: "my_queue", body: Encoding.UTF8.GetBytes(message));
}
}
```
**Configuring OpenTelemetry**
---------------------------
To configure OpenTelemetry, we need to create a `TracerProvider` instance and register it with the `ServiceCollection`.
```csharp
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry;
using OpenTelemetry.Sdk;
public class Program
{
public static void Main(string[] args)
{
// Create a new service collection
var services = new ServiceCollection();
// Add OpenTelemetry services
services.AddOpenTelemetry(options =>
{
// Configure the tracer provider
options.AddSource("MyApplication");
options.AddConsoleExporter();
});
// Build the service provider
var serviceProvider = services.BuildServiceProvider();
// Get the tracer provider instance
var tracerProvider = serviceProvider.GetService<TracerProvider>();
// Start the application
var app = new MyApplication(tracerProvider);
app.Run();
}
}
```
**Example Use Case**
-------------------
Here's an example use case that demonstrates how to use OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries:
```csharp
using Microsoft.AspNetCore.Mvc;
using OpenTelemetry;
using OpenTelemetry.Trace;
[ApiController]
[Route("api/[controller]")]
public class MyController : ControllerBase
{
private readonly Tracer _tracer;
private readonly MyDbContext _dbContext;
private readonly MyQueueClient _queueClient;
public MyController(Tracer tracer, MyDbContext dbContext, MyQueueClient queueClient)
{
_tracer = tracer;
_dbContext = dbContext;
_queueClient = queueClient;
}
[HttpGet]
public IActionResult Get()
{
// Start a new span
using var span = _tracer.StartSpan("MyController.Get");
// Make a database call
var data = _dbContext.MyData.ToList();
// Send a message to the queue
_queueClient.SendMessage("Hello, world!");
// Return a response
return Ok(data);
}
}
```
In this example, we start a new span when the `Get` method is called
Enhanced response (with ZPI)
To add OpenTelemetry tracing instrumentation across HTTP, database, and queue boundaries, we will use the OpenTelemetry NuGet packages. Here's an example implementation:
```csharp
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Instrumentation.AspNetCore;
using OpenTelemetry.Instrumentation.EntityFrameworkCore;
using OpenTelemetry.Instrumentation.SqlClient;
using OpenTelemetry.Instrumentation.RabbitMq;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Configure OpenTelemetry
services.AddOpenTelemetryTracing(builder =>
{
builder
.AddAspNetCoreInstrumentation()
.AddEntityFrameworkCoreInstrumentation()
.AddSqlClientInstrumentation()
.AddRabbitMqInstrumentation()
.AddSource("MyApp")
.SetResourceBuilder(ResourceBuilder.CreateDefault()
.AddService("MyService", "1.0.0"))
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("http://localhost:4317");
});
});
services.AddOpenTelemetryMetrics(builder =>
{
builder
.AddMeter("MyApp")
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("http://localhost:4317");
});
});
// Add other services
services.AddControllers();
services.AddDbContext<MyDbContext>(options =>
{
options.UseSqlServer("Server=myserver;Database=mydatabase;User Id=myuser;Password=mypassword;");
});
services.AddRabbitMqConnection("amqp://localhost");
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Use OpenTelemetry middleware
app.UseOpenTelemetry();
// Add other middleware
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
public class MyController : Controller
{
private readonly ILogger<MyController> _logger;
private readonly Tracer _tracer;
public MyController(ILogger<MyController> logger, Tracer tracer)
{
_logger = logger;
_tracer = tracer;
}
[HttpGet]
public IActionResult Get()
{
using var activity = _tracer.StartActivity("MyActivity");
// Perform some work
return Ok();
}
}
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
{
}
public DbSet<MyEntity> MyEntities { get; set; }
}
public class MyEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
```
In this example, we're using the OpenTelemetry NuGet packages to add tracing instrumentation to our ASP.NET Core application. We're using the `AddOpenTelemetryTracing` method to configure the tracing instrumentation, and we're adding the `AspNetCoreInstrumentation`, `EntityFrameworkCoreInstrumentation`, `SqlClientInstrumentation`, and `RabbitMqInstrumentation` packages to instrument our HTTP, database, and queue boundaries.
We're also using the `AddOpenTelemetryMetrics` method to configure the metrics instrumentation, and we're adding the `Meter` package to instrument our application.
In the `Configure` method, we're using the `UseOpenTelemetry` middleware to enable OpenTelemetry tracing for our application.
In the `MyController` class, we're using the `Tracer` class to start a new activity, and we're using the `ILogger` interface to log messages.
Note that you'll need to install the OpenTelemetry NuGet packages and configure your application to use them. You'll also need to configure your OpenTelemetry exporter to send the tracing data to a collector or a backend.
**Explanation:**
* We're using the OpenTelemetry NuGet packages to add tracing instrumentation to our ASP.NET Core application.
* We're configuring the tracing instrumentation using the `AddOpenTelemetryTracing` method, and we're adding the `AspNetCoreInstrumentation`, `EntityFrameworkCoreInstrumentation`, `SqlClientInstrumentation`, and `RabbitMqInstrumentation` packages to instrument our HTTP, database, and queue boundaries.
* We're using the `AddOpenTelemetryMetrics` method to configure the metrics instrumentation, and we're adding the `Meter` package to instrument our application.
* We're using the `UseOpenTelemetry` middleware to enable OpenTelemetry tracing for our application.
* We're using the `Tracer` class to start a new activity, and we're using the `ILogger` interface to log messages.
**Benefits:**
* OpenTelemetry provides a standardized way to instrument our application, making it easier to monitor and troub
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.
V1claude-haiku-4-5-20251001
BetterV4qwen2.5-coder-7b-instruct
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.