Skip to content

Connect the Zap logger w/ the otel-go SDK error handler and internal logger #6717

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

Closed
wants to merge 1 commit into from

Conversation

jmacd
Copy link
Contributor

@jmacd jmacd commented Dec 9, 2022

Description:

When the OTel-Go metric SDK is configured behind the obsreport package, the logs and errors are not integrated with the collector's Zap logs. This change enables the OTel-Go SDK logs to go to the configured logger destination.

Link to tracking Issue:

Testing: Manual testing. I've run the OTel-Go feature-gate with this change.

@jmacd jmacd added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Dec 9, 2022
@jmacd jmacd requested review from a team and jpkrohling December 9, 2022 01:02
Comment on lines +131 to +134
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
logger.Error("OTel SDK error", zap.Error(err))
}))
otel.SetLogger(zapr.NewLogger(logger))
Copy link
Member

Choose a reason for hiding this comment

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

Very interesting choice of the logger implementation... I am a bit nervous about this extra dependency, but I think there is no other option...

question: If we set the logger, does otel not log the errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default, the built-in internal logger goes to the console. I don't have any examples lying around, and I would be OK not adopting this line as the error handler is more important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I've wanted to catch up with https://go.googlesource.com/proposal/+/master/design/56345-structured-logging.md, regarding logging APIs)

Copy link
Member

Choose a reason for hiding this comment

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

My question is, when you call otel.ErrorHandlerFunc do you not call the logger in advance? With this setup would errors going to be double logged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this is not the case. The default error handler uses the Go-1.0 log package, i.e., log.New(os.Stderr, "", log.LstdFlags), while the default internal logger uses logr's "stdr" package, i.e., stdr.New(log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile)).

I admit I'm not sure whether it's easy/difficult to double-log, but they appear separate. @MadVikingGod would you comment on whether this PR looks sane for a user of zap, to configure both error handler and logger?

Choose a reason for hiding this comment

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

There is no problem setting both. We prefer to use error handling to enable users to take action in response to errors. But nothing in the SDK should do both at the same time. Libraries outside of the base otel can't access the logging library.

I don't know about zap, but if you are looking for the info or debug logs you might need to increase zapr verbosity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that with my change, if the collector were configured for verbose logging, then otel-go's debug logging would begin to appear because zapr does the right thing (I haven't verified this). My secondary goal was to ensure consistent formatting w/ the configured logger. Thanks @MadVikingGod

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 18, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants