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

[BUG] EcsTextFormatter doesn't use the IHostingEnvironment concept in dotnet core #355

Open
HHobeck opened this issue Jan 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@HHobeck
Copy link

HHobeck commented Jan 19, 2024

ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog):
I'm using the Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog (8.6.1) to output my logs in the ECS standard.

ECS schema version (e.g. 1.4.0):
The ecs.version is 8.6.0

ECS .NET assembly version (e.g. 1.4.2):
Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog (8.6.1)

Elasticsearch version (if applicable):
n/a

.NET framework / OS:
.net 6.0

Description of the problem, including expected versus actual behavior:
Depending on the stage I run my application in different environements like Testing, Staging or Production. There are different ways doing this:

  • setup the environment variable with DOTNET_ENVIRONEMENT={STAGE}
  • start the application with the argument parameter --environment {STAGE}

Anyway in microsoft dotnet we have the concept of IHostBuilder who is responsible to setup the IHostingEnvironment. I would expect that in the log output the application name and the application environment will be used from IHostingEnvironment if no other variables like ELASTIC_APM_ENVIRONMENT, OTEL_RESOURCE_ATTRIBUTES or deployment.environment variables are existing.

Starting a console application could be look like on windows:
$ ./JustAApplication.Console.exe --environment Testing --applicationName JustAnother.Application

Actual behaviour of the log output:

{
    "service": {
        "name": "JustAApplication.Console",
        "type": "dotnet",
        "version": "1.0.0"
    },
...
}

Expected behaviour of the log output:

{
    "service": {
        "name": "JustAnother.Application",
        "environment": "Testing",
        "type": "dotnet",
        "version": "1.0.0"
    },
...
}

Steps to reproduce:

  1. Start a dotnet application using Host.CreateDefaultBuilder(arguments).Run();
  2. Log an output using the ECS standard with Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog
  3. view the logs and you see that service.environment is not present and the service.name is not like ApplicationName
@HHobeck HHobeck added the bug Something isn't working label Jan 19, 2024
@HHobeck HHobeck changed the title [BUG] [BUG] EcsTextFormatter doesn't use the IHostingEnvironment concept in dotnet core Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant