-
Notifications
You must be signed in to change notification settings - Fork 3
/
doc.go
74 lines (60 loc) · 2.15 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2014 Space Monkey, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
Package zipkin provides a monkit plugin for sending traces to Zipkin.
Example usage
Your main method gets set up something like this:
package main
import (
"net/http"
"gopkg.in/spacemonkeygo/monkit-zipkin.v2"
"gopkg.in/spacemonkeygo/monkit.v2"
"gopkg.in/spacemonkeygo/monkit.v2/environment"
"gopkg.in/spacemonkeygo/monkit.v2/present"
)
func main() {
environment.Register(monkit.Default)
go http.ListenAndServe("localhost:9000", present.HTTP(monkit.Default))
collector, err := zipkin.NewScribeCollector("zipkin.whatever:9042")
if err != nil {
panic(err)
}
zipkin.RegisterZipkin(monkit.Default, collector, zipkin.Options{
Fraction: 1})
...
}
Once you've done that, you need to make sure your HTTP handlers pull Zipkin
Context info from the Request. That's easy to do with zipkin.ContextWrapper.
func HandleRequest(ctx context.Context, w http.ResponseWriter,
r *http.Request) {
defer mon.Task()(&ctx)(nil)
... whatever
}
func DoTheThing(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
return http.Serve(listener, zipkin.ContextWrapper(
zipkin.TraceHandler(zipkin.ContextHTTPHandlerFunc(HandleRequest))))
}
Last, your outbound HTTP requests need to pass through Context info:
func MakeRequest(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
req, err := http.NewRequest(...)
if err != nil {
return err
}
resp, err := zipkin.TraceRequest(ctx, http.DefaultClient, req)
...
}
*/
package zipkin // import "gopkg.in/spacemonkeygo/monkit-zipkin.v2"