Class ActivityExtensions
- Namespace
- Excalibur.Dispatch.Extensions
- Assembly
- Excalibur.Dispatch.dll
Extension methods for Activity to provide enhanced tracing capabilities.
public static class ActivityExtensions
- Inheritance
-
ActivityExtensions
- Inherited Members
Methods
GetSanitizedErrorDescription(Exception, ITelemetrySanitizer)
Gets a sanitized error description for an exception suitable for span status and tags.
public static string GetSanitizedErrorDescription(this Exception exception, ITelemetrySanitizer sanitizer)
Parameters
exceptionExceptionThe exception to get a description for.
sanitizerITelemetrySanitizerThe telemetry sanitizer for PII protection.
Returns
- string
A sanitized error description safe for telemetry emission.
Remarks
For well-known system exceptions (SystemException, OperationCanceledException, TimeoutException), only the type name is returned since these never contain PII.
For all other exceptions, the message is sanitized using the provided sanitizer.
RecordException(Activity?, Exception)
Records an exception as an event on the activity with standardized exception details.
public static void RecordException(this Activity? activity, Exception exception)
Parameters
activityActivityThe activity to record the exception on.
exceptionExceptionThe exception to record.
Remarks
This method adds an event to the activity with the exception details, including the exception type, message, and stack trace. It also sets the activity status to Error if not already set. This provides compatibility with OpenTelemetry's RecordException extension method when OpenTelemetry is not directly referenced.
RecordException(Activity?, Exception, IDictionary<string, object?>)
Records an exception as an event on the activity with additional custom tags.
public static void RecordException(this Activity? activity, Exception exception, IDictionary<string, object?> additionalTags)
Parameters
activityActivityThe activity to record the exception on.
exceptionExceptionThe exception to record.
additionalTagsIDictionary<string, object>Additional tags to include with the exception event.
RecordSanitizedException(Activity?, Exception, ITelemetrySanitizer)
Records an exception as an event on the activity with sanitized exception details.
public static void RecordSanitizedException(this Activity? activity, Exception exception, ITelemetrySanitizer sanitizer)
Parameters
activityActivityThe activity to record the exception on.
exceptionExceptionThe exception to record.
sanitizerITelemetrySanitizerThe telemetry sanitizer for PII protection.
SetSanitizedErrorStatus(Activity?, Exception, ITelemetrySanitizer)
Sets the activity status to Error with a sanitized exception description and records the exception event.
public static void SetSanitizedErrorStatus(this Activity? activity, Exception exception, ITelemetrySanitizer sanitizer)
Parameters
activityActivityThe activity to set error status on.
exceptionExceptionThe exception to record.
sanitizerITelemetrySanitizerThe telemetry sanitizer for PII protection.
Remarks
This combines RecordSanitizedException(Activity?, Exception, ITelemetrySanitizer) and status-setting into a single call. The exception message in the span status and event tags is sanitized to prevent PII leakage.