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: throwing plug properly handled and returns 500 #411

Merged
merged 4 commits into from
Nov 12, 2024

Conversation

grzuy
Copy link
Contributor

@grzuy grzuy commented Oct 23, 2024

closes #410.

A re-worked attempt after #396, trying to improve it by taking some pieces from #398.

@grzuy grzuy changed the title fix: throwing plug returns 500 fix: throwing plug properly handled and returns 500 Oct 23, 2024
@grzuy grzuy force-pushed the throwing-plug branch 2 times, most recently from aa59606 to e58aeb7 Compare November 12, 2024 15:00

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Comment on lines 79 to 80
* `kind`: The kind of unexpected condition, typically `:exit`
* `exception`: The exception which caused this unexpected termination
* `kind`: The kind of unexpected condition, typically `:error` or `:throw`
* `reason`: The error reason. An Exception struct or the thrown value
Copy link
Owner

Choose a reason for hiding this comment

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

The rest of this PR looks great; these are the only two items I have issue with.

For better or worse, we've already baked in exception and exit in metadata, and downstream packages already depend on them. We can't change them without a major version bump and that's not happening for this.

I'd suggest:

  • Changing :error back to :exit and reason back to exception
  • Keeping :throw as a second valid value forkind
  • Adding a new :throw_value key to pass the thrown value if it's a throw

This is enough to be backwards compatible and still have sensible semantic here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback!

Sounds fair.

Related to this previous discussion, for what is worth, #398 (comment).

Will try adapt to something backwards-compatible.

Copy link
Contributor Author

@grzuy grzuy Nov 12, 2024

Choose a reason for hiding this comment

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

After digging into opentelemetry_bandit I realized it might be a problem to start emitting events of kind: :throw right now.

opentelemetry_bandit (actually opentelemetry_api) is expecting only exceptions structs: https://github.com/open-telemetry/opentelemetry-erlang/blob/a506d08e8439c353bbf8277a1ca619c668d125f8/apps/opentelemetry_api/lib/open_telemetry/span.ex#L138-L144.

The story is different for cowboy because it's using otel_span.erl, which actually handles gracefully different kinds (referred to as Class in there): https://github.com/open-telemetry/opentelemetry-erlang/blob/a506d08e8439c353bbf8277a1ca619c668d125f8/apps/opentelemetry_api/src/otel_span.erl#L239-L242.

Rolling back for now, to only emitting the same events as before this PR and later can tackle emitting new throw events in tandem with possible updates in opentelemetry_bandit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rolling back for now, to only emitting the same events as before this PR and later can tackle emitting new throw events in tandem with possible updates in opentelemetry_bandit.

e8239b6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After digging into opentelemetry_bandit I realized it might be a problem to start emitting events of kind: :throw right now.

opentelemetry_bandit (actually opentelemetry_api) is expecting only exceptions structs: https://github.com/open-telemetry/opentelemetry-erlang/blob/a506d08e8439c353bbf8277a1ca619c668d125f8/apps/opentelemetry_api/lib/open_telemetry/span.ex#L138-L144.

The story is different for cowboy because it's using otel_span.erl, which actually handles gracefully different kinds (referred to as Class in there): https://github.com/open-telemetry/opentelemetry-erlang/blob/a506d08e8439c353bbf8277a1ca619c668d125f8/apps/opentelemetry_api/src/otel_span.erl#L239-L242.

Rolling back for now, to only emitting the same events as before this PR and later can tackle emitting new throw events in tandem with possible updates in opentelemetry_bandit.

For the record: open-telemetry/opentelemetry-erlang#798.

Copy link
Contributor Author

@grzuy grzuy Jan 14, 2025

Choose a reason for hiding this comment

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

For the record, this PR is related to this thread.

@grzuy
Copy link
Contributor Author

grzuy commented Nov 12, 2024

Conflicts with main expected after #413 merged.
Solving soon.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@mtrudel
Copy link
Owner

mtrudel commented Nov 12, 2024

let me know when this is ready to stand for review again!

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@grzuy grzuy requested a review from mtrudel November 12, 2024 20:05
@mtrudel mtrudel merged commit a5da3ce into mtrudel:main Nov 12, 2024
22 of 27 checks passed
@grzuy grzuy deleted the throwing-plug branch November 12, 2024 22:06
@grzuy
Copy link
Contributor Author

grzuy commented Nov 12, 2024

Thank you 🙏

@mtrudel
Copy link
Owner

mtrudel commented Nov 13, 2024

Thank YOU! Sorry this took so long to get sorted; i've had my hands full with real world things and am finally getting back to being able to spend some time on Bandit. Thanks for the patience.

@grzuy
Copy link
Contributor Author

grzuy commented Nov 13, 2024

No worries!
Thanks for all your great work 💯

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.

Mishandled plug throw value
2 participants