コード例 #1
0
        public void ReportsAllProperties()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                Guid providerGuid = new Guid("497c5589-4f7f-56de-ea19-ea0604d23948");
                Guid eventId      = new Guid("30ba9220-89a4-41e4-987c-9e27ade44b74");
                Guid activityId   = new Guid("0724a028-27d7-40a9-a299-acf79ff0db94");
                EventSource.SetCurrentThreadActivityId(activityId);
                TestEventSource.Default.ComplexEvent(eventId);

                TraceTelemetry expected = new TraceTelemetry("Blah blah", SeverityLevel.Verbose);
                expected.Properties.Add("uniqueId", eventId.ToString());
                expected.Properties.Add("ProviderName", TestEventSource.ProviderName);
                expected.Properties.Add("ProviderGuid", providerGuid.ToString());
                expected.Properties.Add("EventId", TestEventSource.ComplexEventId.ToString(InvariantCulture));
                expected.Properties.Add("EventName", nameof(TestEventSource.ComplexEvent));
                expected.Properties.Add("ActivityId", activityId.ToString());
                expected.Properties.Add("Keywords", "0x8000F00000000001");
                expected.Properties.Add("Channel", "Debug");
                expected.Properties.Add("Opcode", "Extension");
                expected.Properties.Add("Tags", "0x00000011");
                expected.Properties.Add("Task", "0x00000020");

                CollectionAssert.AreEqual(new TraceTelemetry[] { expected }, this.adapterHelper.Channel.SentItems, new TraceTelemetryComparer(),
                                          "Reported event has properties different from expected");
            }
        }
コード例 #2
0
        public void ReactsToConfigurationChangesWithDisabledEventSources()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);
                var disableListeningRequest = new DisableEventSourceRequest()
                {
                    Name = TestEventSource.ProviderName
                };

                // Disabled
                module.DisabledSources.Add(disableListeningRequest);
                module.Initialize(GetTestTelemetryConfiguration());
                TestEventSource.Default.InfoEvent("Hey!");
                int sentCount = this.adapterHelper.Channel.SentItems.Count();
                Assert.AreEqual(0, sentCount);

                // From Disabled to Enabled
                module.DisabledSources.Remove(disableListeningRequest);
                module.Initialize(GetTestTelemetryConfiguration());
                TestEventSource.Default.InfoEvent("Hey!");
                sentCount = this.adapterHelper.Channel.SentItems.Count();
                Assert.AreEqual(1, sentCount);

                // From Enabled to Disabled
                module.DisabledSources.Add(disableListeningRequest);
                module.Initialize(GetTestTelemetryConfiguration());
                TestEventSource.Default.InfoEvent("Hey!");
                sentCount = this.adapterHelper.Channel.SentItems.Count();
                Assert.AreEqual(0, sentCount);
            }
        }
コード例 #3
0
        public void ReportsSingleEvent()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                TestEventSource.Default.InfoEvent("Hey!");

                TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems.Single();
                Assert.AreEqual("Hey!", telemetry.Message);
                Assert.AreEqual("Hey!", telemetry.Properties["information"]);
                Assert.AreEqual(SeverityLevel.Information, telemetry.SeverityLevel);
                string expectedVersion = SdkVersionHelper.GetExpectedSdkVersion(prefix: "evl:", loggerType: typeof(EventSourceTelemetryModule));
                Assert.AreEqual(expectedVersion, telemetry.Context.GetInternalContext().SdkVersion);
            }
        }
コード例 #4
0
        public void HandlesDuplicatePropertyNames()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                TestEventSource.Default.Tricky(7, "TrickyEvent", "Actual message");

                Assert.AreEqual(1, this.adapterHelper.Channel.SentItems.Length);
                TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems[0];
                Assert.AreEqual("Manifest message", telemetry.Message);
                Assert.AreEqual(SeverityLevel.Information, telemetry.SeverityLevel);
                Assert.AreEqual("Actual message", telemetry.Properties["Message"]);
                Assert.AreEqual("7", telemetry.Properties["EventId"]);
                Assert.AreEqual("TrickyEvent", telemetry.Properties["EventName"]);
                Assert.IsTrue(telemetry.Properties[telemetry.Properties.Keys.First(key => key.StartsWith("EventId", StringComparison.Ordinal) && !string.Equals(key, "EventId", StringComparison.Ordinal))].Equals("7", StringComparison.Ordinal));
                Assert.IsTrue(telemetry.Properties[telemetry.Properties.Keys.First(key => key.StartsWith("EventName", StringComparison.Ordinal) && !string.Equals(key, "EventName", StringComparison.Ordinal))].Equals("Tricky", StringComparison.Ordinal));
            }
        }
コード例 #5
0
        public void CustomPayloadProperties()
        {
            OnEventWrittenHandler onWrittenHandler = (EventWrittenEventArgs args, TelemetryClient client) =>
            {
                var traceTelemetry = new TraceTelemetry("CustomPayloadProperties", SeverityLevel.Verbose);
                traceTelemetry.Properties.Add("CustomPayloadProperties", "true");
                client.Track(traceTelemetry);
            };

            using (var module = new EventSourceTelemetryModule(onWrittenHandler))
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                TestEventSource.Default.Write("CustomPayloadProperties");

                TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems[0];
                Assert.IsTrue(telemetry.Properties.All(kvp => kvp.Key.Equals("CustomPayloadProperties", StringComparison.Ordinal) && kvp.Value.Equals("true", StringComparison.Ordinal)));
            }
        }
コード例 #6
0
        public void ReactsToConfigurationChanges()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                TestEventSource.Default.InfoEvent("Hey!");
                TestEventSource.Default.WarningEvent(1, 2);

                // Now request reporting events only with certain keywords
                listeningRequest.Keywords = TestEventSource.Keywords.NonRoutine;
                module.Initialize(GetTestTelemetryConfiguration(resetChannel: false));

                TestEventSource.Default.InfoEvent("Hey again!");
                TestEventSource.Default.WarningEvent(3, 4);

                List <TraceTelemetry> expectedTelemetry = new List <TraceTelemetry>();
                TraceTelemetry        traceTelemetry    = new TraceTelemetry("Hey!", SeverityLevel.Information);
                traceTelemetry.Properties["information"] = "Hey!";
                expectedTelemetry.Add(traceTelemetry);
                traceTelemetry = new TraceTelemetry("Warning!", SeverityLevel.Warning);
                traceTelemetry.Properties["i1"] = 1.ToString(InvariantCulture);
                traceTelemetry.Properties["i2"] = 2.ToString(InvariantCulture);
                expectedTelemetry.Add(traceTelemetry);
                // Note that second informational event is not expected
                traceTelemetry = new TraceTelemetry("Warning!", SeverityLevel.Warning);
                traceTelemetry.Properties["i1"] = 3.ToString(InvariantCulture);
                traceTelemetry.Properties["i2"] = 4.ToString(InvariantCulture);
                expectedTelemetry.Add(traceTelemetry);

                CollectionAssert.AreEqual(expectedTelemetry, this.adapterHelper.Channel.SentItems, new TraceTelemetryComparer(), "Reported events are not what was expected");
            }
        }
コード例 #7
0
        public void ReportsSeverityLevel()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest();
                listeningRequest.Name = TestEventSource.ProviderName;
                module.Sources.Add(listeningRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                TestEventSource.Default.InfoEvent("Hey!");
                TestEventSource.Default.WarningEvent(1, 2);
                TestEventSource.Default.ErrorEvent(2.3, "default context");

                TraceTelemetry[] expectedTelemetry = new TraceTelemetry[]
                {
                    new TraceTelemetry("Hey!", SeverityLevel.Information),
                    new TraceTelemetry("Warning!", SeverityLevel.Warning),
                    new TraceTelemetry("Error!", SeverityLevel.Error)
                };

                CollectionAssert.AreEqual(expectedTelemetry, this.adapterHelper.Channel.SentItems, new TraceTelemetryComparer(), "Reported events are not what was expected");
            }
        }
コード例 #8
0
        public void DisablingEventFromEventSource()
        {
            using (var module = new EventSourceTelemetryModule())
            {
                var listeningRequest = new EventSourceListeningRequest()
                {
                    Name = TestEventSource.ProviderName
                };
                module.Sources.Add(listeningRequest);

                var disablingRequest = new DisableEventSourceRequest()
                {
                    Name = TestEventSource.ProviderName
                };
                module.DisabledSources.Add(disablingRequest);

                module.Initialize(GetTestTelemetryConfiguration());

                TestEventSource.Default.InfoEvent("Hey!");

                int sentCount = this.adapterHelper.Channel.SentItems.Count();
                Assert.AreEqual(0, sentCount);
            }
        }