opencensus-go icon indicating copy to clipboard operation
opencensus-go copied to clipboard

Add FormatStatsPath to ochttp Transport to reduce stats path cardinality

Open otternq opened this issue 4 years ago • 3 comments

Updates ochttp.Transport to accept an optional FormatStatsPath which is supplied to ochttp.statsTransport. FormatStatsPath can override a request URL's path parameter to reduce cardinality for stats similar to FormatSpanName.

This should be useful when a resource id is part of a request path such as /posts/1 or /posts/2. Currently each resource is treated as a unique path but it would be nice to optionally treat these requests as a single path.

Without FormatStatsPath specified

2020/10/01 09:02:59 	Row: 0: &view.Row{
    Tags:[]tag.Tag{
        tag.Tag{Key:tag.Key{name:"http_client_host"}, Value:"jsonplaceholder.typicode.com"}, 
        tag.Tag{Key:tag.Key{name:"http_client_method"}, Value:"GET"}, 
        tag.Tag{Key:tag.Key{name:"http_client_path"}, Value:"/posts/2"}, 
        tag.Tag{Key:tag.Key{name:"http_client_status"}, Value:"200"}
    }, 
    Data:(*view.CountData)(0xc00035c080)
}
2020/10/01 09:02:59 	Row: 1: &view.Row{
    Tags:[]tag.Tag{
        tag.Tag{Key:tag.Key{name:"http_client_host"}, Value:"jsonplaceholder.typicode.com"}, 
        tag.Tag{Key:tag.Key{name:"http_client_method"}, Value:"GET"}, 
        tag.Tag{Key:tag.Key{name:"http_client_path"}, Value:"/posts/1"}, 
        tag.Tag{Key:tag.Key{name:"http_client_status"}, Value:"200"}
    }, 
    Data:(*view.CountData)(0xc00035c100)
}

With FormatStatsPath specified

2020/10/01 09:06:48 	Row: 0: &view.Row{
    Tags:[]tag.Tag{
        tag.Tag{Key:tag.Key{name:"http_client_host"}, Value:"jsonplaceholder.typicode.com"}, 
        tag.Tag{Key:tag.Key{name:"http_client_method"}, Value:"GET"}, 
        tag.Tag{Key:tag.Key{name:"http_client_path"}, Value:"/posts/:id"}, 
        tag.Tag{Key:tag.Key{name:"http_client_status"}, Value:"200"}
    }, 
    Data:(*view.DistributionData)(0xc0001181b0)
}

otternq avatar Oct 01 '20 16:10 otternq

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

googlebot avatar Oct 01 '20 16:10 googlebot

@googlebot I signed it!

otternq avatar Oct 01 '20 16:10 otternq

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

googlebot avatar Oct 01 '20 16:10 googlebot