Skip to content

Commit 9cf63d4

Browse files
authored
Merge pull request #29 from zalando/fix_empty_grpc_response_in_pb
Fix empty grpc response in lightstep_pb + set span.custom_kind only when span kind is unspecified
2 parents caf1867 + 5100d31 commit 9cf63d4

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

internal/lightstep_pb/grpc/server.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package grpc
33
import (
44
"context"
55
"errors"
6+
"net"
7+
"sync"
8+
69
"go.opentelemetry.io/collector/component/componentstatus"
710
"go.opentelemetry.io/collector/config/configgrpc"
8-
"sync"
911

1012
lightstepCommon "github.com/zalando/otelcol-lightstep-receiver/internal/lightstep_common"
1113
"github.com/zalando/otelcol-lightstep-receiver/internal/lightstep_pb"
@@ -19,7 +21,6 @@ import (
1921
"go.opentelemetry.io/collector/receiver/receiverhelper"
2022
"go.uber.org/zap"
2123
"google.golang.org/grpc"
22-
"net"
2324
)
2425

2526
const transport = "pbgrpc"
@@ -99,7 +100,9 @@ func (s *ServerGRPC) Report(ctx context.Context, rq *pb.ReportRequest) (*pb.Repo
99100
lr := lightstep_pb.NewLightstepRequest(rq, s.telemetry, transport)
100101
if projectTraces, err = lr.ToOtel(ctx); err != nil {
101102
s.telemetry.IncrementFailed(transport, 1)
102-
return nil, err
103+
return &pb.ReportResponse{
104+
Errors: []string{err.Error()},
105+
}, err
103106
}
104107
s.telemetry.IncrementProcessed(transport, 1)
105108
s.telemetry.IncrementClientDropSpans(projectTraces.ServiceName, projectTraces.ClientSpansDropped)
@@ -113,5 +116,13 @@ func (s *ServerGRPC) Report(ctx context.Context, rq *pb.ReportRequest) (*pb.Repo
113116
err = s.nextTraces.ConsumeTraces(ctx, projectTraces.Traces)
114117
s.obsreport.EndTracesOp(ctx, "protobuf-grpc", spanCount, err)
115118

116-
return nil, err
119+
if err != nil {
120+
return &pb.ReportResponse{
121+
Errors: []string{err.Error()},
122+
}, err
123+
}
124+
125+
return &pb.ReportResponse{
126+
Errors: nil,
127+
}, nil
117128
}

internal/lightstep_pb/transform_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestTransformation(t *testing.T) {
9494
},
9595
{
9696
Key: "span.kind",
97-
Value: &pb.KeyValue_StringValue{StringValue: []byte("client")},
97+
Value: &pb.KeyValue_StringValue{StringValue: []byte("special_span_kind")},
9898
},
9999
},
100100
Logs: []*pb.Log{
@@ -134,7 +134,7 @@ func TestTransformation(t *testing.T) {
134134
is.Equal(span.ParentSpanID().String(), "24be8e394663fb1e")
135135
is.Equal(span.StartTimestamp().AsTime().UnixNano(), int64(1718207928350615000))
136136
is.Equal(span.EndTimestamp().AsTime().UnixNano(), int64(1718207928350715000))
137-
is.Equal(span.Kind(), ptrace.SpanKindClient)
137+
is.Equal(span.Kind(), ptrace.SpanKindUnspecified)
138138

139139
var (
140140
ok bool
@@ -163,7 +163,7 @@ func TestTransformation(t *testing.T) {
163163

164164
v, ok = span.Attributes().Get("span.custom_kind")
165165
is.True(ok)
166-
is.Equal(v.Str(), "client")
166+
is.Equal(v.Str(), "special_span_kind")
167167

168168
is.Equal(span.Events().Len(), 1)
169169
is.Equal(span.Events().At(0).Name(), "event-name")

internal/lightstep_thrift/transform.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ func (tr *Request) ToOtel(ctx context.Context) (*lightstepCommon.ProjectTraces,
103103

104104
if spanKind, ok := attr.Get("span.kind"); ok {
105105
otelSpanKind, stringSpanKind := lightstepCommon.ParseSpanKindAttributeValue(spanKind)
106-
attr.PutStr("span.custom_kind", stringSpanKind)
107106
s.SetKind(otelSpanKind)
107+
if otelSpanKind == ptrace.SpanKindUnspecified {
108+
attr.PutStr("span.custom_kind", stringSpanKind)
109+
}
108110
}
109111

110112
for _, log := range span.LogRecords {

0 commit comments

Comments
 (0)