How to get metrics from outgoing requests per route whe using ochttp.Transpor?
lbeier opened this issue · 2 comments
Please answer these questions before submitting a bug report.
What version of OpenCensus are you using?
0.18.0
What version of Go are you using?
1.12.5
What did you do?
Created an HTTP client using ochttp.Transport
:
&http.Client{
Transport: &ochttp.Transport{
Propagation: &b3.HTTPFormat{},
},
}
What did you expect to see?
Stats about outgoing requests per route, such as:
opencensus_io_http_client_roundtrip_latency_bucket{http_client_method="GET",http_client_status="200",le="500", ---> http_server_route="/users/{UsersID}" <--- } 265
opencensus_io_http_client_roundtrip_latency_sum{http_client_method="GET",http_client_status="200", ---> http_server_route="/users/{UsersID}" <--- } 39628.590544999955
opencensus_io_http_client_roundtrip_latency_count{http_client_method="GET",http_client_status="200", ---> http_server_route="/users/{UsersID}" <--- } 278
What did you see instead?
The stats for the roundtrip (which I'm assuming are coming from ochttp.Transport
:
opencensus_io_http_client_roundtrip_latency_bucket{http_client_method="GET",http_client_status="200",le="500"} 265
opencensus_io_http_client_roundtrip_latency_sum{http_client_method="GET",http_client_status="200"} 39628.590544999955
opencensus_io_http_client_roundtrip_latency_count{http_client_method="GET",http_client_status="200"} 278
Right now the ochttp.DefaultClientViews don't export the path in the metric view. You can add it by doing something similar to this.
var (
ClientRoundtripLatencyDistribution = &view.View{
Name: "opencensus.io/http/client/roundtrip_latency",
Measure: ochttp.ClientRoundtripLatency,
Aggregation: ochttp.DefaultLatencyDistribution,
Description: "End-to-end latency, by HTTP method and response status",
TagKeys: []tag.Key{ochttp.KeyClientMethod, ochttp.KeyClientHost, ochttp.KeyClientPath, ochttp.KeyClientStatus},
}
ClientCompletedCount = &view.View{
Name: "opencensus.io/net/http/client/completed_count",
Measure: ochttp.ClientRoundtripLatency,
Aggregation: view.Count(),
Description: "Count of completed requests, by HTTP method and response status",
TagKeys: []tag.Key{ochttp.KeyClientMethod, ochttp.KeyClientHost, ochttp.KeyClientPath, ochttp.KeyClientStatus},
}
DefaultHttpClientViews = []*view.View{ClientCompletedCount, ClientRoundtripLatencyDistribution}
)
What im trying to investigate right now is how to understand if req.URL.Path
then replace it somehow... has anyone else found a solution to not having the metrics be super granular?
opencensus_io_http_client_completed_count{http_client_method="GET",http_client_status="200",, http_client_path="/users/42112f64-b2b0-4188-a429-2c292bc2d916"} 265
If you use something like Gorilla mux for your client routes you can use named routes logic.
An example adjusting OC span names to these routes can be found here:
https://github.com/basvanbeek/opencensus-gorilla_mux-example/blob/master/client/main.go
You can probably use this as basis for metrics tagging.