public void TestCleanup()
 {
     CallContextHelpers.RestoreOperationContext(null);
     while (Activity.Current != null)
     {
         Activity.Current.Stop();
     }
 }
Пример #2
0
        public void TelemetryContextIsUpdatedWithOperationNameForDependencyTelemetry()
        {
            CallContextHelpers.SaveOperationContext(new OperationContextForCallContext {
                RootOperationName = "OperationName"
            });
            var telemetry = new DependencyTelemetry();

            (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
            Assert.AreEqual(telemetry.Context.Operation.Name, "OperationName");
            CallContextHelpers.RestoreOperationContext(null);
        }
Пример #3
0
        public void TelemetryContextIsUpdatedWithOperationIdForDependencyTelemetry()
        {
            CallContextHelpers.SaveOperationContext(new OperationContextForCallContext {
                ParentOperationId = "ParentOperationId"
            });
            var telemetry = new DependencyTelemetry();

            (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
            Assert.AreEqual("ParentOperationId", telemetry.Context.Operation.ParentId);
            CallContextHelpers.RestoreOperationContext(null);
        }
Пример #4
0
        public void InitializeDoesNotUpdateOperationNameIfItExists()
        {
            CallContextHelpers.SaveOperationContext(new OperationContextForCallContext {
                RootOperationName = "OperationName"
            });
            var telemetry = new DependencyTelemetry();

            telemetry.Context.Operation.Name = "OldOperationName";
            (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
            Assert.AreEqual(telemetry.Context.Operation.Name, "OldOperationName");
            CallContextHelpers.RestoreOperationContext(null);
        }
Пример #5
0
        public void InitializeDoesNotUpdateOperationIdIfItExists()
        {
            CallContextHelpers.SaveOperationContext(new OperationContextForCallContext {
                ParentOperationId = "ParentOperationId"
            });
            var telemetry = new DependencyTelemetry();

            telemetry.Context.Operation.ParentId = "OldParentOperationId";
            (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
            Assert.AreEqual("OldParentOperationId", telemetry.Context.Operation.ParentId);
            CallContextHelpers.RestoreOperationContext(null);
        }
        public void TestInitialize()
        {
            var configuration = new TelemetryConfiguration();

            this.sendItems = new List <ITelemetry>();
            configuration.TelemetryChannel = new StubTelemetryChannel {
                OnSend = item => this.sendItems.Add(item)
            };
            configuration.InstrumentationKey = Guid.NewGuid().ToString();
            configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            this.telemetryClient = new TelemetryClient(configuration);
            CallContextHelpers.RestoreOperationContext(null);
        }
        public void TestInitialize()
        {
            var configuration = new TelemetryConfiguration();

            this.sendItems = new ConcurrentQueue <ITelemetry>();
            configuration.TelemetryChannel = new StubTelemetryChannel {
                OnSend = item => this.sendItems.Enqueue(item)
            };
            configuration.InstrumentationKey = Guid.NewGuid().ToString();
            configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            this.telemetryClient = new TelemetryClient(configuration);
            CallContextHelpers.RestoreOperationContext(null);

            ActivityFormatHelper.EnableW3CFormatInActivity();
        }
Пример #8
0
        public void InitializeWithCorrelationContextSetsProperties()
        {
            CallContextHelpers.SaveOperationContext(new OperationContextForCallContext
            {
                CorrelationContext = new Dictionary <string, string> {
                    ["k1"] = "v1", ["k2"] = "v2"
                }
            });

            var telemetry = new DependencyTelemetry();

            (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);

            Assert.AreEqual(2, telemetry.Context.Properties.Count);
            Assert.AreEqual("v1", telemetry.Context.Properties["k1"]);
            Assert.AreEqual("v2", telemetry.Context.Properties["k2"]);
            CallContextHelpers.RestoreOperationContext(null);
        }