mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-02-09 13:37:12 +02:00
Fix testCollectorEndpoint typo and add tag assertions in jaeger_test (#1753)
* Fix testCollectorEndpoint typo and add tag assertions in jaeger_test * add PR number for CHANGLOG * add tag and sevicename assetions in TestExporter_ExportSpan * update assert.Equal to assert.Len and revert CHANGLOG * update assert.Len to require.Len
This commit is contained in:
parent
ecc635dc1d
commit
3947cab4be
@ -277,38 +277,47 @@ func TestNewRawExporterShouldFailIfCollectorUnset(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
type testCollectorEnpoint struct {
|
||||
type testCollectorEndpoint struct {
|
||||
batchesUploaded []*gen.Batch
|
||||
}
|
||||
|
||||
func (c *testCollectorEnpoint) upload(batch *gen.Batch) error {
|
||||
func (c *testCollectorEndpoint) upload(batch *gen.Batch) error {
|
||||
c.batchesUploaded = append(c.batchesUploaded, batch)
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ batchUploader = (*testCollectorEnpoint)(nil)
|
||||
var _ batchUploader = (*testCollectorEndpoint)(nil)
|
||||
|
||||
func withTestCollectorEndpoint() func() (batchUploader, error) {
|
||||
return func() (batchUploader, error) {
|
||||
return &testCollectorEnpoint{}, nil
|
||||
return &testCollectorEndpoint{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func withTestCollectorEndpointInjected(ce *testCollectorEnpoint) func() (batchUploader, error) {
|
||||
func withTestCollectorEndpointInjected(ce *testCollectorEndpoint) func() (batchUploader, error) {
|
||||
return func() (batchUploader, error) {
|
||||
return ce, nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestExporter_ExportSpan(t *testing.T) {
|
||||
envStore, err := ottest.SetEnvVariables(map[string]string{
|
||||
envDisabled: "false",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, envStore.Restore())
|
||||
}()
|
||||
|
||||
const (
|
||||
serviceName = "test-service"
|
||||
tagKey = "key"
|
||||
tagVal = "val"
|
||||
)
|
||||
// Create Jaeger Exporter
|
||||
exp, err := NewRawExporter(
|
||||
withTestCollectorEndpoint(),
|
||||
|
||||
testCollector := &testCollectorEndpoint{}
|
||||
tp, spanFlush, err := NewExportPipeline(
|
||||
withTestCollectorEndpointInjected(testCollector),
|
||||
WithSDKOptions(
|
||||
sdktrace.WithResource(resource.NewWithAttributes(
|
||||
semconv.ServiceNameKey.String(serviceName),
|
||||
@ -316,23 +325,25 @@ func TestExporter_ExportSpan(t *testing.T) {
|
||||
)),
|
||||
),
|
||||
)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
tp := sdktrace.NewTracerProvider(
|
||||
sdktrace.WithSampler(sdktrace.AlwaysSample()),
|
||||
sdktrace.WithSyncer(exp),
|
||||
)
|
||||
otel.SetTracerProvider(tp)
|
||||
_, span := otel.Tracer("test-tracer").Start(context.Background(), "test-span")
|
||||
span.End()
|
||||
tracer := otel.Tracer("test-tracer")
|
||||
for i := 0; i < 3; i++ {
|
||||
_, span := tracer.Start(context.Background(), fmt.Sprintf("test-span-%d", i))
|
||||
span.End()
|
||||
assert.True(t, span.SpanContext().IsValid())
|
||||
}
|
||||
|
||||
assert.True(t, span.SpanContext().IsValid())
|
||||
spanFlush()
|
||||
batchesUploaded := testCollector.batchesUploaded
|
||||
require.Len(t, batchesUploaded, 1)
|
||||
uploadedBatch := batchesUploaded[0]
|
||||
assert.Equal(t, serviceName, uploadedBatch.GetProcess().GetServiceName())
|
||||
assert.Len(t, uploadedBatch.GetSpans(), 3)
|
||||
|
||||
exp.Flush()
|
||||
tc := exp.uploader.(*testCollectorEnpoint)
|
||||
assert.True(t, len(tc.batchesUploaded) == 1)
|
||||
assert.True(t, len(tc.batchesUploaded[0].GetSpans()) == 1)
|
||||
require.Len(t, uploadedBatch.GetProcess().GetTags(), 1)
|
||||
assert.Equal(t, tagKey, uploadedBatch.GetProcess().GetTags()[0].GetKey())
|
||||
assert.Equal(t, tagVal, uploadedBatch.GetProcess().GetTags()[0].GetVStr())
|
||||
}
|
||||
|
||||
func Test_spanSnapshotToThrift(t *testing.T) {
|
||||
@ -943,14 +954,17 @@ func TestNewExporterPipelineWithOptions(t *testing.T) {
|
||||
const (
|
||||
serviceName = "test-service"
|
||||
eventCountLimit = 10
|
||||
tagKey = "key"
|
||||
tagVal = "val"
|
||||
)
|
||||
|
||||
testCollector := &testCollectorEnpoint{}
|
||||
testCollector := &testCollectorEndpoint{}
|
||||
tp, spanFlush, err := NewExportPipeline(
|
||||
withTestCollectorEndpointInjected(testCollector),
|
||||
WithSDKOptions(
|
||||
sdktrace.WithResource(resource.NewWithAttributes(
|
||||
semconv.ServiceNameKey.String(serviceName),
|
||||
attribute.String(tagKey, tagVal),
|
||||
)),
|
||||
sdktrace.WithSpanLimits(sdktrace.SpanLimits{
|
||||
EventCountLimit: eventCountLimit,
|
||||
@ -970,10 +984,14 @@ func TestNewExporterPipelineWithOptions(t *testing.T) {
|
||||
assert.True(t, span.SpanContext().IsValid())
|
||||
|
||||
batchesUploaded := testCollector.batchesUploaded
|
||||
assert.True(t, len(batchesUploaded) == 1)
|
||||
require.Len(t, batchesUploaded, 1)
|
||||
uploadedBatch := batchesUploaded[0]
|
||||
assert.Equal(t, serviceName, uploadedBatch.GetProcess().GetServiceName())
|
||||
assert.True(t, len(uploadedBatch.GetSpans()) == 1)
|
||||
require.Len(t, uploadedBatch.GetSpans(), 1)
|
||||
uploadedSpan := uploadedBatch.GetSpans()[0]
|
||||
assert.Equal(t, eventCountLimit, len(uploadedSpan.GetLogs()))
|
||||
assert.Len(t, uploadedSpan.GetLogs(), eventCountLimit)
|
||||
|
||||
require.Len(t, uploadedBatch.GetProcess().GetTags(), 1)
|
||||
assert.Equal(t, tagKey, uploadedBatch.GetProcess().GetTags()[0].GetKey())
|
||||
assert.Equal(t, tagVal, uploadedBatch.GetProcess().GetTags()[0].GetVStr())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user