diff --git a/plugin/ocgrpc/client.go b/plugin/ocgrpc/client.go index caa7e7684..f4a2d4d27 100644 --- a/plugin/ocgrpc/client.go +++ b/plugin/ocgrpc/client.go @@ -25,6 +25,9 @@ import ( // traces. Use with gRPC clients only. type ClientHandler struct { // StartOptions allows configuring the StartOptions used to create new spans. + // + // StartOptions.SpanKind will always be set to trace.SpanKindClient + // for spans started by this handler. StartOptions trace.StartOptions } diff --git a/plugin/ocgrpc/server.go b/plugin/ocgrpc/server.go index 7e68552af..f5da89b90 100644 --- a/plugin/ocgrpc/server.go +++ b/plugin/ocgrpc/server.go @@ -45,7 +45,11 @@ type ServerHandler struct { // present on the inbound RPC but the SpanContext is not sampled. This // ensures that each service has some opportunity to be traced. If you would // like to not add any additional traces for this gRPC service, set: + // // StartOptions.Sampler = trace.ProbabilitySampler(0.0) + // + // StartOptions.SpanKind will always be set to trace.SpanKindServer + // for spans started by this handler. StartOptions trace.StartOptions } diff --git a/plugin/ocgrpc/trace_common.go b/plugin/ocgrpc/trace_common.go index c24e2d845..130123279 100644 --- a/plugin/ocgrpc/trace_common.go +++ b/plugin/ocgrpc/trace_common.go @@ -34,6 +34,7 @@ const traceContextKey = "grpc-trace-bin" // It returns ctx with the new trace span added and a serialization of the // SpanContext added to the outgoing gRPC metadata. func (c *ClientHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { + c.StartOptions.SpanKind = trace.SpanKindClient name := "Sent" + strings.Replace(rti.FullMethodName, "/", ".", -1) span := trace.NewSpan(name, trace.FromContext(ctx), c.StartOptions) // span is ended by traceHandleRPC ctx = trace.WithSpan(ctx, span) @@ -48,6 +49,7 @@ func (c *ClientHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) // // It returns ctx, with the new trace span added. func (s *ServerHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { + s.StartOptions.SpanKind = trace.SpanKindServer md, _ := metadata.FromIncomingContext(ctx) name := "Recv" + strings.Replace(rti.FullMethodName, "/", ".", -1) traceContext := md[traceContextKey] diff --git a/plugin/ochttp/client.go b/plugin/ochttp/client.go index cc65191d7..3b58b8251 100644 --- a/plugin/ochttp/client.go +++ b/plugin/ochttp/client.go @@ -38,6 +38,9 @@ type Transport struct { // StartOptions are applied to the span started by this Transport around each // request. + // + // StartOptions.SpanKind will always be set to trace.SpanKindClient + // for spans started by this transport. StartOptions trace.StartOptions // TODO: Implement tag propagation for HTTP. @@ -45,6 +48,7 @@ type Transport struct { // RoundTrip implements http.RoundTripper, delegating to Base and recording stats and traces for the request. func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { + t.StartOptions.SpanKind = trace.SpanKindClient rt := t.base() // TODO: remove excessive nesting of http.RoundTrippers here. format := t.Propagation diff --git a/plugin/ochttp/server.go b/plugin/ochttp/server.go index d91cfdb31..4a390bc17 100644 --- a/plugin/ochttp/server.go +++ b/plugin/ochttp/server.go @@ -47,6 +47,9 @@ type Handler struct { // StartOptions are applied to the span started by this Handler around each // request. + // + // StartOptions.SpanKind will always be set to trace.SpanKindServer + // for spans started by this transport. StartOptions trace.StartOptions // IsPublicEndpoint should be set to true for publicly accessible HTTP(S) @@ -71,6 +74,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (h *Handler) startTrace(w http.ResponseWriter, r *http.Request) (*http.Request, func()) { + h.StartOptions.SpanKind = trace.SpanKindServer name := spanNameFromURL("Recv", r.URL) ctx := r.Context() var span *trace.Span