Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Application Insights in the Azure Government Cloud [v3.x] #2263

Closed
jcbrooks92 opened this issue Jul 11, 2019 · 10 comments · Fixed by Azure/azure-functions-host#5396 or #2385

Comments

@jcbrooks92
Copy link

jcbrooks92 commented Jul 11, 2019

AI with the government cloud requires a change to point to the government AI endpoint:

"ApplicationInsights": { "InstrumentationKey": "instrumentationkey", "TelemetryChannel": { "EndpointAddress": "https://dc.applicationinsights.us/v2/track" } }
https://docs.microsoft.com/en-us/azure/azure-government/documentation-government-services-monitoringandmanagement#application-insights

We tried the settings below but because the config doesn't allow changes to the TelemetryChannel+ the EndpointAddress this does not work.

https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerOptions.cs

{
  "version": "2.0",
   "logging": {
        "applicationInsights": {
            "TelemetryChannel": {
      "EndpointAddress": "https://dc.applicationinsights.us/v2/track"
    }

        }
    }
}
@brettsam
Copy link
Member

Copying my comment from issue #2265 here:

In order to use a government cloud you need to adjust the ServerTelemetryChannel's EndpointAddress. You should be able to do this via DI today with something like:

builder.Services.AddSingleton<ITelemetryChannel>(_ => new ServerTelemetryChannel { EndpointAddress = "https://dc.applicationinsights.us/v2/track" });

... but it'd be nice to have it exposed as an easy setting that we auto-apply for you, especially in Functions.

@jcbrooks92
Copy link
Author

jcbrooks92 commented Jul 12, 2019

This is the sample I used and I can now see data. Still working on getting the log stream working correctly.

image

using System;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;


[assembly: FunctionsStartup(typeof(FunctionV2DotNet.Startup))]

 namespace FunctionV2DotNet

{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<ITelemetryChannel>(_ => new ServerTelemetryChannel { EndpointAddress = "https://dc.applicationinsights.us/v2/track" });
        }
    }
}

@jcbrooks92
Copy link
Author

Updated startup.cs

This should allow log streaming and the other functionality

using System;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
using Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId;
using Microsoft.ApplicationInsights.Extensibility;
using System.Collections.Generic;
using Microsoft.ApplicationInsights.AspNetCore;
using Microsoft.Extensions.Options;
using System.Linq;

[assembly: FunctionsStartup(typeof(FunctionV2DotNet.Startup))]

 namespace FunctionV2DotNet

{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddOptions<TelemetryConfiguration>()
     .Configure<IEnumerable<ITelemetryModuleConfigurator>, IEnumerable<ITelemetryModule>>((telemetryConfig, configurators, modules) =>
     {
         // Run through the registered configurators
         foreach (var configurator in configurators)
         {
             ITelemetryModule telemetryModule = modules.FirstOrDefault((module) => module.GetType() == configurator.TelemetryModuleType);
             if (telemetryModule != null)
             {
                 configurator.Configure(telemetryModule);
             }
         }
     });

            builder.Services.ConfigureTelemetryModule<QuickPulseTelemetryModule>((module, o) => module.QuickPulseServiceEndpoint = "https://quickpulse.applicationinsights.us/QuickPulseService.svc");

            builder.Services.AddSingleton<IApplicationIdProvider>(_ => new ApplicationInsightsApplicationIdProvider() { ProfileQueryEndpoint = "https://dc.applicationinsights.us/api/profiles/{0}/appId" });
            builder.Services.AddSingleton<ITelemetryChannel>(s =>
            {
                // HACK: Need to force the options factory to run somewhere so it'll run through our Configurators.
                var ignore = s.GetService<IOptions<TelemetryConfiguration>>().Value;

                return new ServerTelemetryChannel { EndpointAddress = "https://dc.applicationinsights.us/v2/track" };
            });


        }
    }
}

@vlad2077
Copy link

Unfortunately it works only for AF V2 while we are running on V1..

@brettsam brettsam added the 3.x label Jul 29, 2019
@brettsam brettsam changed the title Support for Application Insights in the Azure Government Cloud Support for Application Insights in the Azure Government Cloud [v3.x] Jul 29, 2019
@DawgCoder
Copy link

How would I set the 3 URLs using Azure Functions V1. The example above is using V2. Is it possible in V1?

@v-vlkuzn
Copy link

Dependency Injection is a good solution for DotNet apps - I'd love to see support for other languages, having just encountered this issue with a NodeJs Function App. Ideally App Insights would be made aware of the environment-specific endpoints without user action.

@brettsam
Copy link
Member

@fabiocav -- we need to get this on the schedule soon. We should expose EndpointAddress/ProfileQueryEndpoint/QuickPulseServiceEndpoint properties that we'll update the right pieces internally.

@fabiocav
Copy link
Member

Any idea on the size of this task?

@ahmedelnably for thoughts on priority.

@brettsam
Copy link
Member

The engineering work would be pretty small. We need to expose the 3 properties I mention above and funnel them down to, basically, the code above, but in the TelemetryConfiguration initialization code. I've never actually deployed anything to a gov cloud before, though, so we may need some help figuring out how to set that up and validate.

@bguidinger
Copy link

@brettsam let me know if you need help testing this. I'd be happy to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment