Microsoft.ApplicationInsights.TelemetryClientExtensions
Extension class providing operation lifecycle helpers for TelemetryClient.
Enables automatic correlation of telemetry with Activity instances.
public static IOperationHolder<T> StartOperation<T>(this TelemetryClient telemetryClient, string operationName) where T : OperationTelemetry
Starts a new telemetry operation (e.g., request, dependency, etc.) with the specified name.
Creates and starts an Activity that defines the operation context.
public static IOperationHolder<T> StartOperation<T>(this TelemetryClient telemetryClient, string operationName, string operationId, string parentOperationId = null) where T : OperationTelemetry
Starts a new telemetry operation with a specific operation and parent operation ID for correlation.
public static IOperationHolder<T> StartOperation<T>(this TelemetryClient telemetryClient, T operationTelemetry) where T : OperationTelemetry
Starts a telemetry operation using an existing telemetry object.
This overload is useful when the telemetry item is pre-populated with metadata or custom properties.
public static IOperationHolder<T> StartOperation<T>(this TelemetryClient telemetryClient, Activity activity) where T : OperationTelemetry
Starts a telemetry operation based on an existing Activity instance that carries trace context.
The activity must have been created by the caller or extracted from incoming telemetry.
public static void StopOperation<T>(this TelemetryClient telemetryClient, IOperationHolder<T> operation) where T : OperationTelemetry
Stops a telemetry operation started by StartOperation<T> or its overloads.
Disposes the operation holder, stopping the associated activity and emitting telemetry.