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

fix: Don't fatal error when we can return an error #36

Merged
merged 2 commits into from
May 3, 2023

Conversation

kentquirk
Copy link
Contributor

Which problem is this PR solving?

Calling this code:

	otelshutdown, err := otelconfig.ConfigureOpenTelemetry(
                 otelconfig.WithExporterProtocol(otelconfig.ProtocolHTTPJSON)))

Crashes with a fatal error, even though the function returns an error.

It would be nice to be able to catch this error and handle it in my app appropriately.

Short description of the changes

Return a wrapped error instead of crashing. Note that this also affects other setup-type errors that are currently fatally crashing, and required reworking some tests.

How to verify that this has the expected result

Run the tests, or the code above; err should come back as non-nil and it shouldn't crash.

@kentquirk kentquirk requested a review from a team May 2, 2023 18:28
@kentquirk kentquirk changed the title bug: Don't fatal error when we can return an error fix: Don't fatal error when we can return an error May 2, 2023
@kentquirk kentquirk added the merge at will Reviewer can merge the PR once reviewed. label May 2, 2023
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks good to me. I agree with returning errors instead of crashing the process 😬

@@ -625,8 +625,7 @@ func ConfigureOpenTelemetry(opts ...Option) (func(), error) {
for _, setup := range []setupFunc{setupTracing, setupMetrics} {
shutdown, err := setup(c)
if err != nil {
c.Logger.Fatalf("setup error: %v", err)
continue
return otelConfig.Shutdown, fmt.Errorf("setup error: %w", err)
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith May 3, 2023

Choose a reason for hiding this comment

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

Do you think it would be worth capturing all the errors from the for loop, combing them and returning a single error?

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 didn't see it as worthwhile, since upstream would have to be told to expect some form of multierror. I saw this loop as simple convenience and considered even unrolling it. But I can do that if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think returning early is fine. Thanks for putting together 👍🏻

@MikeGoldsmith MikeGoldsmith merged commit 22a3a1a into main May 3, 2023
@MikeGoldsmith MikeGoldsmith deleted the kent.no_fatality_yet branch May 3, 2023 14:22
@vreynolds
Copy link
Contributor

@MikeGoldsmith for releasing purposes, is this a patch/bugfix you think?

@vreynolds vreynolds added version: bump minor A PR that adds behavior, but is backwards-compatible. type: enhancement New feature or request labels May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge at will Reviewer can merge the PR once reviewed. type: enhancement New feature or request version: bump minor A PR that adds behavior, but is backwards-compatible.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants