Go Thrift M4
Latest commit 4ccc465 Aug 30, 2016 @jtolds jtolds add fraction to example
Permalink
Failed to load latest commit information.
gen-go
AUTHORS
LICENSE
README.md
backoff.go
collect.go
doc.go
http.go
httpctx17.go
httpctxgen.go.m4
httpxctx.go go 1.7 contexts Aug 18, 2016
rand.go
register.go
request.go rename to monkit May 31, 2016
scribe.go
scribe.thrift monitor2: reintegrate zipkin Aug 28, 2015
udp.go
zipkin.thrift

README.md

monkit-zipkin

A plugin for http://github.com/spacemonkeygo/monkit that supports Zipkin.

See the docs at http://godoc.org/gopkg.in/spacemonkeygo/monkit-zipkin.v2

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)
  ...
}

License

Copyright (C) 2016 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.