census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.05k stars 326 forks source link

Add FormatStatsPath to ochttp Transport to reduce stats path cardinality #1229

Open otternq opened 3 years ago

otternq commented 3 years ago

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)
}
googlebot commented 3 years ago

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.

otternq commented 3 years ago

@googlebot I signed it!

googlebot commented 3 years ago

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.