System.Diagnostics
Namespace with 21 public types
Classes
Activity
Activity represents operation with context to be used for logging.
Activity has operation name, Id, start time and duration, tags and baggage.
Current activity can be accessed with static AsyncLocal variable Activity.Current.
Activities should be created with constructor, configured as necessary
and then started with Activity.Start method which maintains parent-child
relationships for the activities and sets Activity.Current.
When activity is finished, it should be stopped with static Activity.Stop method.
No methods on Activity allow exceptions to escape as a response to bad inputs.
They are thrown and caught (that allows Debuggers and Monitors to see the error)
but the exception is suppressed, and the operation does something reasonable (typically
doing nothing).
ActivityListener
ActivityListener allows listening to the start and stop Activity events and give the opportunity to decide creating the Activity for sampling scenarios.
ActivitySource
ActivityTagsCollection
ActivityTagsCollection is a collection class used to store tracing tags.
This collection will be used with classes like and .
This collection behaves as follows:
- The collection items will be ordered according to how they are added.
- Don't allow duplication of items with the same key.
- When using the indexer to store an item in the collection:
- If the item has a key that previously existed in the collection and the value is null, the collection item matching the key will be removed from the collection.
- If the item has a key that previously existed in the collection and the value is not null, the new item value will replace the old value stored in the collection.
- Otherwise, the item will be added to the collection.
- Add method will add a new item to the collection if an item doesn't already exist with the same key. Otherwise, it will throw an exception.
DiagnosticListener
A DiagnosticListener is something that forwards on events written with DiagnosticSource.
It is an IObservable (has Subscribe method), and it also has a Subscribe overloads that
lets you specify a 'IsEnabled' predicate that users of DiagnosticSource will use for
'quick checks'.
The item in the stream is a KeyValuePair[string, object] where the string is the name
of the diagnostic item and the object is the payload (typically an anonymous type).
There may be many DiagnosticListeners in the system, but we encourage the use of
The DiagnosticSource.DefaultSource which goes to the DiagnosticListener.DefaultListener.
If you need to see 'everything' you can subscribe to the 'AllListeners' event that
will fire for every live DiagnosticListener in the appdomain (past or present).
Please See the DiagnosticSource Users Guide
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md
for instructions on its use.
Structures
ActivityChangedEventArgs
Carries the changed event data.
ActivityContext
ActivityContext representation conforms to the w3c TraceContext specification. It contains two identifiers
a TraceId and a SpanId - along with a set of common TraceFlags and system-specific TraceState values.
ActivityCreationOptions`1
ActivityCreationOptions is encapsulating all needed information which will be sent to the ActivityListener to decide about creating the Activity object and with what state.
The possible generic type parameters is or
ActivityEvent
A text annotation associated with a collection of tags.
ActivityLink
Activity may be linked to zero or more other that are causally related.
Links can point to ActivityContexts inside a single Trace or across different Traces.
Links can be used to represent batched operations where a Activity was initiated by multiple initiating Activities,
each representing a single incoming item being processed in the batch.
ActivitySpanId
A SpanId is the format the W3C standard requires for its ID for a single span in a trace.
It represents 8 binary bytes of information, typically displayed as 16 characters
of Hexadecimal. A SpanId is a STRUCT, and does contain the 8 bytes of binary information
so there is value in passing it by reference. It does know how to convert to and
from its Hexadecimal string representation, tries to avoid changing formats until
it has to, and caches the string representation after it was created.
It is mostly useful as an exchange type.
ActivityTraceId
A TraceId is the format the W3C standard requires for its ID for the entire trace.
It represents 16 binary bytes of information, typically displayed as 32 characters
of Hexadecimal. A TraceId is a STRUCT, and does contain the 16 bytes of binary information
so there is value in passing it by reference. It does know how to convert to and
from its Hexadecimal string representation, tries to avoid changing formats until
it has to, and caches the string representation after it was created.
It is mostly useful as an exchange type.
TagList
Represents a list of tags that can be accessed by index. Provides methods to search, sort, and manipulate lists.
Enumerations
ActivityIdFormat
The possibilities for the format of the ID
ActivityKind
Kind describes the relationship between the Activity, its parents, and its children in a Trace.
--------------------------------------------------------------------------------
ActivityKind Synchronous Asynchronous Remote Incoming Remote Outgoing
--------------------------------------------------------------------------------
Internal
Client yes yes
Server yes yes
Producer yes maybe
Consumer yes maybe
--------------------------------------------------------------------------------
ActivitySamplingResult
Used by ActivityListener to indicate what amount of data should be collected for this Activity
Requesting more data causes greater performance overhead to collect it.
ActivityStatusCode
Define the status code of the Activity which indicate the status of the instrumented operation.
ActivityTraceFlags
These flags are defined by the W3C standard along with the ID for the activity.
Abstract Classes
DiagnosticSource
This is the basic API to 'hook' parts of the framework. It is like an EventSource
(which can also write object), but is intended to log complex objects that can't be serialized.
Please See the DiagnosticSource Users Guide
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md
for instructions on its use.
DistributedContextPropagator
An implementation of DistributedContextPropagator determines if and how distributed context information is encoded and decoded as it traverses the network.
The encoding can be transported over any network protocol that supports string key-value pairs. For example when using HTTP, each key value pair is an HTTP header.
DistributedContextPropagator inject values into and extracts values from carriers as string key/value pairs.