StartServerSpan had the wrong spankind

This commit is contained in:
jonny rhea 2026-01-08 10:32:03 -06:00
parent a91d7ad952
commit cd9665f107

View file

@ -40,14 +40,14 @@ func Int64Attribute(key string, val int64) Attribute {
return attribute.Int64(key, val) return attribute.Int64(key, val)
} }
// StartSpan creates an internal span. // StartSpan creates a SpanKind=INTERNAL span.
func StartSpan(ctx context.Context, spanName string, attributes ...Attribute) (context.Context, trace.Span, func(error)) { func StartSpan(ctx context.Context, spanName string, attributes ...Attribute) (context.Context, trace.Span, func(error)) {
return StartSpanWithTracer(ctx, otel.Tracer(""), spanName, attributes...) return StartSpanWithTracer(ctx, otel.Tracer(""), spanName, attributes...)
} }
// StartSpanWithTracer requires a tracer to be passed in and creates a SpanKind=INTERNAL span. // StartSpanWithTracer requires a tracer to be passed in and creates a SpanKind=INTERNAL span.
func StartSpanWithTracer(ctx context.Context, tracer trace.Tracer, name string, attributes ...Attribute) (context.Context, trace.Span, func(error)) { func StartSpanWithTracer(ctx context.Context, tracer trace.Tracer, name string, attributes ...Attribute) (context.Context, trace.Span, func(error)) {
return startSpan(ctx, tracer, name, attributes...) return startSpan(ctx, tracer, trace.SpanKindInternal, name, attributes...)
} }
// RPCInfo contains information about the RPC request. // RPCInfo contains information about the RPC request.
@ -74,18 +74,13 @@ func StartServerSpan(ctx context.Context, tracer trace.Tracer, rpc RPCInfo, othe
others..., others...,
) )
) )
ctx, span := tracer.Start(ctx, name, trace.WithSpanKind(trace.SpanKindInternal)) ctx, _, end := startSpan(ctx, tracer, trace.SpanKindServer, name, attributes...)
return ctx, end
if len(attributes) > 0 {
span.SetAttributes(attributes...)
}
return ctx, endSpan(span)
} }
// startSpan creates an internal span. // startSpan creates a span with the given kind.
func startSpan(ctx context.Context, tracer trace.Tracer, spanName string, attributes ...Attribute) (context.Context, trace.Span, func(error)) { func startSpan(ctx context.Context, tracer trace.Tracer, kind trace.SpanKind, spanName string, attributes ...Attribute) (context.Context, trace.Span, func(error)) {
ctx, span := tracer.Start(ctx, spanName, trace.WithSpanKind(trace.SpanKindInternal)) ctx, span := tracer.Start(ctx, spanName, trace.WithSpanKind(kind))
if len(attributes) > 0 { if len(attributes) > 0 {
span.SetAttributes(attributes...) span.SetAttributes(attributes...)
} }