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

[docs] Add exception logging best practices #6037

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CodeBlanch
Copy link
Member

Changes

  • Show the correct way to log exceptions in the best-practices doc
  • Reorganize things a bit to improve the flow

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)

@CodeBlanch CodeBlanch requested a review from a team as a code owner December 17, 2024 19:23
@github-actions github-actions bot added the documentation Documentation related label Dec 17, 2024
> [!NOTE]
> When using the compile-time source generator the first `Exception` parameter
> detected is automatically given special handling. It **SHOULD NOT** be part of
> the message template.
Copy link
Contributor

Choose a reason for hiding this comment

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

Few users may find it difficult to understand what we mean as message template. An example or calling it out would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a link to runtime docs for more details. Think that will be enough?

docs/logs/README.md Outdated Show resolved Hide resolved
> the message template.

:heavy_check_mark: You should use the dedicated overloads to log exceptions when
using the logging extensions methods.
Copy link
Member

Choose a reason for hiding this comment

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

since we recommended against using extension methods in earlier section of the doc, lets not talk about it further :)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a tough one. I don't disagree with you necessarily, but I see this mistake being made with users migrating to ILogger who are doing find/replace type of things (not taking the source generator). Perhaps we should soften the recommendation for source generator? It is great for high-perf. But users may not care and prefer the more concise syntax. There are also cases where high-perf probably doesn't matter. For example, startup/shutdown logging.

Copy link
Member

Choose a reason for hiding this comment

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

Even .NET docs show both slow way and fast way, so we may not be able to completely get rid of extension methods from the docs, agree!

You want to use the correct `Exception` APIs because the OpenTelemetry
Specification [defines dedicated
attributes](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/exceptions/exceptions-logs.md)
for `Exception` details. The following examples show what **NOT** to do. In
Copy link
Member

Choose a reason for hiding this comment

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

If a user does not want to get the stack details (due to cost etc.), then there is no opt-out mechanism today, so this maybe a viable workaround folks can use today. i.e they send ex.msg, and ex.type as normal parameters, and not pass in the exception object...

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. Probably doesn't belong in best practices though. What if we put that somewhere with more advanced content or somewhere showing customizations?

Copy link
Member

Choose a reason for hiding this comment

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

That'd be good (move it elsewhere)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants