softwaremill / sttp

The Scala HTTP client you always wanted!
https://sttp.softwaremill.com
Apache License 2.0
1.44k stars 301 forks source link

Response with request tags #1436

Open sergio-margale opened 2 years ago

sergio-margale commented 2 years ago

In order to differentiate sttp prometheus metrics by external service I used to tag the request with the name of the external service, so then when creating the PrometheusBackend I could get the tag from the request and add it to the metric as a label.

my_service_sttp_requests_success_count_total{service="my_service", service_name="external-service-1"}
my_service_sttp_requests_success_count_total{service="my_service", service_name="external-service-2"}
...

Since 3.5.0 that's no longer possible for all metrics, as now responseToSuccessCounterMapper and responseToErrorCounterMapper are based on the Response.

Is there any plan to maybe add tags to the ResponseMetadata? Or is there maybe another way to achieve this?

adamw commented 2 years ago

Adding tags to Response would be tricky, but maybe we can extend RequestMetadata with tags so that Response.request would make it possible to read that. Maybe you'd like to attempt creating a PR?

sergio-margale commented 2 years ago

Tbh, I'm not sure if I can do it anytime soon

sergio-margale commented 2 years ago

I found 5 mins to at least do the first step :) https://github.com/softwaremill/sttp-model/pull/189