Exemplo n.º 1
0
        public void TestHttpRequestsWithQueryStringAreCollected()
        {
            ITelemetry sentTelemetry = null;
            var        channel       = new StubTelemetryChannel {
                OnSend = telemetry => sentTelemetry = telemetry
            };
            var config = new TelemetryConfiguration
            {
                InstrumentationKey = IKey,
                TelemetryChannel   = channel
            };

            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.Initialize(config);
                const string Url = "http://www.bing.com/search?q=1";
                new HttpWebRequestUtils().ExecuteAsyncHttpRequest(Url, HttpMethod.Get);

                while (sentTelemetry == null)
                {
                    Thread.Sleep(100);
                }

                Assert.IsNotNull(sentTelemetry, "Get requests are not monitored with RDD Event Source.");
                var item = (DependencyTelemetry)sentTelemetry;
                Assert.AreEqual(Url, item.Name, "Reported Url must be " + Url);
                Assert.IsTrue(item.Duration > TimeSpan.FromMilliseconds(0), "Duration has to be positive");
                Assert.AreEqual("Http", item.DependencyKind, "HttpAny has to be dependency kind as it includes http and azure calls");
                Assert.IsTrue(
                    DateTime.UtcNow.Subtract(item.Timestamp.UtcDateTime).TotalMilliseconds < TimeSpan.FromMinutes(1).TotalMilliseconds, "timestamp < now");
                Assert.IsTrue(
                    item.Timestamp.Subtract(DateTime.UtcNow).TotalMilliseconds > -TimeSpan.FromMinutes(1).TotalMilliseconds, "now - 1 min < timestamp");
            }
        }
        public void Initialize()
        {
            this.instrumentationKey = Guid.NewGuid().ToString();

            this.telemetryChannel = new StubTelemetryChannel()
            {
                EndpointAddress = "https://endpointaddress",
                OnSend          = this.sentTelemetry.Add
            };

            this.mockCorrelationIdLookupHelper = new MockCorrelationIdLookupHelper(new Dictionary <string, string>()
            {
                [this.instrumentationKey] = MockAppId
            });

            var configuration = new TelemetryConfiguration
            {
                TelemetryChannel   = this.telemetryChannel,
                InstrumentationKey = this.instrumentationKey,
            };

            configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            this.listener = new HttpCoreDiagnosticSourceListener(
                configuration,
                this.telemetryChannel.EndpointAddress,
                setComponentCorrelationHttpHeaders: true,
                correlationDomainExclusionList: new string[] { "excluded.host.com" },
                correlationIdLookupHelper: this.mockCorrelationIdLookupHelper);
        }
        public void Initialize()
        {
            this.sentTelemetry = new List <DependencyTelemetry>();

            this.channel = new StubTelemetryChannel
            {
                OnSend = telemetry =>
                {
                    // The correlation id lookup service also makes http call, just make sure we skip that
                    DependencyTelemetry depTelemetry = telemetry as DependencyTelemetry;
                    if (depTelemetry != null)
                    {
                        this.sentTelemetry.Add(depTelemetry);
                    }
                },
                EndpointAddress = FakeProfileApiEndpoint
            };

            this.config = new TelemetryConfiguration
            {
                InstrumentationKey = IKey,
                TelemetryChannel   = this.channel
            };

            this.config.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            DependencyTableStore.IsDesktopHttpDiagnosticSourceActivated = false;
        }
Exemplo n.º 4
0
        public void TestDependencyCollectionWithParentActivity()
        {
            ITelemetry sentTelemetry = null;

            var channel = new StubTelemetryChannel
            {
                OnSend = telemetry =>
                {
                    // The correlation id lookup service also makes http call, just make sure we skip that
                    DependencyTelemetry depTelemetry = telemetry as DependencyTelemetry;
                    if (depTelemetry != null &&
                        !depTelemetry.Data.StartsWith(FakeProfileApiEndpoint, StringComparison.OrdinalIgnoreCase))
                    {
                        Assert.IsNull(sentTelemetry);
                        sentTelemetry = telemetry;
                    }
                }
            };

            var config = new TelemetryConfiguration
            {
                InstrumentationKey = IKey,
                TelemetryChannel   = channel
            };

            config.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());

            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.ProfileQueryEndpoint = FakeProfileApiEndpoint;
                module.Initialize(config);

                var            url     = new Uri("http://bing.com");
                HttpWebRequest request = WebRequest.CreateHttp(url);

                var parent = new Activity("parent").AddBaggage("k", "v").SetParentId("|guid.").Start();
                request.GetResponse();
                parent.Stop();

                Assert.IsNotNull(sentTelemetry);
                var item = (DependencyTelemetry)sentTelemetry;
                Assert.AreEqual("200", item.ResultCode);

                var requestId = item.Id;
                Assert.AreEqual(requestId, request.Headers["Request-Id"]);
                Assert.AreEqual(requestId, request.Headers["x-ms-request-id"]);
                Assert.IsTrue(requestId.StartsWith(parent.Id));
                Assert.AreNotEqual(parent.Id, requestId);
                Assert.AreEqual("v", item.Context.Properties["k"]);

                Assert.AreEqual("k=v", request.Headers["Correlation-Context"]);
            }
        }
Exemplo n.º 5
0
        public void TestHttpPostRequestsAreCollected()
        {
            ITelemetry sentTelemetry = null;

            var channel = new StubTelemetryChannel
            {
                OnSend = telemetry =>
                {
                    // The correlation id lookup service also makes http call, just make sure we skip that
                    DependencyTelemetry depTelemetry = telemetry as DependencyTelemetry;
                    if (depTelemetry != null && !depTelemetry.Data.StartsWith(FakeProfileApiEndpoint, StringComparison.OrdinalIgnoreCase))
                    {
                        sentTelemetry = telemetry;
                    }
                }
            };

            var config = new TelemetryConfiguration
            {
                InstrumentationKey = IKey,
                TelemetryChannel   = channel
            };

            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.ProfileQueryEndpoint = FakeProfileApiEndpoint;
                module.Initialize(config);

                Uri url = new Uri("http://www.bing.com");
                new HttpWebRequestUtils().ExecuteAsyncHttpRequest(url.ToString(), HttpMethod.Post);

                while (sentTelemetry == null)
                {
                    Thread.Sleep(100);
                }

                Assert.IsNotNull(sentTelemetry, "Get requests are not monitored with RDD Event Source.");
                var item = (DependencyTelemetry)sentTelemetry;
                Assert.AreEqual(url, item.Data);
                Assert.AreEqual(url.Host, item.Target);
                Assert.AreEqual(url.AbsolutePath, item.Name);
                Assert.IsTrue(item.Duration > TimeSpan.FromMilliseconds(0), "Duration has to be positive");
                Assert.AreEqual(RemoteDependencyConstants.HTTP, item.Type, "HttpAny has to be dependency kind as it includes http and azure calls");
                Assert.IsTrue(
                    DateTime.UtcNow.Subtract(item.Timestamp.UtcDateTime).TotalMilliseconds < TimeSpan.FromMinutes(1).TotalMilliseconds, "timestamp < now");
                Assert.IsTrue(
                    item.Timestamp.Subtract(DateTime.UtcNow).TotalMilliseconds > -TimeSpan.FromMinutes(1).TotalMilliseconds, "now - 1 min < timestamp");
            }
        }
Exemplo n.º 6
0
        public void TestHttpPostRequestsAreCollected()
        {
            ITelemetry sentTelemetry = null;
            var        channel       = new StubTelemetryChannel {
                OnSend = telemetry => sentTelemetry = telemetry
            };

            var config = new TelemetryConfiguration
            {
                InstrumentationKey = IKey,
                TelemetryChannel   = channel
            };

            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.Initialize(config);
                Uri url = new Uri("http://www.bing.com");
                new HttpWebRequestUtils().ExecuteAsyncHttpRequest(url.ToString(), HttpMethod.Post);

                while (sentTelemetry == null)
                {
                    Thread.Sleep(100);
                }

                Assert.IsNotNull(sentTelemetry, "Get requests are not monitored with RDD Event Source.");
                var item = (DependencyTelemetry)sentTelemetry;
                Assert.AreEqual(url, item.Data);
                Assert.AreEqual(url.Host, item.Target);
                Assert.AreEqual(url.AbsolutePath, item.Name);
                Assert.IsTrue(item.Duration > TimeSpan.FromMilliseconds(0), "Duration has to be positive");
                Assert.AreEqual(RemoteDependencyConstants.HTTP, item.Type, "HttpAny has to be dependency kind as it includes http and azure calls");
                Assert.IsTrue(
                    DateTime.UtcNow.Subtract(item.Timestamp.UtcDateTime).TotalMilliseconds < TimeSpan.FromMinutes(1).TotalMilliseconds, "timestamp < now");
                Assert.IsTrue(
                    item.Timestamp.Subtract(DateTime.UtcNow).TotalMilliseconds > -TimeSpan.FromMinutes(1).TotalMilliseconds, "now - 1 min < timestamp");
            }
        }
Exemplo n.º 7
0
        public void TestDependencyCollectionNoParentActivity()
        {
            ITelemetry sentTelemetry = null;

            var channel = new StubTelemetryChannel
            {
                OnSend = telemetry =>
                {
                    // The correlation id lookup service also makes http call, just make sure we skip that
                    DependencyTelemetry depTelemetry = telemetry as DependencyTelemetry;
                    if (depTelemetry != null &&
                        !depTelemetry.Data.StartsWith(FakeProfileApiEndpoint, StringComparison.OrdinalIgnoreCase))
                    {
                        Assert.IsNull(sentTelemetry);
                        sentTelemetry = telemetry;
                    }
                }
            };

            var config = new TelemetryConfiguration
            {
                InstrumentationKey = IKey,
                TelemetryChannel   = channel
            };

            config.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());

            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.ProfileQueryEndpoint = FakeProfileApiEndpoint;
                module.Initialize(config);

                var            url     = new Uri("http://bing.com");
                HttpWebRequest request = WebRequest.CreateHttp(url);
                request.GetResponse();

                Assert.IsNotNull(sentTelemetry);
                var item = (DependencyTelemetry)sentTelemetry;
                Assert.AreEqual(url, item.Data);
                Assert.AreEqual(url.Host, item.Target);
                Assert.AreEqual("GET " + url.AbsolutePath, item.Name);
                Assert.IsTrue(item.Duration > TimeSpan.FromMilliseconds(0), "Duration has to be positive");
                Assert.AreEqual(RemoteDependencyConstants.HTTP, item.Type, "HttpAny has to be dependency kind as it includes http and azure calls");
                Assert.IsTrue(
                    DateTime.UtcNow.Subtract(item.Timestamp.UtcDateTime).TotalMilliseconds <
                    TimeSpan.FromMinutes(1).TotalMilliseconds,
                    "timestamp < now");
                Assert.IsTrue(
                    item.Timestamp.Subtract(DateTime.UtcNow).TotalMilliseconds >
                    -TimeSpan.FromMinutes(1).TotalMilliseconds,
                    "now - 1 min < timestamp");
                Assert.AreEqual("200", item.ResultCode);

                var requestId = item.Id;
                Assert.AreEqual(requestId, request.Headers["Request-Id"]);
                Assert.AreEqual(requestId, request.Headers["x-ms-request-id"]);
                Assert.IsTrue(requestId.StartsWith('|' + item.Context.Operation.Id + '.'));

                Assert.IsNull(request.Headers["Correlation-Context"]);
            }
        }