public static ITraceContext CreateChildContext([NotNull] string contextName, [NotNull] string traceId, [NotNull] string parentContextId, bool?activate = null) { if (string.IsNullOrEmpty(contextName)) { throw new InvalidOperationException("ContextName is empty"); } if (string.IsNullOrEmpty(traceId)) { throw new InvalidOperationException("TraceId is empty"); } if (string.IsNullOrEmpty(parentContextId)) { throw new InvalidOperationException("ParentContextId is empty"); } InitializeIfNeeded(); if (!configProvider.GetConfig().IsEnabled) { return(NoOpTraceContext.Instance); } var isSampled = activate ?? tracingEnvironment.TraceSampler.CanSampleTrace(); if (!isSampled) { return(NoOpTraceContext.Instance); } var childContextId = TraceIdGenerator.CreateTraceContextId(); var childContext = new RealTraceContext(traceId, childContextId, contextName, parentContextId, tracingEnvironment, isRoot: false); SetRealTraceContext(childContext); return(childContext); }
public static ITraceContext CreateChildContext([NotNull] string contextName, string contextId = null) { if (string.IsNullOrEmpty(contextName)) { throw new InvalidOperationException("ContextName is empty"); } var currentContext = TryGetRealTraceContext(); if (currentContext == null) { return(NoOpTraceContext.Instance); } InitializeIfNeeded(); if (!configProvider.GetConfig().IsEnabled) { return(NoOpTraceContext.Instance); } if (string.IsNullOrEmpty(contextId)) { contextId = TraceIdGenerator.CreateTraceContextId(); } var childContext = new RealTraceContext(currentContext.TraceId, contextId, contextName, currentContext.ContextId, tracingEnvironment, isRoot: false); SetRealTraceContext(childContext); return(childContext); }
public static ITraceContext ContinueContext([NotNull] string traceId, [NotNull] string contextId, bool isActive, bool isRoot) { if (!isActive) { return(NoOpTraceContext.Instance); } if (string.IsNullOrEmpty(traceId)) { throw new InvalidOperationException("TraceId is empty"); } if (string.IsNullOrEmpty(contextId)) { throw new InvalidOperationException("ContextId is empty"); } InitializeIfNeeded(); if (!configProvider.GetConfig().IsEnabled) { return(NoOpTraceContext.Instance); } var currentContext = new RealTraceContext(traceId, contextId, null, null, tracingEnvironment, isRoot); SetRealTraceContext(currentContext); return(currentContext); }
private static void SetRealTraceContext([CanBeNull] RealTraceContext newCurrentContext) { if (newCurrentContext == null) { CallContext.FreeNamedDataSlot(AnnotatorStorageKey); CallContext.FreeNamedDataSlot(realTraceContextStorageKey); CallContext.FreeNamedDataSlot(dTraceIdPublicStorageKey); } else { CallContext.LogicalSetData(AnnotatorStorageKey, newCurrentContext); CallContext.LogicalSetData(realTraceContextStorageKey, newCurrentContext); CallContext.LogicalSetData(dTraceIdPublicStorageKey, newCurrentContext.TraceId); } }
internal static void PopRealTraceContext([CanBeNull] RealTraceContext previousContext) { SetRealTraceContext(previousContext); }