public class TracingMiddleware { private readonly RequestDelegate _next; private readonly ITracer _tracer; public TracingMiddleware(RequestDelegate next, ITracer tracer) { _next = next; _tracer = tracer; } public async Task InvokeAsync(HttpContext context) { // Start a new span for this request var span = _tracer.StartSpan("http.request"); span.SetTag("http.method", context.Request.Method); span.SetTag("http.url", context.Request.Path); // Inject the tracing headers into the outgoing HTTP request _tracer.Inject(span.Context, BuiltinFormats.HttpHeaders, new TextMapInjectAdapter(context.Request.Headers)); // Call the next middleware component in the pipeline await _next(context); // Finish the span when the request completes span.Finish(); } }This example shows how the TracingMiddleware component can be constructed with an ITracer instance, and then use that tracer to start and finish spans for each incoming HTTP request. It also demonstrates how the tracer can inject tracing headers into outgoing HTTP requests using the TextMapInjectAdapter. The ITracer Inject interface is typically included in a package library for distributed tracing, such as OpenTelemetry, Jaeger, or Zipkin.