From 8260dfd2fab8ec91460d3d5bb22198097d989d9f Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 6 Sep 2026 18:25:39 -0700 Subject: [PATCH] fix(ingest): a span without a status no longer takes the export down exportTraces read sp.Status.Code and sp.Status.Message directly. status is optional in OTLP and most SDKs omit it entirely when the status is unset, so an ordinary span panicked the handler: the connection was dropped mid-request and every span, log and metric in that export was lost with it. A collector sees an EOF and retries, and the retry panics the same way. Found by pointing an OTLP exporter at a local build while checking other work, which is also why the regression test posts the payload a real exporter sends rather than the one the existing tests construct. Both fields read through the generated getters now, and an unset status is recorded as STATUS_CODE_UNSET. Claude-Session: https://claude.ai/code/session_017ovmTezqzvxVP8P9MGDQNk --- internal/ingest/server.go | 8 +++++-- internal/ingest/server_test.go | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/internal/ingest/server.go b/internal/ingest/server.go index 3dbdf4b89..c223b7c08 100644 --- a/internal/ingest/server.go +++ b/internal/ingest/server.go @@ -93,8 +93,12 @@ func (s *Server) exportTraces(ctx context.Context, req *collectortrace.ExportTra StartUnixNanos: int64(sp.StartTimeUnixNano), EndUnixNanos: int64(sp.EndTimeUnixNano), DurationMS: spanDurationMS(sp.StartTimeUnixNano, sp.EndTimeUnixNano), - StatusCode: sp.Status.Code.String(), - StatusMsg: sp.Status.Message, + // status is optional in OTLP and most SDKs omit it entirely + // for an unset status, so these read through generated + // getters: dereferencing sp.Status panicked the handler and + // lost the whole export, not just the span. + StatusCode: sp.GetStatus().GetCode().String(), + StatusMsg: sp.GetStatus().GetMessage(), ResourceJSON: resourceJSON, AttributesJSON: attrsJSON(sp.Attributes), EventsJSON: eventsToJSON(sp.Events), diff --git a/internal/ingest/server_test.go b/internal/ingest/server_test.go index 2894cd2fa..f8e819411 100644 --- a/internal/ingest/server_test.go +++ b/internal/ingest/server_test.go @@ -550,3 +550,41 @@ func TestTraceExportContextCancellation(t *testing.T) { t.Errorf("expected context.Canceled, got %v", err) } } + +func TestTraceExportAcceptsSpanWithoutStatus(t *testing.T) { + // status is optional in OTLP and most SDKs omit it for an unset status. + // Reading it through the struct field panicked the handler, so a single + // ordinary span took the whole export down with it. + spans := make(chan telemetry.Span, 1) + logs := make(chan telemetry.Log, 1) + metrics := make(chan telemetry.Metric, 1) + srv := NewServer(config.Config{}, newTestSubmitter(spans, logs, metrics)) + + req := &collectortrace.ExportTraceServiceRequest{ + ResourceSpans: []*tracepb.ResourceSpans{{ + Resource: &resourcepb.Resource{Attributes: []*common.KeyValue{ + {Key: "service.name", Value: &common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: "checkout"}}}, + }}, + ScopeSpans: []*tracepb.ScopeSpans{{Spans: []*tracepb.Span{{ + TraceId: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, + SpanId: []byte{1, 2, 3, 4, 5, 6, 7, 8}, + Name: "POST /checkout", + }}}}, + }}, + } + + if _, err := (&traceService{srv: srv}).Export(context.Background(), req); err != nil { + t.Fatalf("Export: %v", err) + } + select { + case row := <-spans: + if row.StatusCode != tracepb.Status_STATUS_CODE_UNSET.String() { + t.Fatalf("status code = %q, want the unset status", row.StatusCode) + } + if row.StatusMsg != "" { + t.Fatalf("status message = %q, want empty", row.StatusMsg) + } + default: + t.Fatal("span was dropped") + } +}