ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

Is it possible to send ApplicationInsightsTelemetry to multiple ingestion endpoints?

Open yildizfatih opened this issue 4 years ago • 9 comments

I am looking for ways to send (Trace, Metrics, RemoteDependency) telemetry data to multiple application insight endpoints from the same azure function.

yildizfatih avatar Jan 21 '21 23:01 yildizfatih

Its not clear what you are trying to achieve. Could you explain a bit more?

cijothomas avatar Jan 22 '21 00:01 cijothomas

Sure thing. AFAIK, currently there is only one setting 'APPLICATIONINSIGHTS_CONNECTION_STRING' that can be set to send ApplicationInsightTelemetry data to azure app insights. I would like to set two connection strings instead of one. I would like to send ApplicationInsightTelemetry data to two different places. I am wondering whether it is possible?

yildizfatih avatar Jan 22 '21 00:01 yildizfatih

If your intention is to send same telemetry to more than one ikey, then its possible with the use of TelemetrySinks concept in this SDK. There are no e2e examples for it here, and also I'm not sure if it'll work inside Azure functions, as this requires modififying TelemetryProcessor chains, which can be tricky inside Functions.

Also sending same data to 2 ikeys will double your bill. If you still want to do this @TimothyMothra Do you have samples for using sinks to add 2 AppInsight channel with 2 ikeys?

cijothomas avatar Jan 22 '21 00:01 cijothomas

Yes please, it is exactly what I would like to achieve. Any guidance would be great.

yildizfatih avatar Jan 22 '21 00:01 yildizfatih

I was able to achieve partial success with https://github.com/serilog/serilog-sinks-applicationinsights/. However, data were missing RemoteDependency and Metrics, it only had the Traces. My understanding is that it is related to initializers/processors mismatch between TelemetryConfiguration.Active and TelemetryConfiguration.CreateDefault().

It is not clear how I can make config from TelemetryConfiguration.CreateDefault() similar to TelemetryConfiguration.Active.

        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddLogging(loggingBuilder =>
            {
                var config1 = TelemetryConfiguration.CreateDefault();
                config1.InstrumentationKey = "...";

                var config2 = TelemetryConfiguration.CreateDefault();
                config2.InstrumentationKey = "...";

                var logger = new LoggerConfiguration()
                .WriteTo.ApplicationInsights(config1, TelemetryConverter.Traces)
                .WriteTo.ApplicationInsights(config2, TelemetryConverter.Traces)
                .CreateLogger();
                loggingBuilder.AddSerilog(logger);
            });
        }

But if there is any solution that does not rely on serilog, would be even better.

yildizfatih avatar Jan 22 '21 00:01 yildizfatih

In case anyone has a similar question, I was able to get it working with a custom telemetry channel. Thank you for the TelemetrySinker direction.

yildizfatih avatar Jan 22 '21 21:01 yildizfatih

I'm trying to do the same thing. What does that custom telemetry channel of yours do? One would think you just register an additional TelemetrySink with one of the provided telemetry channel implementations (either InMemoryChannel or ServerTelemetryChannel) and then perhaps call the TelemetryProcessorChainBuilder.Build() as mentioned in #957 but I had no luck with that approach so far.

vit-svoboda avatar Jul 13 '21 15:07 vit-svoboda

This worked for me for my node.js application: https://docs.microsoft.com/en-us/azure/azure-monitor/app/nodejs#use-multiple-instrumentation-keys

let appInsights = require("applicationinsights");

// configure auto-collection under one ikey appInsights.setup("ikey-A").start();

// track some events manually under another ikey let otherClient = new appInsights.TelemetryClient("ikey-B"); otherClient.trackEvent({name: "my custom event"});

megfager avatar Aug 10 '21 18:08 megfager

I've kind of the same question. I've 2 applications both with their own instrumentation key but I would like to view the telemetry traces as if there was only 1 instrumentation key (the flow over applications). Now I could reuse the key but that would result in the forced use of a single key for every application in the whole organization. Alternative I could try to send data to a shared secondary instrumentation key (to "opt-in" on the flow over the applications) but it feels a bit like a work around. Isn't there any way to view data from multiple instrumentation keys from a single perspectvie.

qsdfplkj avatar Apr 08 '22 14:04 qsdfplkj

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Feb 03 '23 00:02 github-actions[bot]

Hello! Do we have a working example for this? I tried the custom telemetry channel option but without luck.

ursaciuc-adrian avatar Jul 20 '23 14:07 ursaciuc-adrian