private Task <TResult> OperationHelperWithRootTraceWithSynchronizationContextAsync <TResult>(
            string operationName,
            RequestOptions requestOptions,
            Func <ITrace, Task <TResult> > task,
            TraceComponent traceComponent,
            Tracing.TraceLevel traceLevel)
        {
            Debug.Assert(SynchronizationContext.Current != null, "This should only be used when a SynchronizationContext is specified");

            string syncContextVirtualAddress = SynchronizationContext.Current.ToString();

            // Used on NETFX applications with SynchronizationContext when doing locking calls
            return(Task.Run(async() =>
            {
                bool disableDiagnostics = requestOptions != null && requestOptions.DisablePointOperationDiagnostics;

                using (ITrace trace = disableDiagnostics ? NoOpTrace.Singleton : (ITrace)Tracing.Trace.GetRootTrace(operationName, traceComponent, traceLevel))
                {
                    trace.AddDatum("Synchronization Context", syncContextVirtualAddress);

                    return await this.RunWithDiagnosticsHelperAsync(
                        trace,
                        task);
                }
            }));
        }
Пример #2
0
        public static void Trace(TraceComponent component, string log)
        {
            // Check the global environment variable named "DEBUGGING_ENABLED" to see if it's set.
            string env = Environment.GetEnvironmentVariable("DEBUGGING_ENABLED");
            bool   isDebuggingEnabled = env == "y" || env == "true" || env == "yes";

            if (!isDebuggingEnabled)
            {
                // Trace disabled globally.
                return;
            }

            // Trace components can be individually enabled or disabled.
            // Based on the capitalized enumeration name, check to see if that environment variable is enabled.
            // If the trace isn't attached to a specific component, it'll be displayed every time (so long as the global setting is on)
            bool componentEnabled = true;

            if (component != TraceComponent.None)
            {
                string componentName = Enum.GetName(typeof(TraceComponent), component)?.ToUpper();
                env = Environment.GetEnvironmentVariable("DEBUGGING_COMPONENT_ENABLED_" + componentName);
                componentEnabled = env == "y" || env == "true" || env == "yes";
            }

            // If the component is enabled, output the trace.
            if (componentEnabled)
            {
                string componentName = component == TraceComponent.None ? string.Empty : component.ToString();
                Console.WriteLine(componentName + " -- " + log);
            }
        }
 internal abstract Task <TResult> OperationHelperAsync <TResult>(
     string operationName,
     RequestOptions requestOptions,
     Func <ITrace, Task <TResult> > task,
     Func <TResult, OpenTelemetryAttributes> openTelemetry = null,
     TraceComponent traceComponent = TraceComponent.Transport,
     TraceLevel traceLevel         = TraceLevel.Info);
Пример #4
0
            public ITrace StartChild(string name, TraceComponent component, TraceLevel level)
            {
                ITrace child = Trace.GetRootTrace(name, component, level);

                this.AddChild(child);
                return(child);
            }
Пример #5
0
            public ITrace StartChild(string name, TraceComponent component, TraceLevel level, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
            {
                ITrace child = Trace.GetRootTrace(name, component, level, memberName, sourceFilePath, sourceLineNumber);

                this.AddChild(child);
                return(child);
            }
Пример #6
0
 public ITrace StartChild(
     string name,
     TraceComponent component,
     TraceLevel level,
     string memberName     = "",
     string sourceFilePath = "",
     int sourceLineNumber  = 0)
 {
     return(this);
 }
Пример #7
0
 protected override void Awake()
 {
     base.Awake();
     _tracer = GetComponent <TraceComponent>();
     if (_tracer == null)
     {
         Debug.LogError("Could not find tracer.");
         enabled = false;
         return;
     }
     _tracer.TraceHit += OnTraceHit;
 }
Пример #8
0
 public static Trace GetRootTrace(
     string name,
     TraceComponent component,
     TraceLevel level,
     [CallerMemberName] string memberName    = "",
     [CallerFilePath] string sourceFilePath  = "",
     [CallerLineNumber] int sourceLineNumber = 0)
 {
     return(new Trace(
                name: name,
                callerInfo: new CallerInfo(memberName, sourceFilePath, sourceLineNumber),
                level: level,
                component: component,
                parent: null));
 }
        private async Task <TResult> OperationHelperWithRootTraceAsync <TResult>(
            string operationName,
            RequestOptions requestOptions,
            Func <ITrace, Task <TResult> > task,
            TraceComponent traceComponent,
            Tracing.TraceLevel traceLevel)
        {
            bool disableDiagnostics = requestOptions != null && requestOptions.DisablePointOperationDiagnostics;

            using (ITrace trace = disableDiagnostics ? NoOpTrace.Singleton : (ITrace)Tracing.Trace.GetRootTrace(operationName, traceComponent, traceLevel))
            {
                return(await this.RunWithDiagnosticsHelperAsync(
                           trace,
                           task));
            }
        }
Пример #10
0
        public ITrace StartChild(
            string name,
            TraceComponent component,
            TraceLevel level,
            [CallerMemberName] string memberName    = "",
            [CallerFilePath] string sourceFilePath  = "",
            [CallerLineNumber] int sourceLineNumber = 0)
        {
            Trace child = new Trace(
                name: name,
                callerInfo: new CallerInfo(memberName, sourceFilePath, sourceLineNumber),
                level: level,
                component: component,
                parent: this);

            this.children.Add(child);
            return(child);
        }
Пример #11
0
 private Trace(
     string name,
     CallerInfo callerInfo,
     TraceLevel level,
     TraceComponent component,
     Trace parent)
 {
     this.Name       = name ?? throw new ArgumentNullException(nameof(name));
     this.Id         = Guid.NewGuid();
     this.CallerInfo = callerInfo;
     this.StartTime  = DateTime.UtcNow;
     this.stopwatch  = Stopwatch.StartNew();
     this.Level      = level;
     this.Component  = component;
     this.Parent     = parent;
     this.children   = new List <Trace>();
     this.data       = new Dictionary <string, object>();
 }
 internal override Task <TResult> OperationHelperAsync <TResult>(
     string operationName,
     RequestOptions requestOptions,
     Func <ITrace, Task <TResult> > task,
     TraceComponent traceComponent = TraceComponent.Transport,
     Tracing.TraceLevel traceLevel = Tracing.TraceLevel.Info)
 {
     return(SynchronizationContext.Current == null?
            this.OperationHelperWithRootTraceAsync(operationName,
                                                   requestOptions,
                                                   task,
                                                   traceComponent,
                                                   traceLevel) :
                this.OperationHelperWithRootTraceWithSynchronizationContextAsync(operationName,
                                                                                 requestOptions,
                                                                                 task,
                                                                                 traceComponent,
                                                                                 traceLevel));
 }
Пример #13
0
        private async Task <TResult> OperationHelperWithRootTraceAsync <TResult>(
            string operationName,
            RequestOptions requestOptions,
            Func <ITrace, Task <TResult> > task,
            Func <TResult, OpenTelemetryAttributes> openTelemetry,
            TraceComponent traceComponent,
            Tracing.TraceLevel traceLevel)
        {
            bool disableDiagnostics = requestOptions != null && requestOptions.DisablePointOperationDiagnostics;

            using (ITrace trace = disableDiagnostics ? NoOpTrace.Singleton : (ITrace)Tracing.Trace.GetRootTrace(operationName, traceComponent, traceLevel))
            {
                trace.AddDatum("Client Configuration", this.client.ClientConfigurationTraceDatum);

                return(await this.RunWithDiagnosticsHelperAsync(
                           trace,
                           task,
                           openTelemetry,
                           operationName));
            }
        }
Пример #14
0
 public Tracer(TraceComponent component)
 {
     _componentName = component.ToString();
 }