github.com/mier85/go-sensor@v1.30.1-0.20220920111756-9bf41b3bc7e0/recorder_test.go (about)

     1  // (c) Copyright IBM Corp. 2021
     2  // (c) Copyright Instana Inc. 2017
     3  
     4  package instana_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/instana/testify/assert"
    10  	"github.com/instana/testify/require"
    11  	instana "github.com/mier85/go-sensor"
    12  	"github.com/opentracing/opentracing-go/ext"
    13  )
    14  
    15  func TestRecorderBasics(t *testing.T) {
    16  	recorder := instana.NewTestRecorder()
    17  	tracer := instana.NewTracerWithEverything(&instana.Options{}, recorder)
    18  
    19  	span := tracer.StartSpan("http-client")
    20  	span.SetTag(string(ext.SpanKind), "exit")
    21  	span.SetTag("http.status", 200)
    22  	span.SetTag("http.url", "https://www.instana.com/product/")
    23  	span.SetTag(string(ext.HTTPMethod), "GET")
    24  	span.Finish()
    25  
    26  	// Validate GetQueuedSpans returns queued spans and clears the queue
    27  	spans := recorder.GetQueuedSpans()
    28  	assert.Len(t, spans, 1)
    29  	assert.Equal(t, 0, recorder.QueuedSpansCount())
    30  }
    31  
    32  func TestRecorder_BatchSpan(t *testing.T) {
    33  	recorder := instana.NewTestRecorder()
    34  	tracer := instana.NewTracerWithEverything(&instana.Options{}, recorder)
    35  
    36  	tracer.StartSpan("test-span", instana.BatchSize(2)).Finish()
    37  
    38  	spans := recorder.GetQueuedSpans()
    39  	require.Len(t, spans, 1)
    40  
    41  	require.NotNil(t, spans[0].Batch)
    42  	assert.Equal(t, 2, spans[0].Batch.Size)
    43  }
    44  
    45  func TestRecorder_BatchSpan_Single(t *testing.T) {
    46  	recorder := instana.NewTestRecorder()
    47  	tracer := instana.NewTracerWithEverything(&instana.Options{}, recorder)
    48  
    49  	tracer.StartSpan("test-span", instana.BatchSize(1)).Finish()
    50  
    51  	spans := recorder.GetQueuedSpans()
    52  	require.Len(t, spans, 1)
    53  
    54  	assert.Nil(t, spans[0].Batch)
    55  }