Instrumentation: phoenix multiple endpoints support #537
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
👋
First of all thank you a lot for your awesome work everyone 💚
The diff here is a bit more brutal than what actually is happening, to ease review the implementation is also split up into 2 commits.
Problem to fix
An application has multiple endpoints all using the same webserver (scenario: one for API, one for web). I had noticed that traces/spans weren't recorded correctly and the current span context wasn't set.
After some debugging I noticed that the root cause to the best of my ability is the little fix I did to
lib
- it seems to me that one would need to callOpentelemetryPhoenix.setup()
multiple times - with the adequateevent_prefixes
.However, that does not work since the
:telemetry.attach
call inside it used the static id of{__MODULE__, :endpoint_start}
which means that subsequent handlers would not be attached. This showed itself in the behavior that setting up more than one in our application never worked.Proposed fix
I propose the fix here to make the
endpoint_prefix
part of the telemetry handler id. This makes sense to me, as each one of those listens to different events so being their own separate entity makes sense. This also keeps the same API and just allows you to call it multiple times. Due to theid-centric
behavior of:telemetry
other handlers won't be attached twice or thrice (i.e. router_start_handler will only be attached once). Hence, I think this ifs fine.Noise around the fix
I wanted to test this all and for the tests to show it (much to my surprise bandit worked without the fix 🤔 ).
As such, I extended the test to setup one additional "endpoint variant" each, defining the modules and everything. To support that, I needed to move some code around. The new endpoints are always defined, but only started in my added tests.
I tried not to change as much. I'm also not 100% happy with the data structure I ended up with but it seems to work so far.
Thank you for your consideration and all your work! 💚