diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/go.opencensus.io/plugin/ochttp/route.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/go.opencensus.io/plugin/ochttp/route.go')
-rw-r--r-- | vendor/go.opencensus.io/plugin/ochttp/route.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/go.opencensus.io/plugin/ochttp/route.go b/vendor/go.opencensus.io/plugin/ochttp/route.go new file mode 100644 index 0000000..dbe22d5 --- /dev/null +++ b/vendor/go.opencensus.io/plugin/ochttp/route.go | |||
@@ -0,0 +1,51 @@ | |||
1 | // Copyright 2018, OpenCensus Authors | ||
2 | // | ||
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | // you may not use this file except in compliance with the License. | ||
5 | // You may obtain a copy of the License at | ||
6 | // | ||
7 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | // | ||
9 | // Unless required by applicable law or agreed to in writing, software | ||
10 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | // See the License for the specific language governing permissions and | ||
13 | // limitations under the License. | ||
14 | |||
15 | package ochttp | ||
16 | |||
17 | import ( | ||
18 | "net/http" | ||
19 | |||
20 | "go.opencensus.io/tag" | ||
21 | ) | ||
22 | |||
23 | // WithRouteTag returns an http.Handler that records stats with the | ||
24 | // http_server_route tag set to the given value. | ||
25 | func WithRouteTag(handler http.Handler, route string) http.Handler { | ||
26 | return taggedHandlerFunc(func(w http.ResponseWriter, r *http.Request) []tag.Mutator { | ||
27 | addRoute := []tag.Mutator{tag.Upsert(KeyServerRoute, route)} | ||
28 | ctx, _ := tag.New(r.Context(), addRoute...) | ||
29 | r = r.WithContext(ctx) | ||
30 | handler.ServeHTTP(w, r) | ||
31 | return addRoute | ||
32 | }) | ||
33 | } | ||
34 | |||
35 | // taggedHandlerFunc is a http.Handler that returns tags describing the | ||
36 | // processing of the request. These tags will be recorded along with the | ||
37 | // measures in this package at the end of the request. | ||
38 | type taggedHandlerFunc func(w http.ResponseWriter, r *http.Request) []tag.Mutator | ||
39 | |||
40 | func (h taggedHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
41 | tags := h(w, r) | ||
42 | if a, ok := r.Context().Value(addedTagsKey{}).(*addedTags); ok { | ||
43 | a.t = append(a.t, tags...) | ||
44 | } | ||
45 | } | ||
46 | |||
47 | type addedTagsKey struct{} | ||
48 | |||
49 | type addedTags struct { | ||
50 | t []tag.Mutator | ||
51 | } | ||