@@ -24,11 +24,9 @@ type InMemoryClient interface {
2424 // Spans returns a copy of the list of in-memory stored spans as a base64
2525 // encoded otlp protobuf string.
2626 Spans () (string , error )
27- // ProtoSpans returns a copy of the list of in-memory stored spans as otlp
28- // protobuf byte array.
29- ProtoSpans () ([]byte , error )
30- // Clear spans removes all in-memory spans
31- ClearSpans ()
27+ // ExportProtoSpans returns a copy of the list of in-memory stored spans as otlp
28+ // protobuf byte array and clears the in-memory spans.
29+ ExportProtoSpans () ([]byte , error )
3230}
3331
3432// InMemoryOtlpClient is a client implementation for otlptrace.Client
@@ -60,15 +58,15 @@ func (mc *InMemoryOtlpClient) UploadTraces(_ context.Context, protoSpans []*trac
6058
6159// Spans returns the list of in-memory stored spans as a base64 encoded otlp protobuf string.
6260func (mc * InMemoryOtlpClient ) Spans () (string , error ) {
63- data , err := mc .ProtoSpans ()
61+ data , err := mc .ExportProtoSpans ()
6462 if err != nil {
6563 return "" , err
6664 }
6765 return base64 .StdEncoding .EncodeToString (data ), nil
6866}
6967
7068// ProtoSpans returns the list of in-memory stored spans as the protobuf byte array.
71- func (mc * InMemoryOtlpClient ) ProtoSpans () ([]byte , error ) {
69+ func (mc * InMemoryOtlpClient ) ExportProtoSpans () ([]byte , error ) {
7270 mc .mu .Lock ()
7371 defer mc .mu .Unlock ()
7472 if len (mc .spans ) <= 0 {
@@ -77,13 +75,12 @@ func (mc *InMemoryOtlpClient) ProtoSpans() ([]byte, error) {
7775 pbRequest := & coltracepb.ExportTraceServiceRequest {
7876 ResourceSpans : mc .spans ,
7977 }
80- return proto .Marshal (pbRequest )
81- }
82-
83- func (mc * InMemoryOtlpClient ) ClearSpans () {
84- mc .mu .Lock ()
85- defer mc .mu .Unlock ()
78+ serializedSpans , err := proto .Marshal (pbRequest )
79+ if err != nil {
80+ return nil , err
81+ }
8682 mc .spans = make ([]* tracepb.ResourceSpans , 0 )
83+ return serializedSpans , nil
8784}
8885
8986// NoopOtlpClient is a client implementation for otlptrace.Client that does nothing
@@ -107,7 +104,7 @@ func (mc *NoopOtlpClient) Spans() (string, error) {
107104}
108105
109106// Spans always returns no traces error
110- func (mc * NoopOtlpClient ) ProtoSpans () ([]byte , error ) {
107+ func (mc * NoopOtlpClient ) ExportProtoSpans () ([]byte , error ) {
111108 return nil , errNoopTracer
112109}
113110
0 commit comments