none
Single App, Multiple App Insights Destinations RRS feed

  • Question

  • Hello, is it possible to send AI telemetry to multiple AI destinations from a single app? We have a vendor created application that sends telemetry to the vendor instance of AI but we also want the same telemetry sent to our AI instance. Is this possible?
    Wednesday, March 27, 2019 7:28 PM

All replies

  • If you'd like to send some data to one AI resource, some to another AI resource and some to both, the OK approach is to use several Telemetry Client instances with the different Instrumentation Keys (or with different Telemetry Configuration objects even). Then you can send through one client or the other or both.

    If you are looking for a hard-copy of everything, you can leverage couple Telemetry Sinks and use one Instrumentation Key in the first sink while using the second Instrumentation Key in the second Telemetry Sink, one client will write to both at the same time for the auto-collected and custom telemetry:

    namespace AiMultiSink
    {
        class Program
        {
            static void Main(string[] args)
            {
                var config = TelemetryConfiguration.Active;
    
                var channel1 = new InMemoryChannel();
                config.DefaultTelemetrySink.TelemetryChannel = channel1;            
    
                var chainBuilder1 = new TelemetryProcessorChainBuilder(config, config.DefaultTelemetrySink);
                chainBuilder1.Use((next) =>
                {
                    var p1 = new StubTelemetryProcessor(next);
                    p1.OnProcess = (telemetry) => { telemetry.Context.InstrumentationKey = "afefc2f8-62c5-449c-a604-15bf92c79d53"; };
                    return p1;
                });
                config.DefaultTelemetrySink.TelemetryProcessorChainBuilder = chainBuilder1;
                
                var channel2 = new InMemoryChannel();
                var sink2 = new TelemetrySink(config, channel2);
                config.TelemetrySinks.Add(sink2);
    
                var chainBuilder2 = new TelemetryProcessorChainBuilder(config, sink2);
                chainBuilder2.Use((next) =>
                {
                    var p2 = new StubTelemetryProcessor(next);
                    p2.OnProcess = (telemetry) => { telemetry.Context.InstrumentationKey = "c52e4c3e-6045-49d3-adae-1346fc0a2431"; };
                    return p2;
                });
                sink2.TelemetryProcessorChainBuilder = chainBuilder2;
    
                var client = new TelemetryClient(config);
                client.TrackTrace("foo");
                channel1.Flush();
                channel2.Flush();
                Console.WriteLine("Press any key to exit");
                Console.ReadKey(intercept: true);
            }
        }
    
        public sealed class StubTelemetryProcessor : ITelemetryProcessor, IDisposable
        {
            private ITelemetryProcessor next;
    
            public StubTelemetryProcessor(ITelemetryProcessor next)
            {
                this.next = next;
                this.OnDispose = () => { };
                this.OnProcess = (unusedTelemetry) => { };
            }
    
            public Action<ITelemetry> OnProcess { get; set; }
    
            public Action OnDispose { get; set; }
    
            public void Process(ITelemetry telemetry)
            {
                this.OnProcess(telemetry);
                if (this.next != null)
                {
                    this.next.Process(telemetry);
                }
            }
    
            public void Dispose()
            {
                this.OnDispose();
            }
        }
    }
    


    Dmitry Matveev

    Wednesday, March 27, 2019 9:15 PM
    Owner