Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Diagnostics.​Activity

Assembly: System.Diagnostics.DiagnosticSource

Inheritance: object → Activity

Implemented Interfaces

Represents an operation with context to be used for logging.

Properties

ActivityTraceFlags
Gets or sets the flags (defined by the W3C ID specification) associated with the activity.
Gets a collection of key/value pairs that represents information that is passed to children of this <see cref="T:System.Diagnostics.Activity" /> .
public static Activity
Current
Gets or sets the current operation ( <see cref="T:System.Diagnostics.Activity" /> ) for the current thread. This flows across async calls.
public static ActivityIdFormat
DefaultIdFormat
Gets or sets the default ID format for the <see cref="T:System.Diagnostics.Activity" /> .
public TimeSpan
Duration
Gets the duration of the operation.
public static bool
ForceDefaultIdFormat
Gets or sets a value that detrmines if the <see cref="P:System.Diagnostics.Activity.DefaultIdFormat" /> is always used to define the default ID format.
public string
Id
Gets an identifier that is specific to a particular request.
public bool
HasRemoteParent
Gets a value that indicates whether the parent context was created from remote propagation.
public bool
IsAllDataRequested
Gets or sets a value that indicates whether this activity should be populated with all the propagation information, as well as all the other properties, such as links, tags, and events.
public bool
IsStopped
Gets a value that indicates whether this <see cref="T:System.Diagnostics.Activity" /> object is stopped or not.
IdFormat
Gets the format for the <see cref="P:System.Diagnostics.Activity.Id" /> .
public ActivityKind
Kind
Gets the relationship between the activity, its parents, and its children in a trace.
public string
OperationName
Gets the operation name.
public string
DisplayName
Gets or sets the display name of the activity.
Source
Gets the activity source associated with this activity.
public Activity
Parent
Gets the parent <see cref="T:System.Diagnostics.Activity" /> that created this activity.
public string
ParentId
Gets the ID of this activity's parent.
ParentSpanId
Gets the parent's <see cref="P:System.Diagnostics.Activity.SpanId" /> .
public bool
Recorded
Gets a value that indicates whether the W3CIdFlags.Recorded flag is set.
public string
RootId
Gets the root ID of this <see cref="T:System.Diagnostics.Activity" /> .
SpanId
Gets the SPAN part of the <see cref="P:System.Diagnostics.Activity.Id" /> .
public DateTime
StartTimeUtc
Gets the time when the operation started.
Status
Gets status code of the current activity object.
public string
StatusDescription
Gets the status description of the current activity object.
Gets a collection of key/value pairs that represent information that will be logged along with the <see cref="T:System.Diagnostics.Activity" /> to the logging system.
Gets the list of tags that represent information to log along with the activity. This information is not passed on to the children of this activity.
Gets the list of all the activity events attached to this activity.
Gets the list of all the activity links attached to this activity.
TraceId
Gets the TraceId part of the <see cref="P:System.Diagnostics.Activity.Id" /> .
public string
TraceStateString
Gets or sets the W3C <see langword="tracestate" /> header.
public static Func<​ActivityTraceId>
TraceIdGenerator
When starting an Activity which does not have a parent context, the Trace Id will automatically be generated using random numbers. TraceIdGenerator can be used to override the runtime's default Trace Id generation algorithm.
Context
Gets the context of the activity. Context becomes valid only if the activity has been started.

Methods

public Activity
AddBaggage​(string key, string value)
Updates the <see cref="T:System.Diagnostics.Activity" /> to have a new baggage item with the specified key and value.
Returns <see langword="this" /> for convenient chaining.
key The baggage key.
value The baggage value.
public Activity
AddEvent​(ActivityEvent e)
Adds the specified activity event to the events list.
Returns <see langword="this" /> for convenient chaining.
e The activity event to add.
public Activity
AddException​(Exception exception, TagList& tags = null, DateTimeOffset timestamp = null)
public Activity
AddLink​(ActivityLink link)
Adds an <see cref="T:System.Diagnostics.ActivityLink" /> to the <see cref="P:System.Diagnostics.Activity.Links" /> list.
Returns <see langword="this" /> for convenient chaining.
link The <see cref="T:System.Diagnostics.ActivityLink" /> to add.
public Activity
AddTag​(string key, string value)
Updates the <see cref="T:System.Diagnostics.Activity" /> to have a new tag with the provided <paramref name="key" /> and <paramref name="value" /> .
Returns <see langword="this" /> for convenient chaining.
key The tag key.
value The tag value.
public Activity
AddTag​(string key, object value)
Updates the activity to have a tag with an additional <paramref name="key" /> and <paramref name="value" /> .
Returns <see langword="this" /> for convenient chaining.
key The tag key name.
value The tag value mapped to the input key.
public Activity
SetTag​(string key, object value)
Adds or update the activity tag with the input key and value.
Returns <see langword="this" /> for convenient chaining.
key The tag key name.
value The tag value mapped to the input key.
public Activity
SetBaggage​(string key, string value)
Add or update the Activity baggage with the input key and value. If the input value is <see langword="null" /> - if the collection has any baggage with the same key, then this baggage will get removed from the collection. - otherwise, nothing will happen and the collection will not change. If the input value is not <see langword="null" /> - if the collection has any baggage with the same key, then the value mapped to this key will get updated with the new input value. - otherwise, the key and value will get added as a new baggage to the collection. Baggage item will be updated/removed only if it was originaly added to the current activity. Items inherited from the parents will not be changed/removed, new item would be added to current activity baggage instead.
Returns <see langword="this" /> for convenient chaining.
key The baggage key name
value The baggage value mapped to the input key
public string
GetBaggageItem​(string key)
Returns the value of a key-value pair added to the activity with <see cref="M:System.Diagnostics.Activity.AddBaggage(System.String,System.String)" /> .
Returns The value of the key-value-pair item if it exists, or <see langword="null" /> if it does not exist.
key The baggage key.
public object
GetTagItem​(string key)
Returns the value of the Activity tag mapped to the input key. Returns <see langword="null" /> if that key does not exist.
Returns The tag value mapped to the input key.
key The tag key string.
public Activity
SetEndTime​(DateTime endTimeUtc)
Updates the <see cref="T:System.Diagnostics.Activity" /> to set its <see cref="P:System.Diagnostics.Activity.Duration" /> as the difference between <see cref="P:System.Diagnostics.Activity.StartTimeUtc" /> and the specified stop time.
Returns <see langword="this" /> for convenient chaining.
endTimeUtc The UTC stop time.
public Activity
SetIdFormat​(ActivityIdFormat format)
Sets the ID format on this <see cref="T:System.Diagnostics.Activity" /> before it is started.
Returns <see langword="this" /> for convenient chaining.
format One of the enumeration values that specifies the format of the <see cref="P:System.Diagnostics.Activity.Id" /> property.
public Activity
SetParentId​(ActivityTraceId traceId, ActivitySpanId spanId, ActivityTraceFlags activityTraceFlags = 0)
Sets the parent ID using the W3C convention of a TraceId and a SpanId.
Returns <see langword="this" /> for convenient chaining.
traceId The parent activity's TraceId.
spanId The parent activity's SpanId.
activityTraceFlags One of the enumeration values that specifies flags defined by the W3C standard that are associated with an activity.
public Activity
SetParentId​(string parentId)
Updates this <see cref="T:System.Diagnostics.Activity" /> to indicate that the <see cref="T:System.Diagnostics.Activity" /> with an ID of <paramref name="parentId" /> caused this <see cref="T:System.Diagnostics.Activity" /> .
Returns <see langword="this" /> for convenient chaining.
parentId The ID of the parent operation.
public Activity
SetStartTime​(DateTime startTimeUtc)
Sets the start time of this <see cref="T:System.Diagnostics.Activity" /> .
Returns <see langword="this" /> for convenient chaining.
startTimeUtc The <see cref="T:System.Diagnostics.Activity" /> start time in UTC.
public Activity
SetStatus​(ActivityStatusCode code, string description = null)
Sets the status code and description on the current activity object.
Returns <see langword="this" /> for convenient chaining.
code The status code
description The error status description
public Activity
Start​()
Starts the activity.
Returns <see langword="this" /> for convenient chaining.
public void
Stop​()
Stops the activity.
public void
Dispose​()
Stops the activity if it is already started and notifies any event listeners. Nothing will happen otherwise.
protected void
Dispose​(bool disposing)
When overriden by a derived type, this method releases any allocated resources.
disposing <see langword="false" /> if the method is being called from the finalizer; <see langword="true" /> if calling from user code.
public void
SetCustomProperty​(string propertyName, object propertyValue)
Attaches any custom object to this activity. If the specified <paramref name="propertyName" /> was previously associated with another object, the property will be updated to be associated with the new <paramref name="propertyValue" /> instead. It is recommended to use a unique property name to avoid conflicts with anyone using the same value.
propertyName The name to associate the value with.
propertyValue The object to attach and map to the property name.
public object
GetCustomProperty​(string propertyName)
Returns the object mapped to the specified property name.
Returns The object mapped to the property name, if one is found; otherwise, <see langword="null" /> .
propertyName The name associated to the object.
public Enumerator<​Collections.​Generic.​KeyValuePair<​string, object>>
EnumerateTagObjects​()
Enumerates the tags attached to this Activity object.
Returns <see cref="T:System.Diagnostics.Activity.Enumerator`1" /> .
EnumerateEvents​()
Enumerates the <see cref="T:System.Diagnostics.ActivityEvent" /> objects attached to this Activity object.
Returns <see cref="T:System.Diagnostics.Activity.Enumerator`1" /> .
EnumerateLinks​()
Enumerates the <see cref="T:System.Diagnostics.ActivityLink" /> objects attached to this Activity object.
Returns <see cref="T:System.Diagnostics.Activity.Enumerator`1" /> .
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object