Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/ingest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
38 changes: 38 additions & 0 deletions internal/ingest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Loading