import("net/http"opentracing"github.com/opentracing/opentracing-go""github.com/opentracing/opentracing-go/ext")...tracer:=opentracing.GlobalTracer()clientSpan:=tracer.StartSpan("client")deferclientSpan.Finish()url:="http://localhost:8082/publish"req,_:=http.NewRequest("GET",url,nil)// Set some tags on the clientSpan to annotate that it's the client span. The additional HTTP tags are useful for debugging purposes.
ext.SpanKindRPCClient.Set(clientSpan)ext.HTTPUrl.Set(clientSpan,url)ext.HTTPMethod.Set(clientSpan,"GET")// Inject the client span context into the headers
tracer.Inject(clientSpan.Context(),opentracing.HTTPHeaders,opentracing.HTTPHeadersCarrier(req.Header))resp,_:=http.DefaultClient.Do(req)
import("log""net/http"opentracing"github.com/opentracing/opentracing-go""github.com/opentracing/opentracing-go/ext")funcmain(){// Tracer initialization, etc.
...http.HandleFunc("/publish",func(whttp.ResponseWriter,r*http.Request){// Extract the context from the headers
spanCtx,_:=tracer.Extract(opentracing.HTTPHeaders,opentracing.HTTPHeadersCarrier(r.Header))serverSpan:=tracer.StartSpan("server",ext.RPCServerOption(spanCtx))deferserverSpan.Finish()})log.Fatal(http.ListenAndServe(":8082",nil))}
// java -javaagent:xxx.jar -jar yy.jar
/**
* The main entrance of sky-walking agent, based on javaagent mechanism.
*/publicclassSkyWalkingAgent{/**
* Main entrance. Use byte-buddy transform to enhance all classes, which define in plugins.
*/publicstaticvoidpremain(StringagentArgs,Instrumentationinstrumentation)throwsPluginException{// instrument
...}}