Closed maxcnunes closed 5 years ago
cc @achille-roussel @rjenkins
@maxcnunes thank you for this. @achille-roussel I'm wondering if it would be cleaner to extend the API to allow the user to provide a func that will get called back with the necessary data they might need to compute the tags? However, this might expose some internals.
@maxcnunes FYI I talked to @achille-roussel offline and he said he'll be commenting on the approach shortly.
hey @achille-roussel any news on this? I was thinking, another approach would be to extract that logic in the RoadTrip into something like a span which we call before running the request and providing the request instance as an argument and after the response had been executed and then providing the response instance to it. It would require more steps to use it, but at least it would provide an API to report an outgoing request metric. Something like this:
span := httpstats.StartOutgoingRequestSpan(req)
res, err := client.Do(req)
span.Finish(res) // span.FinishWithTags(res, customTags)
Also, I'm worried what is the memory cost for creating a new engine withWithTags
for every request just so I can add tags such as endpoint
, request_source
, direction:outgoing
. Wouldn't be more eficient if we made requestBody and responseBody public and they had meta interface{}
field so we could add custom tags to it using the field tags?
Btw, I willing to help implementing any solution :)
@achille-roussel have you had a chance to give this some thought?
Hi I reissued this PR from the fork we used at InVisionApp's repo: https://github.com/segmentio/stats/pull/104. It was updated with these changes.
Did #104 work for you over at InvisionApp @mnichols @maxcnunes ? Can we close this?
Going to close this for now. I think both #104 and #111 together should satisfy this use case. Thanks!
As reported on https://github.com/segmentio/stats/issues/93 and documented in Go api it seems to be a bad practice using a new client/transport instance on every request.
https://golang.org/pkg/net/http/#Client
and
So, a solution that came to my mind is passing the tags by Context and creating the stats engine with thos provided tags during the round trip.
I would like to get a feedback if segmentio team is interested on this changes before adding the proper documentation and tests for this change.