ActivityCreationOptions<T>
Encapsulates all the information that is sent to the activity listener, to make decisions about the creation of the activity instance, as well as its state.
The possible generic type parameters are ActivityContext or String.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Diagnostics
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public readonly struct ActivityCreationOptions<[System.Runtime.CompilerServices.Nullable(2)] T>
{
private readonly ActivityTagsCollection _samplerTags;
private readonly ActivityContext _context;
private readonly string _traceState;
public ActivitySource Source { get; }
public string Name { get; }
public ActivityKind Kind { get; }
public T Parent { get; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
2
})]
public IEnumerable<KeyValuePair<string, object>> Tags {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
2
})]
get;
}
[System.Runtime.CompilerServices.Nullable(2)]
public IEnumerable<ActivityLink> Links {
[System.Runtime.CompilerServices.NullableContext(2)]
get;
}
public ActivityTagsCollection SamplingTags {
get {
if (_samplerTags == null)
Unsafe.AsRef<ActivityTagsCollection>(ref _samplerTags) = new ActivityTagsCollection();
return _samplerTags;
}
}
public ActivityTraceId TraceId {
get {
if (((object)Parent) is ActivityContext && IdFormat == ActivityIdFormat.W3C && _context == default(ActivityContext)) {
ActivityTraceId traceId = Activity.TraceIdGenerator?.Invoke() ?? ActivityTraceId.CreateRandom();
Unsafe.AsRef<ActivityContext>(ref _context) = new ActivityContext(traceId, default(ActivitySpanId), ActivityTraceFlags.None, null, false);
}
return _context.TraceId;
}
}
[System.Runtime.CompilerServices.Nullable(2)]
public string TraceState {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
return _traceState;
}
[System.Runtime.CompilerServices.NullableContext(2)]
set {
_traceState = value;
}
}
internal ActivityIdFormat IdFormat { get; }
internal ActivityCreationOptions(ActivitySource source, string name, T parent, ActivityKind kind, IEnumerable<KeyValuePair<string, object>> tags, IEnumerable<ActivityLink> links, ActivityIdFormat idFormat)
{
Source = source;
Name = name;
Kind = kind;
Parent = parent;
Tags = tags;
Links = links;
IdFormat = idFormat;
if (IdFormat == ActivityIdFormat.Unknown && Activity.ForceDefaultIdFormat)
IdFormat = Activity.DefaultIdFormat;
_samplerTags = null;
_traceState = null;
if (((object)parent) is ActivityContext) {
ActivityContext activityContext = parent as ActivityContext;
if (activityContext != default(ActivityContext)) {
_context = activityContext;
if (IdFormat == ActivityIdFormat.Unknown)
IdFormat = ActivityIdFormat.W3C;
_traceState = activityContext.TraceState;
return;
}
}
string text = parent as string;
if (text != null) {
if (IdFormat != ActivityIdFormat.Hierarchical) {
if (ActivityContext.TryParse(text, null, out _context))
IdFormat = ActivityIdFormat.W3C;
if (IdFormat == ActivityIdFormat.Unknown)
IdFormat = ActivityIdFormat.Hierarchical;
} else
_context = default(ActivityContext);
} else {
_context = default(ActivityContext);
if (IdFormat == ActivityIdFormat.Unknown)
IdFormat = ((Activity.Current != null) ? Activity.Current.IdFormat : Activity.DefaultIdFormat);
}
}
internal void SetTraceState(string traceState)
{
Unsafe.AsRef<string>(ref _traceState) = traceState;
}
internal ActivityTagsCollection GetSamplingTags()
{
return _samplerTags;
}
internal ActivityContext GetContext()
{
return _context;
}
}
}