Ejemplo n.º 1
0
        public void InitializeDoesNotAddSourceFieldForRequestForSameComponent()
        {
            // ARRANGE
            string instrumentationKey = "b3eb14d6-bb32-4542-9b93-473cd94aaedf";

            // Here is the equivalent generated IKey Hash
            string hashedIkey = "o05HMrc4Og8W1Jyy60JPDPxxQy3bOKyuaj6HudZHTjE=";

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add(RequestResponseHeaders.SourceInstrumentationKeyHeader, hashedIkey);

            var source           = new TestableOperationCorrelationTelemetryInitializer(headers);
            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            requestTelemetry.Context.InstrumentationKey = instrumentationKey;

            // ACT
            source.Initialize(requestTelemetry);

            // VALIDATE
            if (!string.IsNullOrEmpty(requestTelemetry.Source))
            {
                Assert.Fail("OperationCorrelationTelemetryInitializer should not set source for same ikey as itself.");
            }
        }
        public void OperationContextIsSetForNonRequestTelemetry()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(new Dictionary <string, string>
            {
                ["Request-Id"]          = "|guid.1",
                ["Correlation-Context"] = "k1=v1,k2=v2,k1=v3"
            });

            // simulate OnBegin behavior:
            // create telemetry and start activity for children
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            // lost Acitivity / call context
            ActivityHelpers.CleanOperationContext();

            var exceptionTelemetry = new ExceptionTelemetry();

            source.Initialize(exceptionTelemetry);

            Assert.AreEqual(requestTelemetry.Context.Operation.Id, exceptionTelemetry.Context.Operation.Id);
            Assert.AreEqual(requestTelemetry.Id, exceptionTelemetry.Context.Operation.ParentId);

            Assert.AreEqual(2, exceptionTelemetry.Context.Properties.Count);

            // undefined behavior for duplicates
            Assert.IsTrue(exceptionTelemetry.Context.Properties["k1"] == "v3" || exceptionTelemetry.Context.Properties["k1"] == "v1");
            Assert.AreEqual("v2", exceptionTelemetry.Context.Properties["k2"]);
        }
Ejemplo n.º 3
0
        public void OperationContextIsSetForNonRequestTelemetry()
        {
            var activity = new Activity("request")
                           .SetParentId("|guid.1")
                           .AddBaggage("k1", "v1")
                           .AddBaggage("k2", "v2")
                           .AddBaggage("k1", "v3")
                           .Start();

            var source = new TestableOperationCorrelationTelemetryInitializer();

            // simulate OnBegin behavior:
            // create telemetry and start activity for children
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            // lost Acitivity / call context
            activity.Stop();

            var exceptionTelemetry = new ExceptionTelemetry();

            source.Initialize(exceptionTelemetry);

            Assert.AreEqual(requestTelemetry.Context.Operation.Id, exceptionTelemetry.Context.Operation.Id);
            Assert.AreEqual(requestTelemetry.Id, exceptionTelemetry.Context.Operation.ParentId);

            Assert.AreEqual(2, exceptionTelemetry.Context.Properties.Count);

            // undefined behavior for duplicates
            Assert.IsTrue(exceptionTelemetry.Context.Properties["k1"] == "v3" || exceptionTelemetry.Context.Properties["k1"] == "v1");
            Assert.AreEqual("v2", exceptionTelemetry.Context.Properties["k2"]);
        }
Ejemplo n.º 4
0
        public void InitializeDoNotMakeRequestAParentOfItself()
        {
            var source           = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            source.Initialize(requestTelemetry);
            Assert.AreEqual(null, requestTelemetry.Context.Operation.ParentId);
            Assert.AreEqual(requestTelemetry.Id, requestTelemetry.Context.Operation.Id);
        }
        public void InitializeSetsParentIdForTelemetryUsingIdFromRequestTelemetry()
        {
            var exceptionTelemetry = new ExceptionTelemetry();
            var source = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            source.Initialize(exceptionTelemetry);

            Assert.AreEqual(requestTelemetry.Id, exceptionTelemetry.Context.Operation.ParentId);
        }
Ejemplo n.º 6
0
        public void InitializeSetsParentIdForTelemetryUsingIdFromRequestTelemetry()
        {
            var exceptionTelemetry = new ExceptionTelemetry();
            var source             = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry   = source.FakeContext.CreateRequestTelemetryPrivate();

            source.Initialize(exceptionTelemetry);

            Assert.AreEqual(requestTelemetry.Id, exceptionTelemetry.Context.Operation.ParentId);
        }
Ejemplo n.º 7
0
        public void InitializeSetsRequestTelemetryRootOperaitonIdToOepraitonId()
        {
            var source           = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            var customerTelemetry = new TraceTelemetry("Text");

            source.Initialize(customerTelemetry);

            Assert.AreEqual(requestTelemetry.Id, requestTelemetry.Context.Operation.Id);
        }
        public void InitializeSetsRequestTelemetryRootOperaitonIdToOepraitonId()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            var customerTelemetry = new TraceTelemetry("Text");

            source.Initialize(customerTelemetry);

            Assert.AreEqual(requestTelemetry.Id, requestTelemetry.Context.Operation.Id);
        }
        public void InitializeDoesNotOverrideCustomerParentOperationId()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(null);

            var customerTelemetry = new TraceTelemetry("Text");
            customerTelemetry.Context.Operation.ParentId = "CustomId";

            source.Initialize(customerTelemetry);

            Assert.AreEqual("CustomId", customerTelemetry.Context.Operation.ParentId);
        }
Ejemplo n.º 10
0
        public void InitializeDoesNotOverrideCustomerParentOperationId()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(null);

            var customerTelemetry = new TraceTelemetry("Text");

            customerTelemetry.Context.Operation.ParentId = "CustomId";

            source.Initialize(customerTelemetry);

            Assert.AreEqual("CustomId", customerTelemetry.Context.Operation.ParentId);
        }
        public void InitializeDoesNotOverrideCustomerRootOperationId()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();
            requestTelemetry.Context.Operation.Id = "RootId";

            var customerTelemetry = new TraceTelemetry("Text");
            customerTelemetry.Context.Operation.Id = "CustomId";

            source.Initialize(customerTelemetry);

            Assert.AreEqual("CustomId", customerTelemetry.Context.Operation.Id);
        }
Ejemplo n.º 12
0
        public void InitializeDoesNotOverrideCustomerRootOperationId()
        {
            var source           = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            requestTelemetry.Context.Operation.Id = "RootId";

            var customerTelemetry = new TraceTelemetry("Text");

            customerTelemetry.Context.Operation.Id = "CustomId";

            source.Initialize(customerTelemetry);

            Assert.AreEqual("CustomId", customerTelemetry.Context.Operation.Id);
        }
Ejemplo n.º 13
0
        public void InitializeReadsParentIdFromCustomHeader()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(new Dictionary <string, string>()
            {
                { "headerName", "ParentId" }
            });

            source.ParentOperationIdHeaderName = "headerName";

            var customerTelemetry = new TraceTelemetry("Text");

            source.Initialize(customerTelemetry);

            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            Assert.AreEqual("ParentId", requestTelemetry.Context.Operation.ParentId);
        }
Ejemplo n.º 14
0
        public void InitializeAddsSourceFieldForRequestWithSourceIkey()
        {
            // ARRANGE
            string hashedIkey = "vwuSMCFBLdIHSdeEXvFnmiXPO5ilQRqw9kO/SE5ino4=";

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add(RequestResponseHeaders.SourceInstrumentationKeyHeader, hashedIkey);

            var source           = new TestableOperationCorrelationTelemetryInitializer(headers);
            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            requestTelemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();

            // ACT
            source.Initialize(requestTelemetry);

            // VALIDATE
            Assert.AreEqual(hashedIkey, requestTelemetry.Source);
        }
Ejemplo n.º 15
0
        public void InitializeDoesNotAddSourceFieldForRequestWithOutSourceIkeyHeader()
        {
            // ARRANGE
            // do not add any sourceikey header.
            Dictionary <string, string> headers = new Dictionary <string, string>();

            var source           = new TestableOperationCorrelationTelemetryInitializer(headers);
            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            requestTelemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();

            // ACT
            source.Initialize(requestTelemetry);

            // VALIDATE
            if (!string.IsNullOrEmpty(requestTelemetry.Source))
            {
                Assert.Fail("OperationCorrelationTelemetryInitializer should not set source if not sourceikey found in header");
            }
        }
        public void OperationContextIsNotUpdatedIfOperationIdIsSet()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(new Dictionary <string, string>
            {
                ["Request-Id"]          = "|guid.1",
                ["Correaltion-Context"] = "k1=v1"
            });

            // create telemetry and immediately clean call context/activity
            source.FakeContext.CreateRequestTelemetryPrivate();
            ActivityHelpers.CleanOperationContext();

            var exceptionTelemetry = new ExceptionTelemetry();

            exceptionTelemetry.Context.Operation.Id = "guid";
            source.Initialize(exceptionTelemetry);

            Assert.IsNull(exceptionTelemetry.Context.Operation.ParentId);

            Assert.AreEqual(0, exceptionTelemetry.Context.Properties.Count);
        }
Ejemplo n.º 17
0
        public void InitializeDoesNotOverrideSourceField()
        {
            // ARRANGE
            string hashedIkeyInHeader    = "o05HMrc4Og8W1Jyy60JPDPxxQy3bOKyuaj6HudZHTjE=";
            string hashedIkeySetInSource = "vwuSMCFBLdIHSdeEXvFnmiXPO5ilQRqw9kO=";

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add(RequestResponseHeaders.SourceInstrumentationKeyHeader, hashedIkeyInHeader);

            var source           = new TestableOperationCorrelationTelemetryInitializer(headers);
            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            requestTelemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();
            requestTelemetry.Source = hashedIkeySetInSource;

            // ACT
            source.Initialize(requestTelemetry);

            // VALIDATE
            Assert.AreEqual(hashedIkeySetInSource, requestTelemetry.Source);
        }
Ejemplo n.º 18
0
        public void OperationContextIsNotUpdatedIfOperationIdIsSet()
        {
            var activity = new Activity("request")
                           .SetParentId("|guid.1")
                           .AddBaggage("k1", "v1")
                           .Start();

            var source = new TestableOperationCorrelationTelemetryInitializer();

            // create telemetry and immediately clean call context/activity
            source.FakeContext.CreateRequestTelemetryPrivate();

            activity.Stop();

            var exceptionTelemetry = new ExceptionTelemetry();

            exceptionTelemetry.Context.Operation.Id = "guid";
            source.Initialize(exceptionTelemetry);

            Assert.IsNull(exceptionTelemetry.Context.Operation.ParentId);

            Assert.AreEqual(0, exceptionTelemetry.Context.Properties.Count);
        }
        public void InitializeDoNotMakeRequestAParentOfItself()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(null);
            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();

            source.Initialize(requestTelemetry);
            Assert.AreEqual(null, requestTelemetry.Context.Operation.ParentId);
            Assert.AreEqual(requestTelemetry.Id, requestTelemetry.Context.Operation.Id);
        }
        public void InitializeReadsParentIdFromCustomHeader()
        {
            var source = new TestableOperationCorrelationTelemetryInitializer(new Dictionary<string, string>() { { "headerName", "ParentId" } });
            source.ParentOperationIdHeaderName = "headerName";

            var customerTelemetry = new TraceTelemetry("Text");

            source.Initialize(customerTelemetry);

            var requestTelemetry = source.FakeContext.ReadOrCreateRequestTelemetryPrivate();
            Assert.AreEqual("ParentId", requestTelemetry.Context.Operation.ParentId);
        }