Example #1
0
        public void ActivityPathDecoderDecodesHierarchicalActivityId()
        {
            Guid   activityId   = new Guid("000000110000000000000000be999d59");
            string activityPath = ActivityPathDecoder.GetActivityPathString(activityId);

            Assert.AreEqual("//1/1/", activityPath);
        }
        public static void Track(this TraceEvent traceEvent, TelemetryClient client)
        {
            Debug.Assert(client != null, "Should always receive a valid client");

            string         formattedMessage = traceEvent.FormattedMessage;
            TraceTelemetry telemetry        = new TraceTelemetry(formattedMessage, traceEventLevelToSeverityLevel[(int)traceEvent.Level]);

            telemetry.AddProperty("EventId", traceEvent.ID.ToString());
            telemetry.AddProperty(nameof(traceEvent.EventName), traceEvent.EventName);
            if (traceEvent.ActivityID != default(Guid))
            {
                telemetry.AddProperty(nameof(traceEvent.ActivityID), ActivityPathDecoder.GetActivityPathString(traceEvent.ActivityID));
            }

            if (traceEvent.RelatedActivityID != default(Guid))
            {
                telemetry.AddProperty(nameof(traceEvent.RelatedActivityID), traceEvent.RelatedActivityID.ToString());
            }

            telemetry.AddProperty(nameof(traceEvent.Channel), traceEvent.Channel.ToString());
            telemetry.AddProperty(nameof(traceEvent.Keywords), GetHexRepresentation((long)traceEvent.Keywords));
            telemetry.AddProperty(nameof(traceEvent.Opcode), traceEvent.Opcode.ToString());
            if (traceEvent.Task != TraceEventTask.Default)
            {
                telemetry.AddProperty(nameof(traceEvent.Task), GetHexRepresentation((int)traceEvent.Task));
            }

            // Make this the call after adding traceEvent properties that property name on trace event will take the priority in possible duplicated property scenario.
            traceEvent.ExtractPayloadData(telemetry);

            client.Track(telemetry);
        }
Example #3
0
        public void ActivityPathDecoderHandlesNonhierarchicalActivityIds()
        {
            string guidString   = "bf0209f9-bf5e-415e-86ed-0e20b615b406";
            Guid   activityId   = new Guid(guidString);
            string activityPath = ActivityPathDecoder.GetActivityPathString(activityId);

            Assert.AreEqual(guidString, activityPath);
        }
Example #4
0
        /// <summary>
        /// Populates a standard set of properties on the <see cref="TraceTelemetry"/> with values from the a given EventSource event.
        /// </summary>
        /// <param name="telemetry">Telemetry item to populate with properties.</param>
        /// <param name="eventSourceEvent">Event to extract values from.</param>
        public static TraceTelemetry PopulateStandardProperties(this TraceTelemetry telemetry, EventWrittenEventArgs eventSourceEvent)
        {
            if (telemetry == null)
            {
                throw new ArgumentNullException(nameof(telemetry));
            }

            if (eventSourceEvent == null)
            {
                throw new ArgumentNullException(nameof(eventSourceEvent));
            }

            if (!string.IsNullOrWhiteSpace(eventSourceEvent.EventSource.Name))
            {
                telemetry.AddProperty(ProviderNameProperty, eventSourceEvent.EventSource.Name);
            }

            if (eventSourceEvent.EventSource.Guid != Guid.Empty)
            {
                telemetry.AddProperty(ProviderGuidProperty, eventSourceEvent.EventSource.Guid.ToString());
            }

            telemetry.AddProperty(nameof(EventWrittenEventArgs.EventId), eventSourceEvent.EventId.ToString(CultureInfo.InvariantCulture));
            telemetry.AddProperty(nameof(EventWrittenEventArgs.EventName), eventSourceEvent.EventName);
            if (eventSourceEvent.ActivityId != default(Guid))
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.ActivityId), ActivityPathDecoder.GetActivityPathString(eventSourceEvent.ActivityId));
            }

            if (eventSourceEvent.RelatedActivityId != default(Guid))
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.RelatedActivityId), ActivityPathDecoder.GetActivityPathString(eventSourceEvent.RelatedActivityId));
            }

            telemetry.AddProperty(nameof(EventWrittenEventArgs.Channel), eventSourceEvent.Channel.GetChannelName());
            telemetry.AddProperty(nameof(EventWrittenEventArgs.Keywords), GetHexRepresentation((long)eventSourceEvent.Keywords));
            telemetry.AddProperty(nameof(EventWrittenEventArgs.Opcode), eventSourceEvent.Opcode.GetOpcodeName());
            if (eventSourceEvent.Tags != EventTags.None)
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.Tags), GetHexRepresentation((int)eventSourceEvent.Tags));
            }

            if (eventSourceEvent.Task != EventTask.None)
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.Task), GetHexRepresentation((int)eventSourceEvent.Task));
            }

            return(telemetry);
        }
Example #5
0
        /// <summary>
        /// Creates a TraceTelemetry out of an EventSource event and tracks it using the supplied client.
        /// </summary>
        /// <param name="eventSourceEvent">The source for the telemetry data.</param>
        /// <param name="client">Client to track the data with.</param>
        public static void Track(this EventWrittenEventArgs eventSourceEvent, TelemetryClient client)
        {
            Debug.Assert(client != null, "Should always receive a valid client");

            string formattedMessage = null;

            if (eventSourceEvent.Message != null)
            {
                try
                {
                    // If the event has a badly formatted manifest, message formatting might fail
                    formattedMessage = string.Format(CultureInfo.InvariantCulture, eventSourceEvent.Message, eventSourceEvent.Payload.ToArray());
                }
                catch
                {
                }
            }
            TraceTelemetry telemetry = new TraceTelemetry(formattedMessage, eventLevelToSeverityLevel[(int)eventSourceEvent.Level]);

            eventSourceEvent.ExtractPayloadData(telemetry);

            telemetry.AddProperty(nameof(EventWrittenEventArgs.EventId), eventSourceEvent.EventId.ToString(CultureInfo.InvariantCulture));
            telemetry.AddProperty(nameof(EventWrittenEventArgs.EventName), eventSourceEvent.EventName);
            if (eventSourceEvent.ActivityId != default(Guid))
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.ActivityId), ActivityPathDecoder.GetActivityPathString(eventSourceEvent.ActivityId));
            }
            if (eventSourceEvent.RelatedActivityId != default(Guid))
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.RelatedActivityId), eventSourceEvent.RelatedActivityId.ToString());
            }
            telemetry.AddProperty(nameof(EventWrittenEventArgs.Channel), eventSourceEvent.Channel.GetChannelName());
            telemetry.AddProperty(nameof(EventWrittenEventArgs.Keywords), GetHexRepresentation((long)eventSourceEvent.Keywords));
            telemetry.AddProperty(nameof(EventWrittenEventArgs.Opcode), eventSourceEvent.Opcode.GetOpcodeName());
            if (eventSourceEvent.Tags != EventTags.None)
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.Tags), GetHexRepresentation((int)eventSourceEvent.Tags));
            }
            if (eventSourceEvent.Task != EventTask.None)
            {
                telemetry.AddProperty(nameof(EventWrittenEventArgs.Task), GetHexRepresentation((int)eventSourceEvent.Task));
            }

            client.Track(telemetry);
        }
Example #6
0
        public void ActivityPathDecoderHandlesEmptyActivityId()
        {
            string activityPath = ActivityPathDecoder.GetActivityPathString(Guid.Empty);

            Assert.AreEqual(Guid.Empty.ToString(), activityPath);
        }