From 6cba74570213701771bda832d2aa8bb935295036 Mon Sep 17 00:00:00 2001
From: Stijn Moreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Thu, 29 Feb 2024 06:42:43 +0100
Subject: [PATCH] chore: use appinsights pkg for isolated az func (#442)
* chore: use preview appinsights pkg for isolated az func
* pr-fix: update w/ trace logging for docker tests
* pr-tmp: try to see if the package addition is the cause
* pr-fix: solely rely on worker pkg
* pr-fix: solely rely on worker pkg
* pr-fix: solely rely on worker pkg
* pr-fix: solely rely on worker pkg
* pr-fix: update with env var
* pr-fix: update with env var
* pr-fix: update with env var
* pr-fix: remove app insights from az func regisration
* pr-fix: remove app insights from az func regisration
* pr-fix: realistic package deps
* pr-fix: use new app insights env var
* pr-fix: update arcus observability
* pr-fix: simplify dependencies
* pr-fix: complete upgrade arcus observability
* pr-fix: dockerfile setup
* pr-fix: move preview package back to arcus
* pr-fix: remaining package conflicts
* pr-fix: revert to original arcus observability dependency
* pr-revert: unnecessary changes
* Update Arcus.WebApi.Logging.AzureFunctions.csproj
* pr-up: newest preview package workings
* Update Arcus.WebApi.Logging.AzureFunctions.csproj
* pr-fix: update dockerfile w/ new 7 .net sdk
* Update Arcus.WebApi.Logging.AzureFunctions.csproj
* pr-fix: force add nuget package diagnostic source
* pr-fix: conditional isolated
* pr-fix: update webjobs package
* Update Dockerfile
* Update Dockerfile
* Update Arcus.WebApi.Tests.Runtimes.AzureFunction.csproj
* Update run-docker-integration-tests.yml
* Update IServiceCollectionExtensions.cs
* Update IServiceCollectionExtensions.cs
* Update Arcus.WebApi.Tests.Integration.csproj
* Update Dockerfile
* Update Dockerfile
* Update Arcus.WebApi.Logging.AzureFunctions.csproj
* pr-fix: correct missing package after merge w/ 'main'
* pr-fix: revert az func isolated Dockerfile
* pr-fix: revert az func in-process Dockerfile
* Update Dockerfile
* Update Dockerfile
* Update Arcus.WebApi.Logging.AzureFunctions.csproj
* Update Arcus.WebApi.Logging.AzureFunctions.csproj
---
.../templates/run-docker-integration-tests.yml | 4 +++-
build/templates/start-docker-project.yml | 4 +++-
.../Arcus.WebApi.Logging.AzureFunctions.csproj | 5 +++--
...nctionsWorkerApplicationBuilderExtensions.cs | 11 ++---------
.../Extensions/IServiceCollectionExtensions.cs | 2 +-
.../Arcus.WebApi.Tests.Integration.csproj | 2 +-
.../Dockerfile | 2 +-
...s.WebApi.Tests.Runtimes.AzureFunction.csproj | 9 ++++-----
.../Dockerfile | 2 +-
.../host.json | 17 ++++++++++-------
.../Arcus.WebApi.Tests.Unit.csproj | 1 -
11 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/build/templates/run-docker-integration-tests.yml b/build/templates/run-docker-integration-tests.yml
index 718a3c66..013b8fd2 100644
--- a/build/templates/run-docker-integration-tests.yml
+++ b/build/templates/run-docker-integration-tests.yml
@@ -14,6 +14,8 @@ steps:
parameters:
dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction.Isolated'
port: '$(Arcus.AzureFunctions.Isolated.HttpPort)'
+ envVars: |
+ APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=$(Arcus.ApplicationInsights.InstrumentationKey)
- template: test/run-integration-tests.yml@templates
parameters:
dotnetSdkVersion: '$(DotNet.Sdk.Version)'
@@ -36,4 +38,4 @@ steps:
docker logs $(Project).Tests.Runtimes.AzureFunction.Isolated
failOnStderr: true
displayName: Show $(Project).Tests.Runtimes.AzureFunction.Isolated logs
- condition: always()
\ No newline at end of file
+ condition: always()
diff --git a/build/templates/start-docker-project.yml b/build/templates/start-docker-project.yml
index e9694a2f..98448eff 100644
--- a/build/templates/start-docker-project.yml
+++ b/build/templates/start-docker-project.yml
@@ -1,6 +1,7 @@
parameters:
dockerProjectName: ''
port: ''
+ envVars: {}
steps:
- bash: |
@@ -28,4 +29,5 @@ steps:
command: 'Run an image'
imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)'
containerName: '${{ parameters.dockerProjectName }}'
- ports: '${{ parameters.port }}:80'
\ No newline at end of file
+ ports: '${{ parameters.port }}:80'
+ envVars: ${{ parameters.envVars }}
\ No newline at end of file
diff --git a/src/Arcus.WebApi.Logging.AzureFunctions/Arcus.WebApi.Logging.AzureFunctions.csproj b/src/Arcus.WebApi.Logging.AzureFunctions/Arcus.WebApi.Logging.AzureFunctions.csproj
index 66c4a637..f8db9c66 100644
--- a/src/Arcus.WebApi.Logging.AzureFunctions/Arcus.WebApi.Logging.AzureFunctions.csproj
+++ b/src/Arcus.WebApi.Logging.AzureFunctions/Arcus.WebApi.Logging.AzureFunctions.csproj
@@ -27,9 +27,10 @@
+
-
-
+
+
diff --git a/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IFunctionsWorkerApplicationBuilderExtensions.cs b/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IFunctionsWorkerApplicationBuilderExtensions.cs
index 7a49594d..ad7ae63e 100644
--- a/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IFunctionsWorkerApplicationBuilderExtensions.cs
+++ b/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IFunctionsWorkerApplicationBuilderExtensions.cs
@@ -1,8 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Net;
using Arcus.Observability.Correlation;
-using Arcus.Observability.Telemetry.Core;
using Arcus.WebApi.Logging;
using Arcus.WebApi.Logging.AzureFunctions;
using Arcus.WebApi.Logging.AzureFunctions.Correlation;
@@ -10,7 +7,6 @@
using GuardNet;
using Microsoft.ApplicationInsights;
using Microsoft.Azure.Functions.Worker;
-using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -64,11 +60,8 @@ public static IFunctionsWorkerApplicationBuilder UseHttpCorrelation(
{
Guard.NotNull(builder, nameof(builder), "Requires a function worker builder instance to add the HTTP correlation middleware");
- builder.Services.AddLogging(logging =>
- {
- logging.AddApplicationInsightsWebJobs()
- .RemoveMicrosoftApplicationInsightsLoggerProvider();
- });
+ builder.Services.AddApplicationInsightsTelemetryWorkerService();
+ builder.Services.ConfigureFunctionsApplicationInsights();
builder.Services.AddSingleton>(provider => provider.GetRequiredService());
builder.Services.AddSingleton(provider => (ICorrelationInfoAccessor) provider.GetRequiredService());
diff --git a/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IServiceCollectionExtensions.cs b/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IServiceCollectionExtensions.cs
index 43840e37..d3a19aef 100644
--- a/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IServiceCollectionExtensions.cs
+++ b/src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IServiceCollectionExtensions.cs
@@ -82,4 +82,4 @@ public static IServiceCollection AddHttpCorrelation(this IFunctionsHostBuilder b
return services;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Arcus.WebApi.Tests.Integration/Arcus.WebApi.Tests.Integration.csproj b/src/Arcus.WebApi.Tests.Integration/Arcus.WebApi.Tests.Integration.csproj
index ec788ded..edcd8080 100644
--- a/src/Arcus.WebApi.Tests.Integration/Arcus.WebApi.Tests.Integration.csproj
+++ b/src/Arcus.WebApi.Tests.Integration/Arcus.WebApi.Tests.Integration.csproj
@@ -1,4 +1,4 @@
-
+
net8.0
diff --git a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction.Isolated/Dockerfile b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction.Isolated/Dockerfile
index 1e1d21b0..d0d800ff 100644
--- a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction.Isolated/Dockerfile
+++ b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction.Isolated/Dockerfile
@@ -19,4 +19,4 @@ FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
- AzureFunctionsJobHost__Logging__Console__IsEnabled=true
\ No newline at end of file
+ AzureFunctionsJobHost__Logging__Console__IsEnabled=true
diff --git a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Arcus.WebApi.Tests.Runtimes.AzureFunction.csproj b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Arcus.WebApi.Tests.Runtimes.AzureFunction.csproj
index ded97bbd..cfc173bd 100644
--- a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Arcus.WebApi.Tests.Runtimes.AzureFunction.csproj
+++ b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Arcus.WebApi.Tests.Runtimes.AzureFunction.csproj
@@ -2,14 +2,13 @@
net8.0
v4
+ /home/site/wwwroot
+ Linux
-
-
+
-
-
@@ -23,4 +22,4 @@
Never
-
\ No newline at end of file
+
diff --git a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Dockerfile b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Dockerfile
index d5a169fa..ec940c9e 100644
--- a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Dockerfile
+++ b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/Dockerfile
@@ -19,4 +19,4 @@ FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
- AzureFunctionsJobHost__Logging__Console__IsEnabled=true
\ No newline at end of file
+ AzureFunctionsJobHost__Logging__Console__IsEnabled=true
diff --git a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/host.json b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/host.json
index bb3b8dad..72d2d68c 100644
--- a/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/host.json
+++ b/src/Arcus.WebApi.Tests.Runtimes.AzureFunction/host.json
@@ -1,11 +1,14 @@
{
"version": "2.0",
- "logging": {
- "applicationInsights": {
- "samplingExcludedTypes": "Request",
- "samplingSettings": {
- "isEnabled": true
- }
- }
+ "logging": {
+ "logLevel": {
+ "default": "Trace"
+ },
+ "applicationInsights": {
+ "samplingExcludedTypes": "Request",
+ "samplingSettings": {
+ "isEnabled": true
+ }
}
+ }
}
\ No newline at end of file
diff --git a/src/Arcus.WebApi.Tests.Unit/Arcus.WebApi.Tests.Unit.csproj b/src/Arcus.WebApi.Tests.Unit/Arcus.WebApi.Tests.Unit.csproj
index c385d05c..5eae5229 100644
--- a/src/Arcus.WebApi.Tests.Unit/Arcus.WebApi.Tests.Unit.csproj
+++ b/src/Arcus.WebApi.Tests.Unit/Arcus.WebApi.Tests.Unit.csproj
@@ -23,7 +23,6 @@
-