0

How do i get the application trace logs deployed in Azure Container Logs to view in Application Insights?

 _logger.LogInformation("get ratings " );

I have tried both Instrumentation key and ConnectionString to daprAI properties with no luck. I can view the logs in Logs Analytics (ContainerAppConsoleLogs_CL) so logs are working fine.

resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' = {
  name: containerAppEnvironmentName
  location: location
  tags: tags
  properties: {
    appLogsConfiguration: {
      destination: 'log-analytics'
      logAnalyticsConfiguration: {
        customerId: logAnalyticsWs.properties.customerId
        sharedKey: logAnalyticsWs.listKeys().primarySharedKey
      }
    }
    daprAIConnectionString: appInsights.properties.ConnectionString
    daprAIInstrumentationKey: appInsights.properties.InstrumentationKey
    vnetConfiguration:  null
    zoneRedundant: false
  }
}

Have added the env values in the container apps container

 { name: 'ApplicationInsights__ConnectionString'
    value: appInsights.properties.ConnectionString
  }
  {
    name: 'ApplicationInsights__InstrumentationKey'
    value: appInsights.properties.InstrumentationKey
  }

bootstrapped in the program files

 builder.Services.AddApplicationInsightsTelemetry();

Logs are not visible in the appinsights enter image description here

Gauls
  • 1,955
  • 6
  • 28
  • 44
  • 1
    By default any trace with a severity of Information is ignored, only Warning and up is logged. – Peter Bons Feb 11 '23 at 13:14
  • And please, post code as formatted text, **not** as images. – Peter Bons Feb 11 '23 at 13:17
  • @PeterBons : Updated to use formatted text as suggested. All severity logs are visible in appinsights when code is deployed to Azure App Service. I don't see why this can't be visible when deployed to Azure Container Apps? – Gauls Feb 12 '23 at 21:10
  • @PeterBons : I tested and noticed only warnings are visible in the appinsights, how to override this default behaviour? – Gauls Feb 13 '23 at 14:48

1 Answers1

0

I got logs ingestion in appinsights for ACA working by updating 1. appsetting file and 2. Using the sdk for in the program.cs file.

Program.cs

var appInsights = builder.Configuration.GetSection("ApplicationInsights");
ApplicationInsightsServiceOptions telemetryOptions=new()
{
ConnectionString=appInsights.GetValue<string>("ConnectionString"),
EnableDebugLogger=true
};
builder.Services.AddApplicationInsightsTelemetry(telemetryOptions);

appsettings.json

 {
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    }
  },
  "ApplicationInsights": {
    "ConnectionString": ""
  }
}
Gauls
  • 1,955
  • 6
  • 28
  • 44