Skip to content

Logging message from Otlp target is not picked up by LogRecord processor #29

@jundayin

Description

@jundayin

In our application we have several processors in place to process the LogRecord (mainly enrich them).

I'm doing the experiment and see how does it the target pacakge work with NLog, I do notice that our LogRecord processor in the application (not the one in OTEL collector) does not pick up the LogRecord and enrich them. Is this by design? Or a missing feature?

A sample repro
Program.cs

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder
                        .UseStartup<Startup>()
                        .ConfigureLogging(logging =>
                        {
                            logging.ClearProviders();
                            logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
                        })
                        .UseNLog();
                });

Startup.cs

services
    .AddOpenTelemetry()
    .WithLogging(builder =>
    {
        builder.AddProcessor<LogRecordTraceContextEnrichProcessor>();
        builder.AddProcessor<LogRecordExceptionParsingProcessor>();
       })

appSettings.json

  "NLog": {
    "autoReload": false,
    "throwConfigExceptions": true,
    "internalLogLevel": "Info",
    "extensions": [
      {
        "assembly": "NLog.Web.AspNetCore"
      },
      {
        "assembly": "NLog.Targets.OpenTelemetryProtocol"
      }
    ],
    "targets": {
      "consoleTarget": {
        "type": "ColoredConsole"
      },
      "otlp": {
        "type": "OtlpTarget",
        "resolveOptionsFromName": "Logging",
        "scheduledDelayMilliseconds": 1000
      }
    },
    "rules": [
      {
        "logger": "*",
        "minLevel": "Fatal",
        "writeTo": "consoleTarget"
      },
      {
        "logger": "*",
        "minLevel": "Info",
        "writeTo": "otlp"
      }
    ]
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions