Activity Activity Activity Activity Class


Represents an operation with context to be used for logging.

public ref class Activity
public class Activity
type Activity = class
Public Class Activity


An Activity has an operation name, an ID, a start time and duration, tags, and baggage.

The current activity can be accessed with the static Activity.Current property.

Activities should be created by calling the constructor, configured as necessary, and then started with the Start method, which maintains parent-child relationships for the activities and sets Activity.Current.

When an activity is finished, it should be stopped with the Activity.Stop() method.

No Activity methods allow exceptions to escape as a response to bad inputs. They are thrown and caught (which allows debuggers and monitors to see the error), but the exception is suppressed, and the operation does something reasonable (typically it does nothing).


Activity(String) Activity(String) Activity(String) Activity(String)

Initializes a new instance of the Activity class.


ActivityTraceFlags ActivityTraceFlags ActivityTraceFlags ActivityTraceFlags

Gets the flags (defined by the W3C ID specification) associated with the activity.

Baggage Baggage Baggage Baggage

Gets a collection of key/value pairs that represents information that is passed to children of this Activity.

Current Current Current Current

Gets or sets the current operation (Activity) for the current thread. This flows across async calls.

DefaultIdFormat DefaultIdFormat DefaultIdFormat DefaultIdFormat

Gets or sets the default ID format for the Activity.

Duration Duration Duration Duration

Gets the duration of the operation.

ForceDefaultIdFormat ForceDefaultIdFormat ForceDefaultIdFormat ForceDefaultIdFormat

Gets or sets a valud that detrmines if the DefaultIdFormat is always used to define the default ID format.

Id Id Id Id

Gets an identifier that is specific to a particular request.

IdFormat IdFormat IdFormat IdFormat

Gets the format for the Id.

OperationName OperationName OperationName OperationName

Gets the operation name.

Parent Parent Parent Parent

Gets the parent Activity that created this activity.

ParentId ParentId ParentId ParentId

Gets the ID of this activity's parent.

ParentSpanId ParentSpanId ParentSpanId ParentSpanId

Gets the parent's SpanId.

Recorded Recorded Recorded Recorded

Gets a value that indicates whether the W3CIdFlags.Recorded flag is set.

RootId RootId RootId RootId

Gets the root ID of this Activity.

SpanId SpanId SpanId SpanId

Gets the SPAN part of the Id.

StartTimeUtc StartTimeUtc StartTimeUtc StartTimeUtc

Gets the time when the operation started.

Tags Tags Tags Tags

Gets a collection of key/value pairs that represent information that will be logged along with the Activity to the logging system.

TraceId TraceId TraceId TraceId

Gets the TraceId part of the Id.

TraceStateString TraceStateString TraceStateString TraceStateString

Gets the W3C tracestate header.


AddBaggage(String, String) AddBaggage(String, String) AddBaggage(String, String) AddBaggage(String, String)

Updates the Activity to have a new baggage item with the specified key and value.

AddTag(String, String) AddTag(String, String) AddTag(String, String) AddTag(String, String)

Updates the Activity to have a new tag with the provided key and value. .

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaggageItem(String) GetBaggageItem(String) GetBaggageItem(String) GetBaggageItem(String)

Returns the value of a key-value pair added to the activity with AddBaggage(String, String).

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SetEndTime(DateTime) SetEndTime(DateTime) SetEndTime(DateTime) SetEndTime(DateTime)

Updates the Activity to set its Duration as the difference between StartTimeUtc and the specified stop time.

SetIdFormat(ActivityIdFormat) SetIdFormat(ActivityIdFormat) SetIdFormat(ActivityIdFormat) SetIdFormat(ActivityIdFormat)

Sets the ID format on this Activity before it is started.

SetParentId(ActivityTraceId, ActivitySpanId, ActivityTraceFlags) SetParentId(ActivityTraceId, ActivitySpanId, ActivityTraceFlags) SetParentId(ActivityTraceId, ActivitySpanId, ActivityTraceFlags) SetParentId(ActivityTraceId, ActivitySpanId, ActivityTraceFlags)

Sets the parent ID using the W3C convention of a TraceId and a SpanId.

SetParentId(String) SetParentId(String) SetParentId(String) SetParentId(String)

Updates this Activity to indicate that the Activity with an ID of parentId caused this Activity.

SetStartTime(DateTime) SetStartTime(DateTime) SetStartTime(DateTime) SetStartTime(DateTime)

Sets the start time of this Activity.

Start() Start() Start() Start()

Starts the activity.

Stop() Stop() Stop() Stop()

Stops the activity.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to