@@ -40,14 +40,14 @@ func Int64Attribute(key string, val int64) Attribute {
4040 return attribute .Int64 (key , val )
4141}
4242
43- // StartSpan creates an internal span.
43+ // StartSpan creates a SpanKind=INTERNAL span.
4444func StartSpan (ctx context.Context , spanName string , attributes ... Attribute ) (context.Context , trace.Span , func (error )) {
4545 return StartSpanWithTracer (ctx , otel .Tracer ("" ), spanName , attributes ... )
4646}
4747
4848// StartSpanWithTracer requires a tracer to be passed in and creates a SpanKind=INTERNAL span.
4949func StartSpanWithTracer (ctx context.Context , tracer trace.Tracer , name string , attributes ... Attribute ) (context.Context , trace.Span , func (error )) {
50- return startSpan (ctx , tracer , name , attributes ... )
50+ return startSpan (ctx , tracer , trace . SpanKindInternal , name , attributes ... )
5151}
5252
5353// RPCInfo contains information about the RPC request.
@@ -74,18 +74,13 @@ func StartServerSpan(ctx context.Context, tracer trace.Tracer, rpc RPCInfo, othe
7474 others ... ,
7575 )
7676 )
77- ctx , span := tracer .Start (ctx , name , trace .WithSpanKind (trace .SpanKindInternal ))
78-
79- if len (attributes ) > 0 {
80- span .SetAttributes (attributes ... )
81- }
82- return ctx , endSpan (span )
77+ ctx , _ , end := startSpan (ctx , tracer , trace .SpanKindServer , name , attributes ... )
78+ return ctx , end
8379}
8480
85- // startSpan creates an internal span.
86- func startSpan (ctx context.Context , tracer trace.Tracer , spanName string , attributes ... Attribute ) (context.Context , trace.Span , func (error )) {
87- ctx , span := tracer .Start (ctx , spanName , trace .WithSpanKind (trace .SpanKindInternal ))
88-
81+ // startSpan creates a span with the given kind.
82+ func startSpan (ctx context.Context , tracer trace.Tracer , kind trace.SpanKind , spanName string , attributes ... Attribute ) (context.Context , trace.Span , func (error )) {
83+ ctx , span := tracer .Start (ctx , spanName , trace .WithSpanKind (kind ))
8984 if len (attributes ) > 0 {
9085 span .SetAttributes (attributes ... )
9186 }
0 commit comments