Class TelemetryMiddleware
A middleware that starts an Activity per request, following OpenTelemetry conventions. The middleware restores the parent invocation activity from the request TraceContext field before starting the dispatch activity.
public class TelemetryMiddleware : IDispatcher
- Inheritance
-
TelemetryMiddleware
- Implements
- Inherited Members
Remarks
The middleware creates an activity only for a request that uses the icerpc protocol. The name of this
activity is {path}/{operation}, and its tags are:
<ul><li><code>rpc.system.name</code>: <code>icerpc</code>.</li><li><code>rpc.method</code>: the operation name.</li><li><code>icerpc.path</code>: the path carried by the request.</li><li><code>rpc.status_code</code>: the status code sent to the caller.</li><li><code>error.type</code>: a status code that reports a server failure.</li><li><code>network.peer.address</code> and <code>network.peer.port</code>: the IP address and the port of the
client.</li><li><code>icerpc.canceled</code>: <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> when the dispatch was canceled.
</li></ul>
An activity with an <code>error.type</code> tag has the <xref href="System.Diagnostics.ActivityStatusCode.Error" data-throw-if-not-resolved="false"></xref> status; the status of any
other activity is unset. The <xref href="IceRpc.StatusCode.ApplicationError" data-throw-if-not-resolved="false"></xref>, <xref href="IceRpc.StatusCode.NotFound" data-throw-if-not-resolved="false"></xref>,
<xref href="IceRpc.StatusCode.InvalidData" data-throw-if-not-resolved="false"></xref>, <xref href="IceRpc.StatusCode.TruncatedPayload" data-throw-if-not-resolved="false"></xref> and
<xref href="IceRpc.StatusCode.Unauthorized" data-throw-if-not-resolved="false"></xref> status codes report a problem with the request, not a server failure.
Constructors
TelemetryMiddleware(IDispatcher, ActivitySource)
Constructs a telemetry middleware.
public TelemetryMiddleware(IDispatcher next, ActivitySource activitySource)
Parameters
nextIDispatcherThe next dispatcher in the dispatch pipeline.
activitySourceActivitySourceThe ActivitySource is used to start the request activity.
Methods
DispatchAsync(IncomingRequest, CancellationToken)
Dispatches an incoming request and returns the corresponding outgoing response.
public ValueTask<OutgoingResponse> DispatchAsync(IncomingRequest request, CancellationToken cancellationToken)
Parameters
requestIncomingRequestThe incoming request being dispatched.
cancellationTokenCancellationTokenA cancellation token that receives the cancellation requests.
Returns
- ValueTask<OutgoingResponse>
The outgoing response.