...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ochttp_test
16
17 import (
18 "log"
19 "net/http"
20
21 "go.opencensus.io/plugin/ochttp"
22 "go.opencensus.io/plugin/ochttp/propagation/b3"
23 "go.opencensus.io/stats/view"
24 "go.opencensus.io/tag"
25 )
26
27 func ExampleTransport() {
28
29
30
31
32
33 if err := view.Register(
34
35 ochttp.ClientSentBytesDistribution,
36 ochttp.ClientReceivedBytesDistribution,
37 ochttp.ClientRoundtripLatencyDistribution,
38
39 &view.View{
40 Name: "httpclient_latency_by_path",
41 TagKeys: []tag.Key{ochttp.KeyClientPath},
42 Measure: ochttp.ClientRoundtripLatency,
43 Aggregation: ochttp.DefaultLatencyDistribution,
44 },
45 ); err != nil {
46 log.Fatal(err)
47 }
48
49 client := &http.Client{
50 Transport: &ochttp.Transport{},
51 }
52
53
54 _ = client
55 }
56
57 var usersHandler http.Handler
58
59 func ExampleHandler() {
60
61
62 http.Handle("/users", ochttp.WithRouteTag(usersHandler, "/users"))
63
64
65 log.Fatal(http.ListenAndServe("localhost:8080", &ochttp.Handler{}))
66 }
67
68 func ExampleHandler_mux() {
69
70
71 mux := http.NewServeMux()
72 mux.Handle("/users", ochttp.WithRouteTag(usersHandler, "/users"))
73 log.Fatal(http.ListenAndServe("localhost:8080", &ochttp.Handler{
74 Handler: mux,
75 Propagation: &b3.HTTPFormat{},
76 }))
77 }
78
View as plain text