Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/BinWang-sh/opentracing-go
https://github.com/BinWang-sh/opentracing-go
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/BinWang-sh/opentracing-go
- Owner: BinWang-sh
- Created: 2019-12-12T12:34:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-16T02:55:23.000Z (almost 5 years ago)
- Last Synced: 2024-08-02T15:18:12.153Z (3 months ago)
- Language: Go
- Size: 39.1 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An example of using opentracing.
This example shows how to trace over the process boundaries and RPC calls.
Jaeger start
docker run \
-p 5775:5775/udp \
-p 16686:16686 \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 14268:14268 \
jaegertracing/all-in-one:latest
Client side<1>import
import (
"github.com/opentracing/opentracing-go/ext"
)
<2>injectext.SpanKindRPCClient.Set(reqSpan)
ext.HTTPUrl.Set(reqSpan, reqURL)
ext.HTTPMethod.Set(reqSpan, "GET")
span.Tracer().Inject(
span.Context(),
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(req.Header),
)Server side
<1>import
import (
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/yurishkuro/opentracing-tutorial/go/lib/tracing"
)<2>Extrace span context from incoming http request
spanCtx, _ := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header))<3>Creates a ChildOf reference to the passed spanCtx as well as sets a span.kind=server tag on the new span by using a special option RPCServerOption
span := tracer.StartSpan("format", ext.RPCServerOption(spanCtx))
defer span.Finish()