Class SpanAssertions
- Namespace
- TracingAssertions.TUnit
- Assembly
- TracingAssertions.TUnit.dll
TUnit-native fluent assertions over Activity spans (typically captured by SpanCapture): operation name, tag existence and value, status, and single-hop parent/child and same-trace relationships.
public static class SpanAssertions
- Inheritance
-
SpanAssertions
- Inherited Members
Remarks
Source methods carry the [GenerateAssertion] attribute; TUnit's source generator emits
the fluent Assert.That(activity).<Method>() entry point at consumer build time. The
generated chain is AOT-clean (no runtime reflection in the assertion path). Tag values are
compared by their invariant ToString() form, matching how spans carry
heterogeneously-typed tag values.
Methods
HasEvent(Activity, string)
Asserts that span carries an ActivityEvent named
name (ordinal).
[GenerateAssertion]
public static AssertionResult HasEvent(this Activity span, string name)
Parameters
Returns
- AssertionResult
A passing assertion when an event with that name is present; otherwise a failing assertion listing the event names the span carries.
Exceptions
- ArgumentNullException
spanornameis null.
HasExceptionEvent(Activity)
Asserts that span carries the OpenTelemetry exception event (an
ActivityEvent named "exception", as recorded by
AddException(Exception, in TagList, DateTimeOffset)
or an OpenTelemetry instrumentation).
[GenerateAssertion]
public static AssertionResult HasExceptionEvent(this Activity span)
Parameters
spanActivityThe captured span.
Returns
- AssertionResult
A passing assertion when an exception event is present; otherwise a failing assertion listing the event names the span carries.
Exceptions
- ArgumentNullException
spanis null.
HasKind(Activity, ActivityKind)
Asserts that span has Kind equal to
kind (for example Server for an inbound request
span or Client for an outbound call).
[GenerateAssertion]
public static AssertionResult HasKind(this Activity span, ActivityKind kind)
Parameters
spanActivityThe captured span.
kindActivityKindThe expected activity kind.
Returns
- AssertionResult
A passing assertion when the kind matches; otherwise a failing assertion naming the expected and observed kind.
Exceptions
- ArgumentNullException
spanis null.
HasOperationName(Activity, string)
Asserts that span has OperationName equal
to operationName (ordinal).
[GenerateAssertion]
public static AssertionResult HasOperationName(this Activity span, string operationName)
Parameters
spanActivityThe captured span, as the receiver of the fluent assertion.
operationNamestringThe operation name the span is expected to carry.
Returns
- AssertionResult
A passing assertion when the operation name matches; otherwise a failing assertion naming the expected and observed operation names.
Exceptions
- ArgumentNullException
spanoroperationNameis null.
HasStatus(Activity, ActivityStatusCode)
Asserts that span has Status equal to
status.
[GenerateAssertion]
public static AssertionResult HasStatus(this Activity span, ActivityStatusCode status)
Parameters
spanActivityThe captured span.
statusActivityStatusCodeThe expected status code.
Returns
- AssertionResult
A passing assertion when the status matches; otherwise a failing assertion naming the expected and observed status.
Exceptions
- ArgumentNullException
spanis null.
HasTag(Activity, string)
Asserts that span carries a tag key with a
non-null value.
[GenerateAssertion]
public static AssertionResult HasTag(this Activity span, string key)
Parameters
Returns
- AssertionResult
A passing assertion when the tag is present; otherwise a failing assertion.
Exceptions
- ArgumentNullException
spanorkeyis null.
HasTagValue(Activity, string, object)
Asserts that span carries a tag key whose value
matches value (compared by invariant ToString()).
[GenerateAssertion]
public static AssertionResult HasTagValue(this Activity span, string key, object value)
Parameters
spanActivityThe captured span.
keystringThe tag key to inspect.
valueobjectThe expected tag value.
Returns
- AssertionResult
A passing assertion when the tag value matches; otherwise a failing assertion naming the expected and observed values, or reporting the tag as absent.
Exceptions
- ArgumentNullException
span,key, orvalueis null.
IsChildOf(Activity, Activity)
Asserts that span is a direct child of parent:
its ParentSpanId equals parent's
SpanId and it shares the same TraceId.
[GenerateAssertion]
public static AssertionResult IsChildOf(this Activity span, Activity parent)
Parameters
Returns
- AssertionResult
A passing assertion when the parent/trace relationship holds; otherwise a failing assertion naming the expected and observed parent span and trace.
Exceptions
- ArgumentNullException
spanorparentis null.
IsRoot(Activity)
Asserts that span is a root span: it has no parent, so its
ParentSpanId is the default (all-zero) span id. A span created under a
propagated remote parent carries that parent's span id and is not a root.
[GenerateAssertion]
public static AssertionResult IsRoot(this Activity span)
Parameters
spanActivityThe captured span.
Returns
- AssertionResult
A passing assertion when the span is a root; otherwise a failing assertion naming the observed parent span.
Exceptions
- ArgumentNullException
spanis null.
SharesTraceWith(Activity, Activity)
Asserts that span shares the same TraceId
as other (context propagation across a boundary).
[GenerateAssertion]
public static AssertionResult SharesTraceWith(this Activity span, Activity other)
Parameters
Returns
- AssertionResult
A passing assertion when the traces match; otherwise a failing assertion naming the expected and observed trace.
Exceptions
- ArgumentNullException
spanorotheris null.