From 074687b26b9ee31ae912e8866a7708cd3b0bcf90 Mon Sep 17 00:00:00 2001 From: Varkeychan Jacob Date: Thu, 23 Nov 2023 15:49:18 +0530 Subject: [PATCH] adding unit tests --- instrumentation/opentelemetry/span_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/instrumentation/opentelemetry/span_test.go b/instrumentation/opentelemetry/span_test.go index 2e8d01e..2a6aa98 100644 --- a/instrumentation/opentelemetry/span_test.go +++ b/instrumentation/opentelemetry/span_test.go @@ -133,3 +133,17 @@ func TestIterate(t *testing.T) { // service.instance.id is added implicitly in StartSpan so 3 attributes will be present. assert.Equal(t, 3, numAttrs) } + +func TestLen(t *testing.T) { + sampler := sdktrace.AlwaysSample() + tp := sdktrace.NewTracerProvider( + sdktrace.WithSampler(sampler), + ) + otel.SetTracerProvider(tp) + _, s, _ := StartSpan(context.Background(), "test_span", &sdk.SpanOptions{}) + s.SetAttribute("k1", "v1") + s.SetAttribute("k2", 200) + + // service.instance.id is added implicitly in StartSpan so 3 attributes will be present. + assert.Equal(t, 3, s.GetAttributes().Len()) +}