AmbientRunAttributionScope
AgentPrism.Abstractions.dllThe ambient pass-through for attributing a run that does not run inside an HTTP request to a user and a set of labels.
public static class AmbientRunAttributionScopeInheritance
Section titled “Inheritance”object ← AmbientRunAttributionScope
Inherited Members
Section titled “Inherited Members”object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”This is the exact counterpart of AmbientTenantScope. An
IRunAttributionContext implementation is a singleton and
normally resolves the user from the current request; a queued job, a
scheduled run or a direct.NET API call has no request to resolve from. The
class carries the value through the same Threading.AsyncLocal
pattern IHttpContextAccessor uses, and the built-in
DefaultRunAttributionContext reads it.
An Threading.AsyncLocal write made inside an async method
does not flow back to its caller. Open the scope in the body of the method
that actually starts the run, and keep it alive across the whole run — on a
streaming path that means the scope must still be open before every
MoveNextAsync, not only before the first one.
Both members of a scope are held in a SINGLE slot, so AmbientRunAttributionScope.Begin replaces the user and the labels together and can never be observed half-applied.
Properties
Section titled “Properties”CurrentLabels
Section titled “ CurrentLabels”Gets the ambient labels, or null when no scope is open.
public static IReadOnlyDictionary<string, string>? CurrentLabels { get; }Property Value
Section titled “Property Value”IReadOnlyDictionary<string, string>?
CurrentUserId
Section titled “ CurrentUserId”Gets the ambient user identity, or null when no scope is open.
public static string? CurrentUserId { get; }Property Value
Section titled “Property Value”IsActive
Section titled “ IsActive”Gets whether a scope is open right now.
public static bool IsActive { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Begin(string?, IReadOnlyDictionary<string, string>?)
Section titled “ Begin(string?, IReadOnlyDictionary<string, string>?)”Sets the ambient attribution for the duration of the scope.
public static IDisposable Begin(string? userId, IReadOnlyDictionary<string, string>? labels)Parameters
Section titled “Parameters”userId string?
The user identity, or null to attribute the run to no user. Whitespace is treated as null.
labels IReadOnlyDictionary<string, string>?
The labels, or null when there are none.
Returns
Section titled “Returns”An object that restores the previous value when IDisposable.Dispose is called. Nested use is safe.
Exceptions
Section titled “Exceptions”userId or labels breaks a limit on
RunLabels. The scope is REJECTED rather than trimmed:
silently trimming a label set turns a measurement into a false claim.