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

Conversation

MagnusSandgren
Copy link
Collaborator

@MagnusSandgren MagnusSandgren commented Nov 13, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced logging capabilities across various projects by integrating environment-specific information.
    • Updated Slack Notifier function app configuration for improved environment categorization and accessibility.
  • Bug Fixes

    • Corrected environment variable usage from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT for consistency across projects.
  • Documentation

    • Maintained Swagger documentation setup and improved logging details in application initialization.
  • Chores

    • Added necessary package references for Serilog.Enrichers.Environment to multiple projects.

@MagnusSandgren MagnusSandgren requested review from a team as code owners November 13, 2024 09:02
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

📝 Walkthrough

Walkthrough

This pull request introduces several modifications across multiple projects, focusing on enhancing logging capabilities and updating configurations for environment handling. Key changes include updating the Bicep template for the Slack Notifier function app to modify environment name extraction and enhance resource definitions. Additionally, several projects have added a new package reference for Serilog.Enrichers.Environment, and logging configurations have been updated to include environment name enrichment. The environment variable used in launch settings has been changed from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT.

Changes

File Change Summary
.azure/modules/functionApp/slackNotifier.bicep Updated query variable to reference customDimensions.EnvironmentName; defined applicationServicePlan with new sku structure; added publicNetworkAccess to functionApp; configured notifyDevTeam resource to use functionApp.properties.defaultHostName.
src/Digdir.Domain.Dialogporten.GraphQL/Digdir.Domain.Dialogporten.GraphQL.csproj Added package reference for Serilog.Enrichers.Environment version 3.0.1.
src/Digdir.Domain.Dialogporten.GraphQL/Program.cs Enhanced logging configuration with .Enrich.WithEnvironmentName().
src/Digdir.Domain.Dialogporten.GraphQL/Properties/launchSettings.json Updated environment variable from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT.
src/Digdir.Domain.Dialogporten.Janitor/Digdir.Domain.Dialogporten.Janitor.csproj Added package reference for Serilog.Enrichers.Environment version 3.0.1.
src/Digdir.Domain.Dialogporten.Janitor/Program.cs Enhanced logging configuration with .Enrich.WithEnvironmentName().
src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj Added package reference for Serilog.Enrichers.Environment version 3.0.1.
src/Digdir.Domain.Dialogporten.Service/Program.cs Enhanced logging configuration with .Enrich.WithEnvironmentName().
src/Digdir.Domain.Dialogporten.Service/Properties/launchSettings.json Updated environment variable from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT.
src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj Added package reference for Serilog.Enrichers.Environment version 3.0.1.
src/Digdir.Domain.Dialogporten.WebApi/Program.cs Enhanced logging configuration with .Enrich.WithEnvironmentName().
src/Digdir.Domain.Dialogporten.WebApi/Properties/launchSettings.json Updated environment variable from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT.

Possibly related PRs

Suggested reviewers

  • oskogstad
  • knuhau

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
src/Digdir.Domain.Dialogporten.Service/Program.cs (1)

47-47: LGTM! Consider standardizing environment property name.

The environment name enrichment is correctly added to the main logger configuration.

Consider standardizing the environment property name in the log output by configuring it explicitly:

-        .Enrich.WithEnvironmentName()
+        .Enrich.WithEnvironmentName()
+        .Enrich.WithProperty("EnvironmentContext", Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"))

This would provide consistent environment naming across your logging infrastructure and make it easier to query logs based on environment.

.azure/modules/functionApp/slackNotifier.bicep (1)

Line range hint 1-240: Consider adding documentation for security configurations.

The template includes several security-related configurations (HTTPS, OAuth, TLS, public network access). Consider adding inline documentation explaining:

  • Why public network access is required
  • The security measures in place
  • The exception filtering strategy in the query
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d289e10 and ebedf2b.

📒 Files selected for processing (12)
  • .azure/modules/functionApp/slackNotifier.bicep (1 hunks)
  • src/Digdir.Domain.Dialogporten.GraphQL/Digdir.Domain.Dialogporten.GraphQL.csproj (1 hunks)
  • src/Digdir.Domain.Dialogporten.GraphQL/Program.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.GraphQL/Properties/launchSettings.json (1 hunks)
  • src/Digdir.Domain.Dialogporten.Janitor/Digdir.Domain.Dialogporten.Janitor.csproj (1 hunks)
  • src/Digdir.Domain.Dialogporten.Janitor/Program.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj (1 hunks)
  • src/Digdir.Domain.Dialogporten.Service/Program.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Service/Properties/launchSettings.json (1 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj (1 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Program.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Properties/launchSettings.json (2 hunks)
🔇 Additional comments (17)
src/Digdir.Domain.Dialogporten.Service/Properties/launchSettings.json (2)

12-12: LGTM: Added newline at end of file

The addition of a newline at the end of the file follows standard file formatting practices.


7-7: Verify environment variable usage across the application

The change from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT follows modern .NET practices and is more appropriate for generic .NET applications. However, we should ensure this change is consistently applied.

src/Digdir.Domain.Dialogporten.GraphQL/Properties/launchSettings.json (1)

11-11: LGTM! The environment variable change aligns with .NET best practices.

The change from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT follows Microsoft's recommended approach for .NET 6+ applications and maintains consistency with other projects in the solution.

src/Digdir.Domain.Dialogporten.WebApi/Properties/launchSettings.json (2)

11-11: LGTM! Good practice using DOTNET_ENVIRONMENT

The change from ASPNETCORE_ENVIRONMENT to DOTNET_ENVIRONMENT aligns with modern .NET practices and is more appropriate for generic .NET applications.

Also applies to: 21-21


11-11: Verify environment variable handling in application code

Ensure that the application code properly reads from DOTNET_ENVIRONMENT instead of ASPNETCORE_ENVIRONMENT.

Also applies to: 21-21

✅ Verification successful

Let me try a different search pattern to verify the environment variable handling.


Let me search for environment-related code in the startup configurations.


Based on the search results, I can now provide a final response:

Environment variable configuration is correctly handled

The codebase properly uses the standard .NET environment configuration pattern through IHostEnvironment and does not rely on direct environment variable access. The DOTNET_ENVIRONMENT setting in launchSettings.json is the correct variable to use as it's the default environment variable that .NET Core uses for non-ASP.NET Core applications.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the codebase correctly handles the DOTNET_ENVIRONMENT variable
# and doesn't have leftover references to ASPNETCORE_ENVIRONMENT

# Search for environment variable usage in C# files
echo "Checking for environment variable usage patterns..."
rg -t cs "(?:ASPNETCORE|DOTNET)_ENVIRONMENT" -A 3

# Look for specific environment configuration patterns
echo "Checking environment configuration patterns..."
ast-grep --pattern 'IHostEnvironment.$_' 
ast-grep --pattern 'IWebHostEnvironment.$_'

Length of output: 356


Script:

#!/bin/bash
# Search for environment-related configuration and startup code
echo "Checking Program.cs and Startup.cs files..."
fd -e cs "Program|Startup" --exec cat {}

echo "Checking configuration and environment setup..."
rg -t cs "CreateHostBuilder|ConfigureWebHostDefaults|UseEnvironment|GetEnvironmentVariable" -A 3

echo "Checking appsettings files for environment references..."
fd "appsettings" --exec cat {}

Length of output: 84667


Script:

#!/bin/bash
# Search for environment configuration in Program.cs and related files
echo "Checking for environment configuration in startup code..."
rg -t cs "IWebHostEnvironment|IHostEnvironment|Environment\." -A 3

# Search for environment variable usage
echo "Checking for environment variable usage..."
rg -t cs "DOTNET_ENVIRONMENT|ASPNETCORE_ENVIRONMENT" --type-add "json:*.{json,jsonc}" -g "!**/bin/*" -g "!**/obj/*"

Length of output: 14378

src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj (1)

5-5: LGTM! Package addition aligns with PR objectives.

The addition of Serilog.Enrichers.Environment package is appropriate for enriching logs with environment information.

Let's verify package compatibility:

✅ Verification successful

✅ Package version is consistent across all projects

The verification confirms that:

  • Serilog.Enrichers.Environment package is consistently used with version 3.0.1 across all projects
  • It's properly integrated alongside Serilog.Sinks.ApplicationInsights, indicating good compatibility with the logging infrastructure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify package versions and compatibility across projects
# Expected: Consistent versions of Serilog.Enrichers.Environment and compatible Serilog packages

# Check for Serilog.Enrichers.Environment usage across projects
echo "Checking Serilog.Enrichers.Environment usage:"
rg -l "Serilog\.Enrichers\.Environment"

# Check for version consistency
echo -e "\nChecking version consistency:"
rg -A 1 '<PackageReference Include="Serilog\.Enrichers\.Environment"' --type csproj

Length of output: 656


Script:

#!/bin/bash
# Let's try a different approach to check version consistency
# Search for PackageReference lines in all .csproj files containing Serilog.Enrichers.Environment

# First find all .csproj files
fd '\.csproj$' --exec grep -A 1 'Serilog\.Enrichers\.Environment' {}

Length of output: 693

src/Digdir.Domain.Dialogporten.GraphQL/Digdir.Domain.Dialogporten.GraphQL.csproj (1)

13-13: LGTM! Package addition aligns with PR objectives.

The addition of Serilog.Enrichers.Environment package will enable environment name enrichment in logs, which is consistent with the PR's goal.

Let's verify version compatibility with other Serilog packages:

✅ Verification successful

Let me generate one more verification script to check the current Serilog version in the project to ensure compatibility:


Let me try one more search with a broader pattern to understand the Serilog package ecosystem in the project:


Version compatibility verified - package addition is safe

The Serilog.Enrichers.Environment 3.0.1 package is compatible with:

  • .NET 8.0 (project's target framework)
  • Other Serilog packages in use (AspNetCore 8.0.3, ApplicationInsights 4.0.0)
  • The package is consistently used across multiple projects in the solution
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check version compatibility between Serilog packages
# Expected: No known compatibility issues between versions

# Check latest versions and release dates
curl -s https://api.nuget.org/v3/registration5-semver1/serilog.enrichers.environment/index.json | jq -r '.items[0].items[].catalogEntry | select(.version=="3.0.1") | {version, published}'
curl -s https://api.nuget.org/v3/registration5-semver1/serilog.aspnetcore/index.json | jq -r '.items[0].items[].catalogEntry | select(.version=="8.0.3") | {version, published}'
curl -s https://api.nuget.org/v3/registration5-semver1/serilog.sinks.applicationinsights/index.json | jq -r '.items[0].items[].catalogEntry | select(.version=="4.0.0") | {version, published}'

# Check dependencies
curl -s https://api.nuget.org/v3/registration5-semver1/serilog.enrichers.environment/index.json | jq -r '.items[0].items[].catalogEntry | select(.version=="3.0.1") | .dependencyGroups'

Length of output: 3904


Script:

#!/bin/bash
# Check Serilog version in the project
rg -U 'PackageReference Include="Serilog".*Version="([^"]+)"' -g '*.csproj'

Length of output: 77


Script:

#!/bin/bash
# Check all Serilog-related package references
rg -U 'PackageReference Include="Serilog[^"]*"' -g '*.csproj'

Length of output: 2715

src/Digdir.Domain.Dialogporten.Janitor/Digdir.Domain.Dialogporten.Janitor.csproj (1)

21-21: LGTM! Package addition aligns with logging enhancement objectives.

The addition of Serilog.Enrichers.Environment package is correct and uses the latest stable version, consistent with other Serilog packages in the project.

Let's verify the logger configuration in Program.cs:

✅ Verification successful

Environment enricher is properly configured and integrated

The verification confirms:

  • Environment enricher is correctly configured in both bootstrap and main logger setup
  • Environment variable DOTNET_ENVIRONMENT is properly set in launchSettings.json
  • The implementation aligns with the package addition
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the environment enricher is properly configured in Program.cs

# Check if Program.cs contains the environment enricher configuration
rg -A 5 "\.Enrich\.WithEnvironmentName\(\)" "src/Digdir.Domain.Dialogporten.Janitor/Program.cs"

# Also verify the environment variable usage
rg "DOTNET_ENVIRONMENT" "src/Digdir.Domain.Dialogporten.Janitor/Properties/launchSettings.json"

Length of output: 740

src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj (1)

17-17: LGTM! Package addition aligns with PR objectives.

The addition of Serilog.Enrichers.Environment package will enable environment name enrichment in logs, which is consistent with the PR's goal of adding environment names to logs and alerts.

Let's verify the version compatibility with other Serilog packages:

✅ Verification successful

Package version is compatible and consistently used across projects

The Serilog.Enrichers.Environment package (v3.0.1) is used consistently across multiple projects in the solution:

  • Digdir.Domain.Dialogporten.Janitor
  • Digdir.Domain.Dialogporten.WebApi
  • Digdir.Domain.Dialogporten.GraphQL
  • Digdir.Domain.Dialogporten.Service

It's also compatible with other Serilog packages in use:

  • Serilog.AspNetCore (8.0.3)
  • Serilog.Sinks.ApplicationInsights (4.0.0)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check version compatibility between Serilog packages
# Expected: No known compatibility issues between versions

# Check dependencies of Serilog.Enrichers.Environment 3.0.1
curl -s https://api.nuget.org/v3/registration5-gz-semver2/serilog.enrichers.environment/3.0.1.json | jq -r '.packageContent' | xargs curl -s | jq '.dependencyGroups'

# Check if there are any reported issues linking these specific versions
gh api graphql -f query='
{
  search(query: "repo:serilog/serilog-enrichers-environment is:issue label:compatibility", type: ISSUE, first: 5) {
    nodes {
      ... on Issue {
        title
        state
        url
      }
    }
  }
}'

Length of output: 588


Script:

#!/bin/bash
# Let's check for Serilog package references in the project file
rg -U "PackageReference.*Serilog.*Version" src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj

# Also check if this package is referenced in other project files
fd -e csproj -x rg -l "Serilog.Enrichers.Environment"

Length of output: 754

src/Digdir.Domain.Dialogporten.Janitor/Program.cs (2)

18-18: Verify Serilog.Enrichers.Environment package dependency

The environment name enrichment is correctly added to the bootstrap logger configuration.

Let's verify the package reference is properly added:

✅ Verification successful

Let me try a different search pattern to find the package reference.


Package dependency verified, environment enrichment properly configured

The Serilog.Enrichers.Environment package (version 3.0.1) is correctly referenced in the project file, and the environment name enrichment is properly added to the bootstrap logger configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if Serilog.Enrichers.Environment package is referenced
# Expected: Find the package reference in the project file

rg -l "Serilog\.Enrichers\.Environment" --type csproj

Length of output: 891


Script:

#!/bin/bash
# Search for Serilog.Enrichers.Environment in csproj files
rg -l "PackageReference.*Serilog\.Enrichers\.Environment" --type csproj

# Also check the package references in the project file directly
cat src/Digdir.Domain.Dialogporten.Janitor/Digdir.Domain.Dialogporten.Janitor.csproj

Length of output: 1837


55-55: Verify environment variable configuration

The environment name enrichment is correctly added to the main logger configuration, maintaining consistency with the bootstrap logger.

Let's verify the environment variable configuration:

✅ Verification successful

Let me check the content of the Janitor project's launchSettings.json to verify the environment configuration.


Environment configuration is properly set up

The environment name enrichment is well-supported by the configuration:

  • DOTNET_ENVIRONMENT is correctly configured in launchSettings.json
  • Environment-specific appsettings files exist for all environments (Development, Production, Staging, Test, YT01)
  • The logger will correctly pick up the environment name from these configurations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check environment variable configuration
# Expected: Find references to DOTNET_ENVIRONMENT in configuration files

# Check for environment variable configuration
rg -l "DOTNET_ENVIRONMENT|ASPNETCORE_ENVIRONMENT" --type json --type xml

# Check for any launch settings files
fd "launchSettings.json"

Length of output: 891


Script:

#!/bin/bash
# Check the content of launchSettings.json for Janitor project
cat "src/Digdir.Domain.Dialogporten.Janitor/Properties/launchSettings.json"

# Also check for any appsettings files that might contain environment configurations
fd "appsettings" "src/Digdir.Domain.Dialogporten.Janitor"

Length of output: 751

src/Digdir.Domain.Dialogporten.Service/Program.cs (1)

19-19: LGTM! Verify environment variable configuration.

The environment name enrichment is correctly added to the bootstrap logger configuration.

Let's verify the environment variable configuration:

✅ Verification successful

Environment variable configuration verified and consistent

The environment enrichment is correctly configured:

  • All services except ChangeDataCapture are using DOTNET_ENVIRONMENT
  • Development environment is properly set in launch settings
  • The environment name enrichment will work as expected with the configured environment variables
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for environment variable configuration in launch settings and configuration files

# Check launch settings for DOTNET_ENVIRONMENT
echo "Checking launch settings for environment configuration..."
fd --type f launchSettings.json --exec rg -l "DOTNET_ENVIRONMENT|ASPNETCORE_ENVIRONMENT" {}

# Check configuration files for environment-related settings
echo "Checking configuration files..."
fd --type f "appsettings*.json" --exec rg -l "Environment" {}

Length of output: 726


Script:

#!/bin/bash
# Let's check the content of launchSettings.json files to verify environment configuration
echo "Checking launchSettings.json content for environment variables..."
fd launchSettings.json --exec cat {}

# Also check for any environment-related configuration in Program.cs
echo -e "\nChecking Program.cs for environment configuration..."
rg -A 5 "DOTNET_ENVIRONMENT|ASPNETCORE_ENVIRONMENT" src/Digdir.Domain.Dialogporten.Service/Program.cs

Length of output: 2474

src/Digdir.Domain.Dialogporten.GraphQL/Program.cs (2)

27-27: LGTM! Environment enrichment added to bootstrap logger.

The addition of environment name enrichment to the bootstrap logger ensures that startup errors will include environment context, improving debugging capabilities.


55-55: LGTM! Environment enrichment added to main logger configuration.

The addition of environment name enrichment to the main logger configuration ensures consistent environment context across all application logs, which aligns with the PR objective of enhancing logging capabilities.

.azure/modules/functionApp/slackNotifier.bicep (1)

168-168: Verify alert functionality with the new environment name field.

The change from AspNetCoreEnvironment to EnvironmentName aligns with the broader changes in the codebase. However, we should ensure this doesn't break existing alerts.

✅ Verification successful

Change from AspNetCoreEnvironment to EnvironmentName is safe and aligned with the alert configuration

The change to use customDimensions.EnvironmentName in the alert query is correct and matches the existing alert configuration. The query is already using EnvironmentName for environment filtering in the exception monitoring alert rule, so this change maintains consistency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if both old and new environment fields are present in logs
# to ensure smooth transition and no alert disruption

# Check Application Insights logs for both field names
gh api graphql -f query='
{
  repository(owner: "digdir", name: "dialogporten") {
    object(expression: "main") {
      ... on Commit {
        tree {
          entries {
            name
            object {
              ... on Blob {
                text
              }
            }
          }
        }
      }
    }
  }
}' | jq -r '.data.repository.object.tree.entries[] | select(.name | contains(".cs")) | .object.text' | \
rg -A 5 'WithEnvironmentName|DOTNET_ENVIRONMENT|ASPNETCORE_ENVIRONMENT'

Length of output: 505


Script:

#!/bin/bash
# Let's check the Bicep files for environment-related configurations and alerts
rg -A 5 -B 5 "AspNetCoreEnvironment|EnvironmentName" --type bicep

# Also check for any alert or monitoring related configurations
rg -A 10 "Scheduled Query Rule|Action Group|alert" --type bicep

Length of output: 193


Script:

#!/bin/bash
# Let's check the Bicep files for environment-related configurations and alerts without specifying file type
rg -A 5 -B 5 "AspNetCoreEnvironment|EnvironmentName" .azure/

# Also check for any alert or monitoring related configurations
rg -A 10 "Scheduled Query Rule|Action Group|alert" .azure/

Length of output: 33965


Script:

#!/bin/bash
# Let's check the query definition and alert rules to understand the environment field usage
rg -A 20 -B 5 "traces.*where.*Environment" .azure/

# Also check for any existing alert configurations
rg -A 10 "Scheduled Query Rule|metric alert" .azure/

Length of output: 107


Script:

#!/bin/bash
# Let's examine the full query context in the slackNotifier.bicep file
cat .azure/modules/functionApp/slackNotifier.bicep

Length of output: 7134

src/Digdir.Domain.Dialogporten.WebApi/Program.cs (2)

32-32: LGTM! Environment name enrichment added to bootstrap logger.

The addition of environment name enrichment to the bootstrap logger configuration is correctly placed and aligns with the PR objectives.


65-65: LGTM! Environment name enrichment added to main logger configuration.

The addition of environment name enrichment to the main logger configuration is consistent with the bootstrap logger changes and correctly implements the PR objectives.

@@ -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

@MagnusSandgren MagnusSandgren merged commit 96d4583 into main Nov 13, 2024
24 checks passed
@MagnusSandgren MagnusSandgren deleted the chore/add-environement-name-to-logs branch November 13, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants