public TraceListener(ActivityTraceListenerManager parent, ActivityTraceId traceId) { Parent = parent; TraceId = traceId; _CompletedActivities = new List <Activity>(); }
public System.Diagnostics.Activity SetParentId(System.Diagnostics.ActivityTraceId traceId, System.Diagnostics.ActivitySpanId spanId, System.Diagnostics.ActivityTraceFlags activityTraceFlags = System.Diagnostics.ActivityTraceFlags.None) { throw null; }
private Activity?StartActivity(string name, ActivityKind kind, ActivityContext context, string?parentId, IEnumerable <KeyValuePair <string, object?> >?tags, IEnumerable <ActivityLink>?links, DateTimeOffset startTime) { // _listeners can get assigned to null in Dispose. SynchronizedList <ActivityListener>?listeners = _listeners; if (listeners == null || listeners.Count == 0) { return(null); } Activity?activity = null; ActivityDataRequest dataRequest = ActivityDataRequest.None; bool?useContext = default; ActivityCreationOptions <ActivityContext> optionsWithContext = default; if (parentId != null) { var aco = new ActivityCreationOptions <string>(this, name, parentId, kind, tags, links); listeners.EnumWithFunc((ActivityListener listener, ref ActivityCreationOptions <string> data, ref ActivityDataRequest request, ref bool?canUseContext, ref ActivityCreationOptions <ActivityContext> dataWithContext) => { GetRequestedData <string>?getRequestedDataUsingParentId = listener.GetRequestedDataUsingParentId; if (getRequestedDataUsingParentId != null) { ActivityDataRequest dr = getRequestedDataUsingParentId(ref data); if (dr > request) { request = dr; } // Stop the enumeration if we get the max value RecordingAndSampling. return(request != ActivityDataRequest.AllDataAndRecorded); } else { // In case we have a parent Id and the listener not providing the GetRequestedDataUsingParentId, we'll try to find out if the following conditions are true: // - The listener is providing the GetRequestedDataUsingContext callback // - Can convert the parent Id to a Context // Then we can call the listener GetRequestedDataUsingContext callback with the constructed context. GetRequestedData <ActivityContext>?getRequestedDataUsingContext = listener.GetRequestedDataUsingContext; if (getRequestedDataUsingContext != null) { if (!canUseContext.HasValue) { canUseContext = Activity.TryConvertIdToContext(parentId, out ActivityContext ctx); if (canUseContext.Value) { dataWithContext = new ActivityCreationOptions <ActivityContext>(data.Source, data.Name, ctx, data.Kind, data.Tags, data.Links); } } if (canUseContext.Value) { ActivityDataRequest dr = getRequestedDataUsingContext(ref dataWithContext); if (dr > request) { request = dr; } // Stop the enumeration if we get the max value RecordingAndSampling. return(request != ActivityDataRequest.AllDataAndRecorded); } } } return(true); }, ref aco, ref dataRequest, ref useContext, ref optionsWithContext); } else { ActivityContext initializedContext = context == default && Activity.Current != null ? Activity.Current.Context : context; optionsWithContext = new ActivityCreationOptions <ActivityContext>(this, name, initializedContext, kind, tags, links); listeners.EnumWithFunc((ActivityListener listener, ref ActivityCreationOptions <ActivityContext> data, ref ActivityDataRequest request, ref bool?canUseContext, ref ActivityCreationOptions <ActivityContext> dataWithContext) => { GetRequestedData <ActivityContext>?getRequestedDataUsingContext = listener.GetRequestedDataUsingContext; if (getRequestedDataUsingContext != null) { if (listener.AutoGenerateRootContextTraceId && !canUseContext.HasValue && data.Parent == default) { ActivityContext ctx = new ActivityContext(ActivityTraceId.CreateRandom(), default, default);