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

NLog 5.1.3 structured logs are not enriched by agent for APM Logs with Context #1609

Closed
the-Hill opened this issue May 6, 2023 · 4 comments
Labels
community To tag external issues and PRs feature request To tag an issue after triage that is a feature instead of TD

Comments

@the-Hill
Copy link

the-Hill commented May 6, 2023

Description
I just updated NLog from version 4.7.15 to 5.1.3 and noticed that some of my logs are no longer enriched for APM Logs with Context by the agent (eg no entity.guid).
Some structured NLog logs (https://github.com/NLog/NLog/wiki/How-to-use-structured-logging#using-structured-logging) are no longer enriched by the APM agent and accordingly cannot be traced. Sample log format: _logger.LogDebug("Start Request: {request}", request);
Also many logs from System and Microsoft which has variable context are no longer enriched. Sample: Hosting environment: Development from logger Microsoft.Hosting.Lifetime.

Expected Behavior
The logs that were enriched with NLog 4.7.15 shall be enriched with NLog 5.1.3.

Steps to Reproduce
Write structured NLog (https://github.com/NLog/NLog/wiki/How-to-use-structured-logging#using-structured-logging) like:
_logger.LogDebug("Start Request: {request}", request);

Your Environment
.NET 6
NLog 5.1.3
NLog.Extensions.Logging 5.2.3
NLog.Web.AspNetCore 5.2.3
Microsoft.Extensions.Logging 6.0.0
NewRelic.Agent 10.10.0

NLog config:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="info"
      internalLogFile="internal-nlog.txt">

    <extensions>
        <add assembly="NLog.Web.AspNetCore" />
    </extensions>

    <targets async="true">

        <target name="logconsole" xsi:type="Console">

            <layout xsi:type="JsonLayout">
                <attribute name="datetime" layout="${date}" />
                <attribute name="level" layout="${level}" />
                <attribute name="application" layout="${environment:APP_NAME:whenEmpty=${hostname}}" />
                <attribute name="environment" layout="${aspnet-environment}" />
                <attribute name="loggername" layout="${logger}" />
                <attribute name="message" layout="${message}" />
                <attribute name="exception" layout="${exception:format=@}" />

                <!--MDLC Properties-->
                <attribute name="scope.connection.id" layout="${scopeproperty:item=ConnectionId}" />
                <attribute name="scope.request.id" layout="${scopeproperty:item=RequestId}" />
                <attribute name="scope.request.path" layout="${scopeproperty:item=RequestPath}" />
                <attribute name="scope.action.id" layout="${scopeproperty:item=ActionId}" />
                <attribute name="scope.action.name" layout="${scopeproperty:item=ActionName}" />
            </layout>
        </target>

    </targets>
    <rules>
        <logger name="System.*" finalMinLevel="Warn" writeTo="logconsole" />
        <logger name="System.Net.Http.*" finalMinLevel="Info" writeTo="logconsole" />
        <logger name="Microsoft.*" finalMinLevel="Warn" writeTo="logconsole" />
        <logger name="Microsoft.Hosting.Lifetime*" finalMinLevel="Info" writeTo="logconsole" />

        <logger name="*" minlevel="Trace" writeTo="logconsole" />
    </rules>
</nlog>

Docker build file:

FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-bullseye-slim-arm64v8

WORKDIR /app
COPY ./app .

ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A}
ENV CORECLR_NEWRELIC_HOME=/app/newrelic
ENV CORECLR_PROFILER_PATH="/app/newrelic/linux-arm64/libNewRelicProfiler.so"

ENV NEW_RELIC_APPLICATION_LOGGING_ENABLED=true
ENV NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED=false
ENV NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED=true

EXPOSE 7190

ENTRYPOINT ["./com.Sample"]

Additional context
Related to #1459

@the-Hill the-Hill added the bug Something isn't working label May 6, 2023
@workato-integration
Copy link

@github-actions github-actions bot added the community To tag external issues and PRs label May 6, 2023
@nr-ahemsath
Copy link
Member

Thanks for taking the time to create an issue in our repo, @the-Hill. Based on the previous conversation in issue #1459, I believe this is a feature request for our agent, not a bug. I'll make sure our product management is aware of our agent's functionality gap for your use case and they will consider that when prioritizing our roadmap.

@nr-ahemsath nr-ahemsath added feature request To tag an issue after triage that is a feature instead of TD and removed bug Something isn't working labels May 8, 2023
@the-Hill
Copy link
Author

the-Hill commented May 9, 2023

Hello @nr-ahemsath according to .NET agent logs in context NLog 4.5+ (.NET Core) with .NET Agent v9.7.0+ should be supported.
NLog: 4.1+ (.NET Framework), 4.5+ (.NET Core). Requires .NET Agent v9.7.0+.

@tippmar-nr
Copy link
Member

Hi @the-Hill

We believe this issue was resolved with changes made a few months ago to our instrumentation of NLog.Extensions.Logging and Microsoft.Extensions.Logging - I created a test app using the latest .NET agent release along with the NLog configuration you provided and I'm seeing logs being fully enriched as expected.

Could you try upgrading to the latest release of the .NET Agent and verifying that you're also seeing the expected behavior? If there's still a problem, feel free to re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community To tag external issues and PRs feature request To tag an issue after triage that is a feature instead of TD
Projects
None yet
Development

No branches or pull requests

3 participants