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

Add ErrorHandlerFunc to simplify creating ErrorHandlers #2149

Merged
merged 5 commits into from
Aug 3, 2021

Conversation

yvrhdn
Copy link
Contributor

@yvrhdn yvrhdn commented Jul 31, 2021

This PR adds a convenience adapter to simplify setting the error handler.

Code before:

func main() {
	otel.SetErrorHandler(myErrorHandler{})

	// ...
}

type myErrorHandler struct {}

func (h myErrorHandler) Handle(err error) {
	// your custom error handling
	level.Error(log.Logger).Log("msg", "OpenTelemetry.ErrorHandler", "err", err)
}

After:

func main() {
	otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
		// your custom error handling
		level.Error(log.Logger).Log("msg", "OpenTelemetry.ErrorHandler", "err", err)
	}))

	// ...
}

@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #2149 (4790a33) into main (23cb939) will increase coverage by 0.0%.
The diff coverage is 0.0%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2149   +/-   ##
=====================================
  Coverage   72.2%   72.2%           
=====================================
  Files        169     170    +1     
  Lines      12074   12076    +2     
=====================================
+ Hits        8724    8727    +3     
  Misses      3109    3109           
+ Partials     241     240    -1     
Impacted Files Coverage Δ
error_handler.go 0.0% <0.0%> (ø)
...s/otlp/otlptrace/internal/connection/connection.go 16.4% <0.0%> (+1.5%) ⬆️

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Outside of minor doc changes, I think these changes are a good addition.

CHANGELOG.md Outdated Show resolved Hide resolved
error_handler.go Outdated Show resolved Hide resolved
error_handler.go Outdated Show resolved Hide resolved
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@yvrhdn
Copy link
Contributor Author

yvrhdn commented Aug 3, 2021

Thanks for the suggestion @MrAlias!

@MrAlias MrAlias merged commit 21d4686 into open-telemetry:main Aug 3, 2021
@yvrhdn yvrhdn deleted the error-handler-func branch August 3, 2021 23:12
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