Remote dependency monitoring.
Inheritance: ITelemetryModule, IDisposable
        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");
            }
        }
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var telemetryConfig = new TelemetryConfigurationBuilder()
                    .WithChannel(Channel)
                    .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                    .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(telemetryConfig);
                app.UseApplicationInsights(telemetryConfiguration: telemetryConfig);
            }
        public void DependencyTrackingTelemetryModuleIsNotInitializedTwiceToPreventProfilerAttachFailure()
        {
            var module = new DependencyTrackingTelemetryModule();
            PrivateObject privateObject = new PrivateObject(module);

            module.Initialize(TelemetryConfiguration.CreateDefault());
            object config1 = privateObject.GetField("telemetryConfiguration");

            module.Initialize(TelemetryConfiguration.CreateDefault());
            object config2 = privateObject.GetField("telemetryConfiguration");

            Assert.AreSame(config1, config2);
        }
コード例 #4
0
        public static void ConfigureTelemetryModules(this TelemetryConfiguration configuration)
        {
            var performanceCounters = new PerformanceCollectorModule();
            performanceCounters.Counters.Add(new PerformanceCounterCollectionRequest(@"\Process\ID", "ID"));
            performanceCounters.Initialize(configuration);

            telemetryModules.Add(performanceCounters);

            var dependencies = new DependencyTrackingTelemetryModule();
            dependencies.Initialize(configuration);
           
            telemetryModules.Add(dependencies);
        }
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var config = new TelemetryConfigurationBuilder()
                    .WithChannel(Channel)
                    .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                    .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(config);

                app.UseApplicationInsights(
                    middlewareConfiguration:
                        new OperationIdContextMiddlewareConfiguration {ShouldTryGetIdFromHeader = true},
                    telemetryConfiguration: config);
            }
        public void EventHubsSuccessfulSendIsHandledW3COff()
        {
            Activity.DefaultIdFormat      = ActivityIdFormat.Hierarchical;
            Activity.ForceDefaultIdFormat = true;
            using (var listener = new DiagnosticListener("Microsoft.Azure.EventHubs"))
                using (var module = new DependencyTrackingTelemetryModule())
                {
                    module.IncludeDiagnosticSourceActivities.Add("Microsoft.Azure.EventHubs");
                    module.Initialize(this.configuration);

                    Activity sendActivity   = null;
                    Activity parentActivity = new Activity("parent").AddBaggage("k1", "v1").Start();
                    var      telemetry      = this.TrackOperation <DependencyTelemetry>(
                        listener,
                        "Microsoft.Azure.EventHubs.Send",
                        TaskStatus.RanToCompletion,
                        null,
                        () => sendActivity = Activity.Current);

                    Assert.IsNotNull(telemetry);
                    Assert.AreEqual("Send", telemetry.Name);
                    Assert.AreEqual(RemoteDependencyConstants.AzureEventHubs, telemetry.Type);
                    Assert.AreEqual("sb://eventhubname.servicebus.windows.net/ | ehname", telemetry.Target);
                    Assert.IsTrue(telemetry.Success.Value);

                    Assert.AreEqual(parentActivity.Id, telemetry.Context.Operation.ParentId);
                    Assert.AreEqual(parentActivity.RootId, telemetry.Context.Operation.Id);
                    Assert.AreEqual(sendActivity.Id, telemetry.Id);

                    Assert.AreEqual("v1", telemetry.Properties["k1"]);
                    Assert.AreEqual("eventhubname.servicebus.windows.net", telemetry.Properties["peer.hostname"]);
                    Assert.AreEqual("ehname", telemetry.Properties["eh.event_hub_name"]);
                    Assert.AreEqual("SomePartitionKeyHere", telemetry.Properties["eh.partition_key"]);
                    Assert.AreEqual("EventHubClient1(ehname)", telemetry.Properties["eh.client_id"]);
                }
        }
コード例 #7
0
        public void ServiceBusBadStatusHanding()
        {
            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.IncludeDiagnosticSourceActivities.Add("Microsoft.Azure.ServiceBus");
                module.Initialize(this.configuration);

                DiagnosticListener listener = new DiagnosticListener("Microsoft.Azure.ServiceBus");

                Activity parentActivity = new Activity("parent").AddBaggage("k1", "v1").Start();
                var      telemetry      = this.TrackOperation <DependencyTelemetry>(listener, "Microsoft.Azure.ServiceBus.Send", TaskStatus.Faulted);

                Assert.IsNotNull(telemetry);
                Assert.AreEqual("Send", telemetry.Name);
                Assert.AreEqual(RemoteDependencyConstants.AzureServiceBus, telemetry.Type);
                Assert.AreEqual("sb://queuename.myservicebus.com/ | queueName", telemetry.Target);
                Assert.IsFalse(telemetry.Success.Value);

                Assert.AreEqual(parentActivity.Id, telemetry.Context.Operation.ParentId);
                Assert.AreEqual(parentActivity.RootId, telemetry.Context.Operation.Id);
                Assert.AreEqual("v1", telemetry.Properties["k1"]);
                Assert.AreEqual("messageId", telemetry.Properties["MessageId"]);
            }
        }
コード例 #8
0
        public void ServiceBusProcessHandingWithoutParent()
        {
            using (var module = new DependencyTrackingTelemetryModule())
            {
                module.IncludeDiagnosticSourceActivities.Add("Microsoft.Azure.ServiceBus");
                module.Initialize(this.configuration);

                DiagnosticListener listener = new DiagnosticListener("Microsoft.Azure.ServiceBus");

                var telemetry = this.TrackOperation <RequestTelemetry>(listener, "Microsoft.Azure.ServiceBus.Process", TaskStatus.RanToCompletion);

                Assert.IsNotNull(telemetry);
                Assert.AreEqual("Process", telemetry.Name);
                Assert.AreEqual($"type:{RemoteDependencyConstants.AzureServiceBus} | name:queueName | endpoint:sb://queuename.myservicebus.com/", telemetry.Source);
                Assert.IsTrue(telemetry.Success.Value);

                // W3C compatible-Id ( should go away when W3C is implemented in .NET https://github.com/dotnet/corefx/issues/30331 TODO)
                Assert.AreEqual(32, telemetry.Context.Operation.Id.Length);
                Assert.IsTrue(Regex.Match(telemetry.Context.Operation.Id, @"[a-z][0-9]").Success);
                // end of workaround test

                Assert.AreEqual("messageId", telemetry.Properties["MessageId"]);
            }
        }
        public void AzureClientSpansAreCollectedServerKind()
        {
            using (var listener = new DiagnosticListener("Azure.SomeClient"))
                using (var module = new DependencyTrackingTelemetryModule())
                {
                    module.Initialize(this.configuration);

                    Activity sendActivity = new Activity("Azure.SomeClient.Send");
                    sendActivity.AddTag("kind", "server");

                    listener.StartActivity(sendActivity, null);
                    listener.StopActivity(sendActivity, null);

                    var telemetry = this.sentItems.Last() as RequestTelemetry;

                    Assert.IsNotNull(telemetry);
                    Assert.AreEqual("SomeClient.Send", telemetry.Name);
                    Assert.IsTrue(telemetry.Success.Value);

                    Assert.IsNull(telemetry.Context.Operation.ParentId);
                    Assert.AreEqual(sendActivity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
                    Assert.AreEqual(sendActivity.SpanId.ToHexString(), telemetry.Id);
                }
        }
コード例 #10
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);
                Uri url = new Uri("http://www.bing.com/search?q=1");
                new HttpWebRequestUtils().ExecuteAsyncHttpRequest(url.ToString(), 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.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");
            }
        }
コード例 #11
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"]);
            }
        }
        public void TestHttpGetRequestsAreCollected()
        {
            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/maps");
                new HttpWebRequestUtils().ExecuteAsyncHttpRequest(url.ToString(), 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.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");
            }
        }