0

I have created the application Insights using ARM template with C# code.

var creds = new AzureCredentialsFactory().FromServicePrincipal(client, key, tenant, AzureEnvironment.AzureGlobalCloud);
            
IAzure azure = Microsoft.Azure.Management.Fluent.Azure.Authenticate(creds).WithSubscription(subscription);

IDeployment deployement = azure.Deployments.Define("my-app")
                    .WithExistingResourceGroup("my-rg-grp")
                    .WithTemplate(template)
                    .WithParameters("{}")
                    .WithMode(DeploymentMode.Incremental)
                    .CreateAsync();

deployment doesn't have the InstrumentationKey in response.

How could I get the InstrumentationKey just after the Application Insights creation using ARM?

1 Answers1

0

You can use ApplicationInsightsManagementClient class to get the ApplicationInsights resources and the relevant property. The class is defined at Microsoft.Azure.Management.ApplicationInsights v0.3.0-preview package

ApplicationInsightsManagementClient applicationInsightsManagementClient = 
                         new ApplicationInsightsManagementClient(creds) { SubscriptionId = subscriptionId };

var appliationInsightComponents = await applicationInsightsManagementClient.Components.ListAsync();

var requiredApplicationInsightComponent = appliationInsightComponents.SingleOrDefault(a => 
          a.ApplicationId.Equals("<<Name of resource>>", StringComparison.OrdinalIgnoreCase));

// to get the InstrumentationKey use

requiredApplicationInsightComponent.InstrumentationKey

user1672994
  • 10,509
  • 1
  • 19
  • 32