/// <summary>
            /// Sends the item to sink. If cloning of item is required, clones the item before sending it to <see cref="TelemetrySink"/>
            /// </summary>
            /// <param name="telemetry">The telemetry item to send to sink.</param>
            public void SendItemToSink(ITelemetry telemetry)
            {
                ITelemetry itemToSendToSink = this.cloneBeforeDispatch ? telemetry.DeepClone() : telemetry;

                if (itemToSendToSink != null)
                {
                    this.sink.Process(itemToSendToSink);
                }
                else
                {
                    Debug.Fail("Telemetry item should not be null");
                }
            }
        public void Initialize(ITelemetry telemetry)
        {
            if (_httpContextAccessor.HttpContext == null)
            {
                return;
            }

            string remoteAI = _httpContextAccessor.HttpContext.Request.Headers["ai-callback"];

            if (!string.IsNullOrWhiteSpace(remoteAI) && telemetry.Context.InstrumentationKey != remoteAI)
            {
                var telemetryClone = telemetry.DeepClone();
                telemetryClone.Context.InstrumentationKey = remoteAI;

                TelemetryConfiguration.CreateDefault().TelemetryChannel.Send(telemetryClone);
            }
        }
        public void Initialize(ITelemetry telemetry)
        {
            if (HttpContext.Current != null && HttpContext.Current.Items.Contains("ai_preferred"))
            {
                var preferredAI = HttpContext.Current.Items["ai_preferred"];
                if (preferredAI.GetType() == typeof(int))
                {
                    int aiOptions = (int)preferredAI;

                    if (aiOptions > 0)
                    {
                        telemetry.Context.InstrumentationKey = System.Configuration.ConfigurationManager.AppSettings[aiOptions == 1 ? "ai_primary" : "ai_secondary"];
                    }
                    else if (telemetry.Context.InstrumentationKey == System.Configuration.ConfigurationManager.AppSettings["ai_primary"])
                    {
                        var telemetryClone = telemetry.DeepClone();
                        telemetryClone.Context.InstrumentationKey = System.Configuration.ConfigurationManager.AppSettings["ai_secondary"];
                        _telemetryClient.Track(telemetryClone);
                    }
                }
            }
        }
 public void Offer(ITelemetry telemetry)
 {
     this.nextTelemetryToProcess = this.cloneBeforeDispatch ? telemetry.DeepClone() : telemetry;
 }