Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade to observability v2.5 in Azure Functions project templates #645

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions build/templates/docker-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ stages:
projectAlias: 'arcus-servicebus-queue'
ports: '$(Arcus.ServiceBus.Queue.Worker.HealthPort):$(Arcus.ServiceBus.Queue.Worker.HealthPort)'
script: |
Get-Content './Arcus.Demo.ServiceBus.Queue/Program.cs' |
Where-Object { $_ -notmatch '#error' -and $_ -notmatch 'secretProvider: null' -and $_ -notmatch 'EmptyMessageHandler' -and $_ -notmatch 'AddServiceBusQueueMessagePump' } |
Where-Object { $_ -notmatch 'AddAzureKeyVaultWithManagedIdentity' -and $_ -notmatch '#if DEBUG' -and $_ -notmatch '#endif' } |
Get-Content './Arcus.Demo.ServiceBus.Queue/Program.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
Set-Content './Arcus.Demo.ServiceBus.Queue/Program.cs'
envVars: |
ARCUS_HEALTH_PORT=$(Arcus.ServiceBus.Queue.Worker.HealthPort)
Expand All @@ -59,9 +58,8 @@ stages:
projectAlias: 'arcus-servicebus-topic'
ports: '$(Arcus.ServiceBus.Topic.Worker.HealthPort):$(Arcus.ServiceBus.Topic.Worker.HealthPort)'
script: |
Get-Content './Arcus.Demo.ServiceBus.Topic/Program.cs' |
Where-Object { $_ -notmatch '#error' -and $_ -notmatch 'secretProvider: null' -and $_ -notmatch 'EmptyMessageHandler' -and $_ -notmatch 'AddServiceBusTopicMessagePump' } |
Where-Object { $_ -notmatch 'AddAzureKeyVaultWithManagedIdentity' -and $_ -notmatch '#if DEBUG' -and $_ -notmatch '#endif' } |
Get-Content './Arcus.Demo.ServiceBus.Topic/Program.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
Set-Content './Arcus.Demo.ServiceBus.Topic/Program.cs'
envVars: |
ARCUS_HEALTH_PORT=$(Arcus.ServiceBus.Topic.Worker.HealthPort)
Expand All @@ -75,21 +73,21 @@ stages:
projectAlias: 'arcus-az-databricks-jobmetrics'
ports: '$(Arcus.AzureFunctions.Databricks.HttpPort):80'
script: |
Get-Content './Arcus.Demo.AzureFunctions.Databricks.JobMetrics/Startup.cs' |
Where-Object { $_ -notmatch '#error' } |
Get-Content './Arcus.Demo.AzureFunctions.Databricks.JobMetrics/Startup.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
Set-Content './Arcus.Demo.AzureFunctions.Databricks.JobMetrics/Startup.cs'
envVars: |
Arcus__Databricks__Url=$(Arcus.Databricks.Url)
Arcus__ApplicationInsights__MetricName=$(Arcus.ApplicationInsights.MetricName)
APPLICATIONINSIGHTS_INSTRUMENTATIONKEY=$(Arcus.ApplicationInsights.InstrumentationKey)
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=$(Arcus.ApplicationInsights.InstrumentationKey)
- template: 'run-new-project-from-template.yml'
parameters:
projectName: 'Arcus.Demo.AzureFunctions.Http'
projectAlias: 'arcus-az-func-http'
ports: '$(Arcus.AzureFunctions.Http.HttpPort):80'
script: |
Get-Content './Arcus.Demo.AzureFunctions.Http/Startup.cs' |
Where-Object { $_ -notmatch '#error' } |
Get-Content './Arcus.Demo.AzureFunctions.Http/Startup.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
Set-Content './Arcus.Demo.AzureFunctions.Http/Startup.cs'
envVars: |
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=$(Arcus.ApplicationInsights.InstrumentationKey)
Expand All @@ -99,24 +97,24 @@ stages:
projectAlias: 'arcus-az-func-servicebus-queue'
ports: '$(Arcus.AzureFunctions.ServiceBus.Queue.Port):$(Arcus.AzureFunctions.ServiceBus.Queue.Port)'
script: |
Get-Content './Arcus.Demo.AzureFunctions.ServiceBus.Queue/Startup.cs' |
Where-Object { $_ -notmatch '#error' } |
Get-Content './Arcus.Demo.AzureFunctions.ServiceBus.Queue/Startup.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
Set-Content './Arcus.Demo.AzureFunctions.ServiceBus.Queue/Startup.cs'
envVars: |
ServiceBusConnectionString=$(Arcus.Worker.ServiceBus.Queue.ConnectionString)
APPINSIGHTS_INSTRUMENTATIONKEY=$(Arcus.ApplicationInsights.InstrumentationKey)
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=$(Arcus.ApplicationInsights.InstrumentationKey)
- template: 'run-new-project-from-template.yml'
parameters:
projectName: 'Arcus.Demo.AzureFunctions.ServiceBus.Topic'
projectAlias: 'arcus-az-func-servicebus-topic'
ports: '$(Arcus.AzureFunctions.ServiceBus.Topic.Port):$(Arcus.AzureFunctions.ServiceBus.Topic.Port)'
script: |
Get-Content './Arcus.Demo.AzureFunctions.ServiceBus.Topic/Startup.cs' |
Where-Object { $_ -notmatch '#error' } |
Get-Content './Arcus.Demo.AzureFunctions.ServiceBus.Topic/Startup.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
Set-Content './Arcus.Demo.AzureFunctions.ServiceBus.Topic/Startup.cs'
envVars: |
ServiceBusConnectionString=$(Arcus.Worker.ServiceBus.Topic.ConnectionString)
APPINSIGHTS_INSTRUMENTATIONKEY=$(Arcus.ApplicationInsights.InstrumentationKey)
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=$(Arcus.ApplicationInsights.InstrumentationKey)
- task: UseDotNet@2
displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))'
inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@

<ItemGroup>
<PackageReference Include="Arcus.BackgroundJobs.Databricks" Version="0.4.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.AzureFunctions" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Filters" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.Applicationinsights" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Filters" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.Applicationinsights" Version="2.5.0" />
<PackageReference Include="Arcus.Security.AzureFunctions" Version="1.7.0" />
<PackageReference Include="Arcus.Security.Providers.AzureKeyVault" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public override void Configure(IFunctionsHostBuilder builder)

private static LoggerConfiguration CreateLoggerConfiguration(IFunctionsHostBuilder builder)
{
IConfiguration appConfig = builder.GetContext().Configuration;
var configuration = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithComponentName("Azure Databricks Metrics Scraper")
.Enrich.WithVersion()
.WriteTo.Console();

IConfiguration appConfig = builder.GetContext().Configuration;
var instrumentationKey = appConfig.GetValue<string>("APPINSIGHTS_INSTRUMENTATIONKEY");
if (!string.IsNullOrWhiteSpace(instrumentationKey))
var connectionString = appConfig.GetValue<string>("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (!string.IsNullOrWhiteSpace(connectionString))
{
configuration.WriteTo.AzureApplicationInsights(instrumentationKey);
configuration.WriteTo.AzureApplicationInsightsWithConnectionString(connectionString);
}

return configuration;
Expand Down
4 changes: 2 additions & 2 deletions src/Arcus.Templates.AzureFunctions.Http/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public override void Configure(IFunctionsHostBuilder builder)

private static LoggerConfiguration CreateLoggerConfiguration(IFunctionsHostBuilder builder)
{
IConfiguration appConfig = builder.GetContext().Configuration;
var configuration = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithComponentName("Azure HTTP Trigger")
.Enrich.WithVersion()
.WriteTo.Console();

IConfiguration appConfig = builder.GetContext().Configuration;
var connectionString = appConfig.GetValue<string>("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (!string.IsNullOrWhiteSpace(connectionString))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
<ItemGroup>
<PackageReference Include="Arcus.Messaging.Abstractions.ServiceBus" Version="1.2.0" />
<PackageReference Include="Arcus.Messaging.AzureFunctions.ServiceBus" Version="1.2.0" />
<PackageReference Include="Arcus.Observability.Correlation" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Correlation" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.AzureFunctions" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Filters" Version="2.4.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="2.4.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Filters" Version="2.5.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="2.5.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Security.AzureFunctions" Version="1.7.0" />
<PackageReference Include="Arcus.Security.Providers.AzureKeyVault" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
Expand Down
10 changes: 5 additions & 5 deletions src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public override void Configure(IFunctionsHostBuilder builder)

private static LoggerConfiguration CreateLoggerConfiguration(IFunctionsHostBuilder builder)
{
IConfiguration appConfig = builder.GetContext().Configuration;
var logConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithComponentName("Service Bus Queue Trigger")
.Enrich.WithVersion()
.WriteTo.Console();

IConfiguration appConfig = builder.GetContext().Configuration;
var instrumentationKey = appConfig.GetValue<string>("APPINSIGHTS_INSTRUMENTATIONKEY");
if (!string.IsNullOrWhiteSpace(instrumentationKey))
var connectionString = appConfig.GetValue<string>("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (!string.IsNullOrWhiteSpace(connectionString))
{
logConfig.WriteTo.AzureApplicationInsights(instrumentationKey);
logConfig.WriteTo.AzureApplicationInsightsWithConnectionString(connectionString);
}

return logConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
<ItemGroup>
<PackageReference Include="Arcus.Messaging.Abstractions.ServiceBus" Version="1.2.0" />
<PackageReference Include="Arcus.Messaging.AzureFunctions.ServiceBus" Version="1.2.0" />
<PackageReference Include="Arcus.Observability.Correlation" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Correlation" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.AzureFunctions" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="2.4.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Filters" Version="2.4.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="2.4.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="2.5.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Filters" Version="2.5.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="2.5.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Arcus.Security.AzureFunctions" Version="1.7.0" />
<PackageReference Include="Arcus.Security.Providers.AzureKeyVault" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
Expand Down
10 changes: 5 additions & 5 deletions src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public override void Configure(IFunctionsHostBuilder builder)

private static LoggerConfiguration CreateLoggerConfiguration(IFunctionsHostBuilder builder)
{
IConfiguration appConfig = builder.GetContext().Configuration;
var logConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithComponentName("Service Bus Topic Trigger")
.Enrich.WithVersion()
.WriteTo.Console();

IConfiguration appConfig = builder.GetContext().Configuration;
var instrumentationKey = appConfig.GetValue<string>("APPINSIGHTS_INSTRUMENTATIONKEY");
if (!string.IsNullOrWhiteSpace(instrumentationKey))
var connectionString = appConfig.GetValue<string>("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (!string.IsNullOrWhiteSpace(connectionString))
{
logConfig.WriteTo.AzureApplicationInsights(instrumentationKey);
logConfig.WriteTo.AzureApplicationInsightsWithConnectionString(connectionString);
}

return logConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.11.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" Condition="'$(Serilog)' == 'true'" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/Arcus.Templates.ServiceBus.Queue/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ public static IHostBuilder CreateHostBuilder(string[] args)

private static async Task ConfigureSerilogAsync(IHost host)
{
var appConfiguration = host.Services.GetRequiredService<IConfiguration>();
var secretProvider = host.Services.GetRequiredService<ISecretProvider>();
string connectionString = await secretProvider.GetRawSecretAsync(ApplicationInsightsConnectionStringKeyName);

var reloadLogger = (ReloadableLogger) Log.Logger;
reloadLogger.Reload(config =>
{
config.MinimumLevel.Debug()
config.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.11.0" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" Condition="'$(Serilog)' == 'true'" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" Condition="'$(Serilog)' == 'true'" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Arcus.Templates.ServiceBus.Topic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static async Task ConfigureSerilogAsync(IHost host)
var reloadLogger = (ReloadableLogger) Log.Logger;
reloadLogger.Reload(config =>
{
config.MinimumLevel.Debug()
config.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace Arcus.Templates.Tests.Integration.AzureFunctions
/// </summary>
public abstract class AzureFunctionsProject : TemplateProject
{
protected const string ApplicationInsightsInstrumentationKeyVariable = "APPINSIGHTS_INSTRUMENTATIONKEY",
ApplicationInsightsConnectionStringKeyVariable = "APPLICATIONINSIGHTS_CONNECTION_STRING";
protected const string ApplicationInsightsConnectionStringKeyVariable = "APPLICATIONINSIGHTS_CONNECTION_STRING";

private static readonly HttpClient HttpClient = new HttpClient();

Expand Down Expand Up @@ -109,7 +108,6 @@ protected override ProcessStartInfo PrepareProjectRun(
};
Logger.WriteLine("> {0} {1}", processInfo.FileName, processInfo.Arguments);

Environment.SetEnvironmentVariable(ApplicationInsightsInstrumentationKeyVariable, ApplicationInsightsConfig.InstrumentationKey);
Environment.SetEnvironmentVariable(ApplicationInsightsConnectionStringKeyVariable, $"InstrumentationKey={ApplicationInsightsConfig.InstrumentationKey}");
return processInfo;
}
Expand Down Expand Up @@ -164,7 +162,6 @@ await Policy.TimeoutAsync(TimeSpan.FromSeconds(30))
/// <param name="disposing">The flag indicating whether or not the additional tasks should be disposed.</param>
protected override void Disposing(bool disposing)
{
Environment.SetEnvironmentVariable(ApplicationInsightsInstrumentationKeyVariable, null);
Environment.SetEnvironmentVariable(ApplicationInsightsConnectionStringKeyVariable, null);
}
}
Expand Down