Beispiel #1
0
        public void InitializePopulatesOperationContextFromActivityWhenW3CIsDisabled()
        {
            // Arrange
            ActivityFormatHelper.DisableW3CFormatInActivity();
            try
            {
                Activity parent = new Activity("parent");

                // Setting parentid like this forces Activity to use Hierarchical ID Format
                parent.SetParentId("parent");
                parent.Start();

                var telemetry   = new DependencyTelemetry();
                var initializer = new OperationCorrelationTelemetryInitializer();

                // Act
                initializer.Initialize(telemetry);

                // Validate
                Assert.AreEqual("parent", telemetry.Context.Operation.Id);
                Assert.AreEqual(parent.Id, telemetry.Context.Operation.ParentId);
                parent.Stop();
            }
            finally
            {
                ActivityFormatHelper.EnableW3CFormatInActivity();
            }
        }
Beispiel #2
0
        public void InitializeDoesNotOverrideEmptyParentIdIfOperationIdExists()
        {
            // Arrange
            var telemetry = new DependencyTelemetry();

            telemetry.Context.Operation.Id = "OldOperationId";
            // Does not set parentid and hence it'll be empty
            var      initializer = new OperationCorrelationTelemetryInitializer();
            Activity parent      = new Activity("parent");

            parent.Start();

            initializer.Initialize(telemetry);

            Assert.IsNull(telemetry.Context.Operation.ParentId, "Operation.ParentID should not be overwritten when Operation.ID is already present");
            Assert.AreEqual("OldOperationId", telemetry.Context.Operation.Id, "Operation should not be overwritten");
            parent.Stop();
        }
Beispiel #3
0
        public void InitializeDoesNotOverrideOperationIdIfItExists()
        {
            // Arrange
            var telemetry = new DependencyTelemetry();

            telemetry.Context.Operation.ParentId = "OldParentOperationId";
            telemetry.Context.Operation.Id       = "OldOperationId";
            var      initializer = new OperationCorrelationTelemetryInitializer();
            Activity parent      = new Activity("parent");

            parent.Start();

            // Act
            initializer.Initialize(telemetry);

            // Validate
            Assert.AreEqual("OldParentOperationId", telemetry.Context.Operation.ParentId);
            Assert.AreEqual("OldOperationId", telemetry.Context.Operation.Id);
            parent.Stop();
        }
Beispiel #4
0
        public void InitializePopulatesOperationContextFromActivity()
        {
            // Arrange
            Activity activity = new Activity("somename");

            activity.Start();
            var telemetry           = new DependencyTelemetry();
            var originalTelemetryId = telemetry.Id;

            // Act
            var initializer = new OperationCorrelationTelemetryInitializer();

            initializer.Initialize(telemetry);

            // Validate
            Assert.AreEqual(activity.TraceId.ToHexString(), telemetry.Context.Operation.Id, "OperationCorrelationTelemetryInitializer is expected to populate OperationID from Activity");
            Assert.AreEqual(activity.SpanId.ToHexString(), telemetry.Context.Operation.ParentId,
                            "OperationCorrelationTelemetryInitializer is expected to populate Operation ParentID as |traceID.SpanId. from Activity");
            Assert.AreEqual(originalTelemetryId, telemetry.Id, "OperationCorrelationTelemetryInitializer is not expected to modify Telemetry ID");
            activity.Stop();
        }