1 | 1 |
|
2 | 2 |
## Development and Testing Set-up
|
3 | 3 |
|
4 | |
Setting up [Zipkin] is not an easy thing to do. It will also demand quite some
|
5 | |
resources. To help you get started with development and testing we've made a
|
6 | |
docker-compose file available for running a full Zipkin stack.
|
|
4 |
Great efforts have been made to make [Zipkin] easier to test, develop and
|
|
5 |
experiment against. [Zipkin] can now be run from a single Docker container or by
|
|
6 |
running its self-contained executable jar without extensive configuration. In
|
|
7 |
its default configuration you will run Zipkin with a HTTP collector, In memory
|
|
8 |
Span storage backend and web UI on port 9411.
|
7 | 9 |
|
8 | |
You will need [docker-compose] 1.6.0+ and [docker-engine] 1.10.0+.
|
9 | |
|
10 | |
If running on Linux `HOSTNAME` can be set to `localhost`. If running on Mac OS X
|
11 | |
or Windows you probably need to set the hostname environment variable to the
|
12 | |
hostname of the VM running the docker containers.
|
13 | |
|
14 | |
```sh
|
15 | |
cd tracing/zipkin
|
16 | |
HOSTNAME=localhost docker-compose -f docker-compose-zipkin.yml up
|
|
10 |
Example:
|
|
11 |
```
|
|
12 |
docker run -d -p 9411:9411 openzipkin/zipkin
|
17 | 13 |
```
|
18 | 14 |
|
19 | |
[Zipkin]: http://zipkin.io/
|
20 | |
[docker-compose]: https://docs.docker.com/compose/
|
21 | |
[docker-engine]: https://docs.docker.com/engine/
|
|
15 |
[zipkin]: http://zipkin.io
|
22 | 16 |
|
23 | |
As mentioned the [Zipkin] stack is quite heavy and may take a few minutes to
|
24 | |
fully initialize.
|
25 | |
|
26 | |
The following services have been set-up to run:
|
27 | |
- Apache Cassandra (port: 9160 (thrift), 9042 (native))
|
28 | |
- Apache ZooKeeper (port: 2181)
|
29 | |
- Apache Kafka (port: 9092)
|
30 | |
- Zipkin Collector
|
31 | |
- Zipkin Query
|
32 | |
- Zipkin Web (port: 8080, 9990)
|
33 | |
|
|
17 |
Instrumenting your services with Zipkin distributed tracing using the default
|
|
18 |
configuration is now possible with the latest release of [zipkin-go-opentracing]
|
|
19 |
as it includes an HTTP transport for sending spans to the [Zipkin] HTTP
|
|
20 |
Collector.
|
34 | 21 |
|
35 | 22 |
## Middleware Usage
|
36 | 23 |
|
37 | 24 |
Follow the [addsvc] example to check out how to wire the Zipkin Middleware. The
|
38 | 25 |
changes should be relatively minor.
|
39 | 26 |
|
40 | |
The [zipkin-go-opentracing] package has support for Kafka and Scribe collectors
|
41 | |
as well as using Go Kit's [Log] package for logging.
|
|
27 |
The [zipkin-go-opentracing] package has support for HTTP, Kafka and Scribe
|
|
28 |
collectors as well as using Go Kit's [Log] package for logging.
|
|
29 |
|
|
30 |
### Configuring for the Zipkin HTTP Collector
|
|
31 |
|
|
32 |
To select the transport for the HTTP Collector, you configure the `Recorder`
|
|
33 |
with the appropriate collector like this:
|
|
34 |
|
|
35 |
```go
|
|
36 |
var (
|
|
37 |
debugMode = false
|
|
38 |
serviceName = "MyService"
|
|
39 |
serviceHostPort = "localhost:8000"
|
|
40 |
zipkinHTTPEndpoint = "localhost:9411"
|
|
41 |
)
|
|
42 |
collector, err = zipkin.NewHTTPCollector(zipkinHTTPEndpoint)
|
|
43 |
if err != nil {
|
|
44 |
// handle error
|
|
45 |
}
|
|
46 |
tracer, err = zipkin.NewTracer(
|
|
47 |
zipkin.NewRecorder(collector, debugMode, serviceHostPort, serviceName),
|
|
48 |
...
|
|
49 |
)
|
|
50 |
```
|
42 | 51 |
|
43 | 52 |
### Span per Node vs. Span per RPC
|
44 | 53 |
By default Zipkin V1 considers either side of an RPC to have the same identity
|
45 | 54 |
and differs in that respect from many other tracing systems which consider the
|
46 | |
caller to be the parent and the receiver the child. The OpenTracing
|
|
55 |
caller to be the parent and the receiver to be the child. The OpenTracing
|
47 | 56 |
specification does not dictate one model over the other, but the Zipkin team is
|
48 | 57 |
looking into these [single-host-spans] to potentially bring Zipkin more in-line
|
49 | 58 |
with the other tracing systems.
|
|
134 | 143 |
parentSpan := opentracing.SpanFromContext(ctx)
|
135 | 144 |
if parentSpan == nil {
|
136 | 145 |
parentSpan = opentracing.StartSpan(queryLabel)
|
|
146 |
defer parentSpan.Finish()
|
137 | 147 |
}
|
138 | 148 |
|
139 | 149 |
// create a new span to record the resource interaction
|