-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: expose requestRecorder on locals or server and as export #48
Conversation
Codecov Report
@@ Coverage Diff @@
## master #48 +/- ##
==========================================
+ Coverage 99.22% 99.25% +0.03%
==========================================
Files 8 8
Lines 129 135 +6
Branches 12 12
==========================================
+ Hits 128 134 +6
Misses 1 1
|
This is amazing! Thanks so much for taking a look into this 🙏 To make this concrete, I can share my pre-existing
The relevant bit here is the So that I can access the metrics in other parts of my codebase I have this code:
Then, finally, I will have a utility like this in my
which then allows me to write network request code like this:
The idea here is that we'd like a metric for both inbound and outbound requests, and in my company these metrics both have identical definitions except that inbound requests have a role of @tdeekens, do you have different ideas on how this might best be achieved now you've seen something more concrete? |
Thanks, now I follow. Some thoughts:
Additionally, looking at your example of return axios
.get(url, updateOpts(options))
.then(createRequestObserver()) won't work as you have to take the start time before the Promise settles. I added an example to the readme in one of my last commits. Lastly, your example of return res => {
clientMetrics.requestLatencySecondsObserver(start, {
labels: {
// NOTE: I forgot to consider how I'd spread in the default set of labels here!
role: 'client',
},
}) is interesting but there is not much the library can help here as the request does not run through the express/Hapi you'd have to pass the default labels if you want them such as Can you verify that the changes on this PR suit your use case? Then I'd merge and release this. |
I renamed the request observer to request recorder. I found observer a bit misleading as it doesn't observe it just reports or records things. Observing would be more when it hooks into the Promise. Everything remains the same just: const { getRequestRecorder } = require('@promster/express'); changed. |
Hi @tdeekens, just been checking everything over on my end one last time, and I can confirm that this completely solves everything for me, plus cleans things up quite nicely what with the direct import and clearer naming; in the same spirit, I've even started directly importing Just want to say a massive thank you for the personal time you contributed here 🥇. I feel slightly guilty taking so much of your time up, so if you accept donations I'd be very happy to contribute ❤️. In case it helps others any, here's the code I've ended up with for a fully customized middleware plus some extra metrics in just a tiny bit of code (thanks NOTE: Updated as per advice in comments below
|
Glad it helps. Don't feel guilty. I enjoy these kind of things and expect this also to help others maybe even me. Regarding your code snippet: you should not import import { createMiddleware, getRequestRecorder, Prometheus } from '@promster/express' I've honestly never received a donation during three years of Open Source with about ten libraries and would not expect anybody to donate. However, if you would like to buy me a coffee through that I would be thankful (PayPal: |
This worked perfectly. Thanks again 👍, and some coffees are on their way... ☕️ |
Summary
This pull request adds exposing the
observeRequest
function (fromcreateRequestObserver
) on the locals or server (depending if express or Hapi).