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

Logging loop with n log sentry #1824

Merged
merged 14 commits into from Jul 28, 2022
Merged

Logging loop with n log sentry #1824

merged 14 commits into from Jul 28, 2022

Conversation

SimonCropp
Copy link
Contributor

@SimonCropp SimonCropp commented Jul 28, 2022

although this is not the exact scenario as #1741 as #1701, it is the same root cause. essentially when inside logging we have anything that causes a log event it results in an infinite loop. in #1701

  • NLog.SentryTarget.Write occurs
  • Scope.Evaluate occurs
  • triggering AspNetCore.SentryMiddleware which is failing
  • triggering NLog.SentryTarget.Write
  • repeat

@SimonCropp SimonCropp marked this pull request as draft July 28, 2022 06:09
@getsentry getsentry deleted a comment from github-actions bot Jul 28, 2022
@SimonCropp SimonCropp marked this pull request as ready for review July 28, 2022 11:46
Copy link
Member

@bruno-garcia bruno-garcia 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 fixing this Simon!

@SimonCropp
Copy link
Contributor Author

i work around this with an asynclocal. can anyone think of a better approach?

@mattjohnsonpint
Copy link
Contributor

i work around this with an asynclocal. can anyone think of a better approach?

Yes. We can use NLog's built-in context for this. See my update, and LMK if you agree. Thanks.

@SimonCropp
Copy link
Contributor Author

@mattjohnsonpint much nicer. thanks

@SimonCropp SimonCropp merged commit f2cda27 into main Jul 28, 2022
@SimonCropp SimonCropp deleted the Logging-loop-with-NLog-Sentry branch July 28, 2022 20:24
@snakefoot
Copy link
Contributor

snakefoot commented Jul 30, 2022

Think it is a bad idea to "abuse" the NLog ScopeContext to protect against bad calling pattern. The NLog ScopeContext is for the user to capture application-state, not for secret infrastructure problems. Just like you hopefully won't "abuse" the Serilog LogContext for injecting special context values.

If you really insist on abusing the NLog NestedDiagnosticsLogicalContext, then you should render the Sentry-LogEvent outside this secret-scope. As layouts depending on ${ndlc} will have side-effects from this usage.

But I recommend that you keep the special infrastructure problems secret, and use a local AsyncLocal-member-variable.

@mattjohnsonpint
Copy link
Contributor

@snakefoot that's a good point.

@SimonCropp - let's go back to the async local approach you had. Thanks.

@SimonCropp
Copy link
Contributor Author

done #1830

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.

Logging loop with NLog-Sentry
4 participants