コード例 #1
0
        /// <summary>
        /// Sends telemetry data item to the configured channel if the instrumentation key
        /// is not empty. Also publishes the telemetry item to the MessageBroker. Filters
        /// out the requests to Glimpse handler.
        /// </summary>
        /// <param name="item">Item to send.</param>
        public void Send(ITelemetry item)
        {
            var timer = this.TimerStrategy();

            if (item == null)
            {
                return;
            }

            // Filter the request telemetry to glimpse.axd
            if (item is RequestTelemetry)
            {
                var request = item as RequestTelemetry;
                if (request.Url != null && request.Url.AbsolutePath != null)
                {
                    if (request.Url.AbsolutePath.ToLower().EndsWith("glimpse.axd"))
                    {
                        return;
                    }
                }
            }

            if (timer != null && this.MessageBroker != null)
            {
                if (item is TraceTelemetry)
                {
                    var trace = item as TraceTelemetry;
                    var traceMessage = new TraceTelemetryTraceMessage(trace);
                    traceMessage.FromFirst = timer.Point().Offset;
                    traceMessage.FromLast = this.CalculateFromLast(timer);
                    this.MessageBroker.Publish(traceMessage);
                }
                else if (item is EventTelemetry)
                {
                    // Send it to TraceTab
                    var eventT = item as EventTelemetry;
                    var eventMessage = new EventTelemetryTraceMessage(eventT);
                    eventMessage.FromFirst = timer.Point().Offset;
                    eventMessage.FromLast = this.CalculateFromLast(timer);
                    this.MessageBroker.Publish(eventMessage);

                    // Send it to TimelineTab
                    var timelineMessage = new EventTelemetryTimelineMessage(eventT);
                    timelineMessage.Offset = timer.Point().Offset;
                    this.MessageBroker.Publish(timelineMessage);
                }
                else if (item is ExceptionTelemetry)
                {
                    // Send it to TraceTab
                    var trace = item as ExceptionTelemetry;
                    var traceMessage = new ExceptionTelemetryTraceMessage(trace);
                    traceMessage.FromFirst = timer.Point().Offset;
                    traceMessage.FromLast = this.CalculateFromLast(timer);
                    this.MessageBroker.Publish(traceMessage);

                    // Send it to TimelineTab
                    var timelineMessage = new ExceptionTelemetryTimelineMessage(trace);
                    timelineMessage.Offset = timer.Point().Offset;
                    this.MessageBroker.Publish(timelineMessage);
                }
                else if (item is RequestTelemetry)
                {
                    var request = item as RequestTelemetry;
                    var timelineMessage = new RequestTelemetryTimelineMessage(request);
                    timelineMessage.Offset = timer.Point().Offset.Subtract(request.Duration);
                    this.MessageBroker.Publish(timelineMessage);
                }
                else if (item is DependencyTelemetry)
                {
                    var dependency = item as DependencyTelemetry;
                    var timelineMessage = new DependencyTelemetryTimelineMessage(dependency);
                    timelineMessage.Offset = timer.Point().Offset.Subtract(dependency.Duration);
                    this.MessageBroker.Publish(timelineMessage);
                }

                this.messageBroker.Publish(item);
            }

            // Filter telemetry with empty instrumentation key
            if (item.Context.InstrumentationKey != null && !item.Context.InstrumentationKey.Equals("00000000-0000-0000-0000-000000000000"))
            {
                if (this.Channel != null)
                {
                    this.Channel.Send(item);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Sends telemetry data item to the configured channel if the instrumentation key
        /// is not empty. Also publishes the telemetry item to the MessageBroker. Filters
        /// out the requests to Glimpse handler.
        /// </summary>
        /// <param name="item">Item to send.</param>
        public void Send(ITelemetry item)
        {
            var timer = this.TimerStrategy();

            if (item == null || timer == null || this.MessageBroker == null)
            {
                this.SetItemSent(false);
                return;
            }

            // Filter the request telemetry to glimpse.axd
            if (item is RequestTelemetry)
            {
                var request = item as RequestTelemetry;
                if (request.Url != null && request.Url.AbsolutePath != null)
                {
                    if (request.Url.AbsolutePath.ToLower().EndsWith("glimpse.axd"))
                    {
                        this.SetItemSent(false);
                        return;
                    }
                }
            }

            if (item is DependencyTelemetry)
            {
                var dependency      = item as DependencyTelemetry;
                var timelineMessage = new DependencyTelemetryTimelineMessage(dependency);
                timelineMessage.Offset = timer.Point().Offset.Subtract(dependency.Duration);
                this.MessageBroker.Publish(timelineMessage);
            }

            if (item is TraceTelemetry)
            {
                var trace        = item as TraceTelemetry;
                var traceMessage = new TraceTelemetryTraceMessage(trace);
                traceMessage.FromFirst = timer.Point().Offset;
                traceMessage.FromLast  = this.CalculateFromLast(timer);
                this.MessageBroker.Publish(traceMessage);
            }

            if (item is EventTelemetry)
            {
                var eventT       = item as EventTelemetry;
                var eventMessage = new EventTelemetryTraceMessage(eventT);
                eventMessage.FromFirst = timer.Point().Offset;
                eventMessage.FromLast  = this.CalculateFromLast(timer);
                this.MessageBroker.Publish(eventMessage);
            }

            if (item is ExceptionTelemetry)
            {
                var trace        = item as ExceptionTelemetry;
                var traceMessage = new ExceptionTelemetryTraceMessage(trace);
                traceMessage.FromFirst = timer.Point().Offset;
                traceMessage.FromLast  = this.CalculateFromLast(timer);
                this.MessageBroker.Publish(traceMessage);
            }


            // Filter telemetry with empty instrumentation key
            if (item.Context.InstrumentationKey != null && !item.Context.InstrumentationKey.Equals("00000000-0000-0000-0000-000000000000"))
            {
                this.ApplicationInsightsChannel.Send(item);
                this.SetItemSent(true);
            }

            this.messageBroker.Publish(item);
            this.SetItemSent(true);
        }