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: Add environment name to logs and alerts #1446

Merged
merged 1 commit into from
Nov 13, 2024
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
2 changes: 1 addition & 1 deletion .azure/modules/functionApp/slackNotifier.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var query = '''
| where customDimensions.RequestPath !startswith "/health"
| summarize Count = count()
by
Environment = tostring(customDimensions.AspNetCoreEnvironment),
Environment = tostring(customDimensions.EnvironmentName),
Type = itemType,
problemId,
tostring(customDimensions.MessageTemplate),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="13.9.14" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0"/>
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/Digdir.Domain.Dialogporten.GraphQL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Warning()
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)
.CreateBootstrapLogger();
Expand Down Expand Up @@ -51,6 +52,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"launchUrl": "graphql",
"applicationUrl": "http://localhost:5181",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DOTNET_ENVIRONMENT": "Development"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Update environment variable in ChangeDataCapture project

The codebase shows inconsistent environment variable usage. While most projects use DOTNET_ENVIRONMENT, the ChangeDataCapture project still uses ASPNETCORE_ENVIRONMENT. This should be updated for consistency.

  • src/Digdir.Domain.Dialogporten.ChangeDataCapture/Properties/launchSettings.json needs to be updated to use DOTNET_ENVIRONMENT instead of ASPNETCORE_ENVIRONMENT
🔗 Analysis chain

Verify environment variable usage across configuration files

Let's ensure this change is consistently applied across all relevant configuration files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of ASPNETCORE_ENVIRONMENT
# and verify DOTNET_ENVIRONMENT is used consistently

echo "Checking for any remaining ASPNETCORE_ENVIRONMENT usage:"
rg -l "ASPNETCORE_ENVIRONMENT" --type json

echo -e "\nVerifying DOTNET_ENVIRONMENT usage in launch settings:"
fd "launchSettings.json" --type f --exec rg -l "DOTNET_ENVIRONMENT" {}

Length of output: 728


Script:

#!/bin/bash
# Let's check the content of the remaining ASPNETCORE_ENVIRONMENT file
echo "Content of file with ASPNETCORE_ENVIRONMENT:"
cat "src/Digdir.Domain.Dialogporten.ChangeDataCapture/Properties/launchSettings.json"

echo -e "\nChecking content of files using DOTNET_ENVIRONMENT:"
for file in $(fd "launchSettings.json" --type f); do
    echo -e "\n=== $file ==="
    cat "$file"
done

Length of output: 4541

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Digdir.Domain.Dialogporten.Janitor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Warning()
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(
TelemetryConfiguration.CreateDefault(),
Expand Down Expand Up @@ -51,6 +52,7 @@ static void BuildAndRun(string[] args)
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(
services.GetRequiredService<TelemetryConfiguration>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0"/>
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/Digdir.Domain.Dialogporten.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Warning()
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)
.CreateBootstrapLogger();
Expand Down Expand Up @@ -43,6 +44,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces));

builder.Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"commandName": "Project",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DOTNET_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:56841;http://localhost:56842"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0"/>
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/Digdir.Domain.Dialogporten.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Warning()
.Enrich.WithEnvironmentName()
.Enrich.FromLogContext()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)
Expand Down Expand Up @@ -61,6 +62,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
.MinimumLevel.Warning()
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.WithEnvironmentName()
.Enrich.FromLogContext()
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5123",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DOTNET_ENVIRONMENT": "Development"
}
},
"https": {
Expand All @@ -18,7 +18,7 @@
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7214;http://localhost:5123",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DOTNET_ENVIRONMENT": "Development"
}
}
}
Expand Down
Loading