-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zipkin native instrumentation using zipkin-go #2
Changes from 2 commits
0dc1263
367c60a
c633c28
2593fe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ import ( | |
"github.com/apache/thrift/lib/go/thrift" | ||
lightstep "github.com/lightstep/lightstep-tracer-go" | ||
stdopentracing "github.com/opentracing/opentracing-go" | ||
zipkin "github.com/openzipkin/zipkin-go-opentracing" | ||
zipkin "github.com/openzipkin/zipkin-go" | ||
zipkinot "github.com/openzipkin/zipkin-go-opentracing" | ||
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" | ||
"sourcegraph.com/sourcegraph/appdash" | ||
appdashot "sourcegraph.com/sourcegraph/appdash/opentracing" | ||
|
||
|
@@ -40,9 +42,10 @@ func main() { | |
thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") | ||
thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") | ||
thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") | ||
zipkinURL = fs.String("zipkin-url", "", "Enable Zipkin tracing via a collector URL e.g. http://localhost:9411/api/v1/spans") | ||
lightstepToken = flag.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") | ||
appdashAddr = flag.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") | ||
zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) via HTTP Reporter URL e.g. http://localhost:94111/api/v2/spans") | ||
zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) via a collector URL e.g. http://localhost:9411/api/v1/spans") | ||
lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") | ||
appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") | ||
method = fs.String("method", "sum", "sum, concat") | ||
) | ||
fs.Usage = usageFor(fs, os.Args[0]+" [flags] <a> <b>") | ||
|
@@ -54,35 +57,55 @@ func main() { | |
|
||
// This is a demonstration client, which supports multiple tracers. | ||
// Your clients will probably just use one tracer. | ||
var tracer stdopentracing.Tracer | ||
var otTracer stdopentracing.Tracer | ||
{ | ||
if *zipkinURL != "" { | ||
collector, err := zipkin.NewHTTPCollector(*zipkinURL) | ||
if *zipkinV1URL != "" { | ||
collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(1) | ||
} | ||
defer collector.Close() | ||
var ( | ||
debug = false | ||
hostPort = "localhost:80" | ||
serviceName = "addsvc" | ||
hostPort = "localhost:0" | ||
serviceName = "addsvc-cli" | ||
) | ||
recorder := zipkin.NewRecorder(collector, debug, hostPort, serviceName) | ||
tracer, err = zipkin.NewTracer(recorder) | ||
recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) | ||
otTracer, err = zipkinot.NewTracer(recorder) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(1) | ||
} | ||
} else if *lightstepToken != "" { | ||
tracer = lightstep.NewTracer(lightstep.Options{ | ||
otTracer = lightstep.NewTracer(lightstep.Options{ | ||
AccessToken: *lightstepToken, | ||
}) | ||
defer lightstep.FlushLightStepTracer(tracer) | ||
defer lightstep.FlushLightStepTracer(otTracer) | ||
} else if *appdashAddr != "" { | ||
tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) | ||
otTracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) | ||
} else { | ||
tracer = stdopentracing.GlobalTracer() // no-op | ||
otTracer = stdopentracing.GlobalTracer() // no-op | ||
} | ||
} | ||
|
||
var zipkinTracer *zipkin.Tracer | ||
{ | ||
var ( | ||
err error | ||
hostPort = "" // if host:port is unknown we can keep this empty | ||
serviceName = "addsvc-cli" | ||
) | ||
noopTracer := (*zipkinV2URL == "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for readability purposes I'd call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed... will update |
||
reporter := zipkinhttp.NewReporter(*zipkinV2URL) | ||
defer reporter.Close() | ||
zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pronounced "zee endpoint" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol |
||
zipkinTracer, err = zipkin.NewTracer( | ||
reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(noopTracer), | ||
) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could add more context to this error. Something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
os.Exit(1) | ||
} | ||
} | ||
|
||
|
@@ -93,15 +116,15 @@ func main() { | |
err error | ||
) | ||
if *httpAddr != "" { | ||
svc, err = addtransport.NewHTTPClient(*httpAddr, tracer, log.NewNopLogger()) | ||
svc, err = addtransport.NewHTTPClient(*httpAddr, otTracer, zipkinTracer, log.NewNopLogger()) | ||
} else if *grpcAddr != "" { | ||
conn, err := grpc.Dial(*grpcAddr, grpc.WithInsecure(), grpc.WithTimeout(time.Second)) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v", err) | ||
os.Exit(1) | ||
} | ||
defer conn.Close() | ||
svc = addtransport.NewGRPCClient(conn, tracer, log.NewNopLogger()) | ||
svc = addtransport.NewGRPCClient(conn, otTracer, zipkinTracer, log.NewNopLogger()) | ||
} else if *thriftAddr != "" { | ||
// It's necessary to do all of this construction in the func main, | ||
// because (among other reasons) we need to control the lifecycle of the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for making this explicit, as people have unfortunately sent v2 to the v1 endpoint in the past!