diff --git a/.github/workflows/push_to_live.yml b/.github/workflows/push_to_live.yml index 67ed6b7..ded1a5f 100644 --- a/.github/workflows/push_to_live.yml +++ b/.github/workflows/push_to_live.yml @@ -29,6 +29,23 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Set lowercase image name run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV + - name: Ensure Application Insights exists + id: appinsights + run: | + CONN_STR=$(az monitor app-insights component show \ + --app bottomly-live \ + --resource-group ${{ secrets.RESOURCE_GROUP }} \ + --query connectionString \ + --output tsv 2>/dev/null || \ + az monitor app-insights component create \ + --app bottomly-live \ + --resource-group ${{ secrets.RESOURCE_GROUP }} \ + --location "uk south" \ + --kind web \ + --application-type other \ + --query connectionString \ + --output tsv) + echo "connection_string=$CONN_STR" >> $GITHUB_OUTPUT - name: Deploy to Azure Container Instances uses: azure/aci-deploy@v1 with: @@ -49,3 +66,4 @@ jobs: bottomly_env=${{ secrets.ENV }} ConnectionStrings__mongodb=${{ secrets.MONGO_CONN_STR }} bottomly_github_token=${{ secrets.RELEASE_HISTORY_TOKEN }} + APPLICATIONINSIGHTS_CONNECTION_STRING=${{ steps.appinsights.outputs.connection_string }} diff --git a/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj b/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj index 938db20..0e8b658 100644 --- a/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj +++ b/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj @@ -17,6 +17,7 @@ + diff --git a/Bottomly.ServiceDefaults/Extensions.cs b/Bottomly.ServiceDefaults/Extensions.cs index b3f7b27..5e47062 100644 --- a/Bottomly.ServiceDefaults/Extensions.cs +++ b/Bottomly.ServiceDefaults/Extensions.cs @@ -1,3 +1,4 @@ +using Azure.Monitor.OpenTelemetry.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Extensions.DependencyInjection; @@ -88,12 +89,11 @@ private static TBuilder AddOpenTelemetryExporters(this TBuilder builde builder.Services.AddOpenTelemetry().UseOtlpExporter(); } - // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package) - //if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) - //{ - // builder.Services.AddOpenTelemetry() - // .UseAzureMonitor(); - //} + if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) + { + builder.Services.AddOpenTelemetry() + .UseAzureMonitor(); + } return builder; }