The middleware emits a System.Diagnostics.Activity for each evaluation, so IP filtering shows up in your traces alongside the rest of the request. This uses the standard .NET diagnostics primitives and is picked up by OpenTelemetry with no extra code in the library.
Activity source
The ActivitySource name is:
BBelius.Yarp.ReverseProxy.IPFilters
Each request that reaches the middleware starts an activity named IPFilterEvaluation.
Span tags
Tags are set depending on the outcome:
| Tag | Value | When | ||
|---|---|---|---|---|
blocked | true | The request was blocked by the global or a route-specific policy. | ||
policy | "global" or the policy name | Identifies which policy blocked the request. | ||
ip | the client IP | The remote IP that was evaluated, on a block. | ||
error | "policy_not_found" | A route referenced a policy name that does not exist. The activity status is also set to Error. |
Allowed requests start and complete the activity without the block/error tags.
Subscribing with OpenTelemetry
Register the source with the OpenTelemetry .NET SDK:
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddSource("BBelius.Yarp.ReverseProxy.IPFilters")
.AddOtlpExporter());
Once the source is added, IPFilterEvaluation spans are exported to your collector with the tags above, letting you see how often — and by which policy — requests are being blocked.
Subscribing without OpenTelemetry
You can also consume the activities directly with an ActivityListener:
using var listener = new ActivityListener
{
ShouldListenTo = source => source.Name == "BBelius.Yarp.ReverseProxy.IPFilters",
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData,
ActivityStopped = activity =>
{
var blocked = activity.GetTagItem("blocked");
// record metrics, log, etc.
}
};
ActivitySource.AddActivityListener(listener);
For a full picture, pair these traces with the middleware's log events, which record allow/block decisions with the route id, policy name, and mode.