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

Skip ActivityData capture for NLog, since doing Layout capture #379

Merged
merged 2 commits into from
May 28, 2024

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Apr 20, 2024

When enabling writing on background-thread, then one should not capture the activity-traceid of the background-thread.

I guess Serilog has the same issue, since it relies on its enricher-capture (similar to NLog layout capture)

This is ofcourse a breaking change, since adding new property to existing interface IEcsDocumentCreationOptions. Maybe change to use enum-flag-values?

Alternative only perform automatic capture for Elastic.Extensions.Logging? (Skip helping NLog / Serilog / Log4net)

@snakefoot snakefoot force-pushed the net6 branch 2 times, most recently from cf1fd62 to 084a6c3 Compare May 4, 2024 15:06
@snakefoot snakefoot force-pushed the net6 branch 2 times, most recently from 439efad to f48620b Compare May 11, 2024 13:51
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

Thank you for covering this @snakefoot

This also needs some work on Serilog which i'll do in a separate PR.

It requires updating to Serilog 3.1 and updating our base TFM from net461 to 462.

AFAIK log4net appenders are synchronous so we should be okay there.

@Mpdreamz
Copy link
Member

run docs-build

@Mpdreamz
Copy link
Member

This is ofcourse a breaking change, since adding new property to existing interface IEcsDocumentCreationOptions. Maybe change to use enum-flag-values?

I am not concerned breaking this in a non major update.

Yes its breaking but the chances someone updating a shipper/formatter without updating Elastic.CommonSchema are slim IMO.

Copy link
Contributor

@gregkalapos gregkalapos left a comment

Choose a reason for hiding this comment

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

LGTM, with one small comment.


if (options?.IncludeHost is null or true) doc.Host = GetHost(initialCache);
if (options?.IncludeProcess is null or true) doc.Process = GetProcess(initialCache);
if (options?.IncludeUser is null or true) doc.User = GetUser();
if (options?.IncludeTraceId is null or true)
SetActivityData(doc);
Copy link
Contributor

Choose a reason for hiding this comment

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

The new ActivityExtensions.cs introduced here could be also used within SetActivityData - it has basically the same logic.

Copy link
Contributor Author

@snakefoot snakefoot May 28, 2024

Choose a reason for hiding this comment

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

@Mpdreamz Should I make the suggested change in this pull-request? It will complicate a little since ActivityExtensions.cs is right now isolated for the NLog, and will require shared code between projects (new public API)

Copy link
Member

Choose a reason for hiding this comment

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

Let's do it in a follow up PR 👍

It would be nice if they used the same logic across logging implementations.

ToString already calls ToHexString however we currently have different fallbacks if the format is not W3C or if it's null or empty.

@Mpdreamz Mpdreamz merged commit 6d61edb into elastic:main May 28, 2024
5 checks passed
@snakefoot
Copy link
Contributor Author

snakefoot commented May 28, 2024

@Mpdreamz This also needs some work on Serilog which i'll do in a separate PR.

I guess there are two directions:

@Mpdreamz
Copy link
Member

That enricher is deprecated and so I rather update to a more recent serilog :)

@Mpdreamz
Copy link
Member

Mpdreamz commented May 28, 2024

Actually @snakefoot I think we are good for Serilog:

https://github.com/serilog/serilog/blob/4ef3a8772c2dee065a5c6d5ac951f405b6c7ced4/src/Serilog/Core/Logger.cs#L427-L429

Dispatch calls Emit() which is where we do the Activity inspection so its on the same callstack.

Similar to why we are good for extensions logging.

@snakefoot
Copy link
Contributor Author

snakefoot commented May 28, 2024

Serilog has the ability (Like NLog) to render on background-thread. See also: serilog/serilog-sinks-async#93

But yes extensions logging is good.

@Mpdreamz
Copy link
Member

Yeah there really is no sense in using us with serilog-sinks-async, we already push our events over a channel that is being consumed in a background thread.

Will add an explicit note to our docs to not use us wrapped in the async sync.

@Mpdreamz
Copy link
Member

Ahhh sorry,

Elastic.CommonSchema.Serilog and using it with an async file sink is something we need to support.

Elastic.Serilog.Sinks should never be wrapped in an async sink.

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.

3 participants