Update tracing_test.go

This commit is contained in:
sashass1315 2026-02-03 14:46:30 +02:00 committed by GitHub
parent 5f17eea09c
commit 111b97bbb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,7 @@ package rpc
import ( import (
"context" "context"
"net/http/httptest" "net/http/httptest"
"strings"
"testing" "testing"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
@ -196,8 +197,8 @@ func TestTracingBatchHTTP(t *testing.T) {
} }
// TestTracingSubscribeUnsubscribe verifies that subscribe and unsubscribe calls // TestTracingSubscribeUnsubscribe verifies that subscribe and unsubscribe calls
// do not emit any spans. // do not emit RPC server spans (like "jsonrpc.service/method").
// Note: This works because client.newClientConn() passes nil as the tracer provider. // Note: handleSubscribe does not create the main RPC span, only internal encoding spans.
func TestTracingSubscribeUnsubscribe(t *testing.T) { func TestTracingSubscribeUnsubscribe(t *testing.T) {
t.Parallel() t.Parallel()
server, tracer, exporter := newTracingServer(t) server, tracer, exporter := newTracingServer(t)
@ -213,12 +214,16 @@ func TestTracingSubscribeUnsubscribe(t *testing.T) {
// Unsubscribe. // Unsubscribe.
sub.Unsubscribe() sub.Unsubscribe()
// Flush and check that no spans were emitted. // Flush and check that no RPC server spans were emitted.
// Internal spans like "rpc.encodeJSONResponse" are allowed.
if err := tracer.ForceFlush(context.Background()); err != nil { if err := tracer.ForceFlush(context.Background()); err != nil {
t.Fatalf("failed to flush: %v", err) t.Fatalf("failed to flush: %v", err)
} }
spans := exporter.GetSpans() spans := exporter.GetSpans()
if len(spans) != 0 { for _, span := range spans {
t.Errorf("expected no spans for subscribe/unsubscribe, got %d", len(spans)) // RPC server spans have names like "jsonrpc.service/method"
if strings.HasPrefix(span.Name, "jsonrpc.") {
t.Errorf("unexpected RPC server span for subscribe/unsubscribe: %s", span.Name)
}
} }
} }