Search in sources :

Example 1 with ApplicationInsightsEntity

use of com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity in project azure-tools-for-java by Microsoft.

the class FunctionAppService method bindApplicationInsights.

private void bindApplicationInsights(final Map<? super String, ? super String> appSettings, final FunctionAppConfig config) {
    // Skip app insights creation when user specify ai connection string in app settings or disable ai in configuration
    if (appSettings.containsKey(APPINSIGHTS_INSTRUMENTATION_KEY) || config.getMonitorConfig().getApplicationInsightsConfig() == null) {
        return;
    }
    String instrumentationKey = config.getMonitorConfig().getApplicationInsightsConfig().getInstrumentationKey();
    if (StringUtils.isEmpty(instrumentationKey)) {
        final ApplicationInsightsEntity applicationInsightsComponent = getOrCreateApplicationInsights(config);
        instrumentationKey = applicationInsightsComponent == null ? null : applicationInsightsComponent.getInstrumentationKey();
    }
    appSettings.put(APPINSIGHTS_INSTRUMENTATION_KEY, instrumentationKey);
}
Also used : ApplicationInsightsEntity(com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity)

Example 2 with ApplicationInsightsEntity

use of com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity in project azure-tools-for-java by Microsoft.

the class FunctionAppService method createApplicationInsights.

@Nullable
private ApplicationInsightsEntity createApplicationInsights(final FunctionAppConfig config) {
    try {
        AzureMessager.getMessager().info(APPLICATION_INSIGHTS_CREATE_START);
        final AzureEnvironment environment = Azure.az(AzureAccount.class).account().getEnvironment();
        final ApplicationInsightsEntity resource = Azure.az(ApplicationInsights.class).create(config.getSubscription().getId(), config.getResourceGroup().getName(), config.getRegion(), config.getMonitorConfig().getApplicationInsightsConfig().getName());
        AzureMessager.getMessager().info(String.format(APPLICATION_INSIGHTS_CREATED, resource.getName(), IdentityAzureManager.getInstance().getPortalUrl(), resource.getId()));
        return resource;
    } catch (final Exception e) {
        AzureMessager.getMessager().warning(String.format(APPLICATION_INSIGHTS_CREATE_FAILED, e.getMessage()));
        return null;
    }
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) ApplicationInsights(com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsights) ApplicationInsightsEntity(com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity) IOException(java.io.IOException) ManagementException(com.azure.core.management.exception.ManagementException) Nullable(javax.annotation.Nullable)

Aggregations

ApplicationInsightsEntity (com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsightsEntity)2 AzureEnvironment (com.azure.core.management.AzureEnvironment)1 ManagementException (com.azure.core.management.exception.ManagementException)1 ApplicationInsights (com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsights)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1