-
Notifications
You must be signed in to change notification settings - Fork 23
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 context for connect and close functions #77
add context for connect and close functions #77
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #77 +/- ##
==========================================
- Coverage 82.42% 82.20% -0.23%
==========================================
Files 7 7
Lines 717 736 +19
==========================================
+ Hits 591 605 +14
- Misses 93 96 +3
- Partials 33 35 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention that the Ctx methods take priority if both are non-nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about the context we pass here, and it seems that we don't use it in any of the package functions/methods. The main purpose is to pass it to the user's handlers. But then, I'm like: do we actually need this?
Do you want to wire in otel to these contexts? |
In DB driver, when we pass the context, driver can close the connection if context is Canceled or Done, but here we don't use context and that's my concern. We accept it and pass it through to handlers so they can do something with it. Is it good enough reason for this change? |
As @adamdecaf posted the whole point of passing through these contexts into the user defined handlers allows the user to pass through any values that they have attached to the context values. In Moov's internal case we attach our telemetry to contexts, so this allows us to attach child spans in the handlers to the root spans from calling Initially I had something like this (and something similar for OnClose):
this gets us most of the way, but produces a "dangling" span, so we cannot associate it with app startup, or if we just tried to reconnect, etc. I agree that we can enhance the use of the contexts that are being passed into these methods and look for cancelation, etc. However, given the context of the work that I am doing at the moment, that would fall out of scope for that. |
Sounds good. Can you pass the app-startup span we create to these calls? That span's End() is called when NewEnvironment returns. |
This adds functions:
ConnectCtx
CloseCtx
OnConnectCtx
OnCloseCtx
that mimic the same functions without
Ctx
but allow passing in a context object. This can be useful for adding telemetry, etc.I am not a huge fan of the names of things, but since I wanted to maintain backwards compatibility with the library I couldn't really figure out a better way to do this.