You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
Add env support for span limits configuration (#2606)
* add env support for otel_span configuration Signed-off-by: Cuichen Li <cuichli@cisco.com> * update changelog * update changelog and some logic based on comment * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> * add document about retrieve value from environment variable Signed-off-by: Cuichen Li <cuichli@cisco.com> * remove trailing whitespace Signed-off-by: Cuichen Li <cuichli@cisco.com> * parse environment variable before apply the options * Update CHANGELOG.md Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Update sdk/trace/provider_test.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@@ -17,8 +17,14 @@ package trace
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
ottest "go.opentelemetry.io/otel/internal/internaltest"
|
||||
"go.opentelemetry.io/otel/sdk/internal/env"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
@@ -94,3 +100,58 @@ func TestSchemaURL(t *testing.T) {
|
||||
tracerStruct := tracerIface.(*tracer)
|
||||
assert.EqualValues(t, schemaURL, tracerStruct.instrumentationLibrary.SchemaURL)
|
||||
}
|
||||
|
||||
func TestNewTraceProviderWithoutSpanLimitConfiguration(t *testing.T) {
|
||||
envStore := ottest.NewEnvStore()
|
||||
defer func() {
|
||||
require.NoError(t, envStore.Restore())
|
||||
}()
|
||||
envStore.Record(env.SpanAttributesCountKey)
|
||||
envStore.Record(env.SpanEventCountKey)
|
||||
envStore.Record(env.SpanLinkCountKey)
|
||||
require.NoError(t, os.Setenv(env.SpanEventCountKey, "111"))
|
||||
require.NoError(t, os.Setenv(env.SpanAttributesCountKey, "222"))
|
||||
require.NoError(t, os.Setenv(env.SpanLinkCountKey, "333"))
|
||||
tp := NewTracerProvider()
|
||||
assert.Equal(t, 111, tp.spanLimits.EventCountLimit)
|
||||
assert.Equal(t, 222, tp.spanLimits.AttributeCountLimit)
|
||||
assert.Equal(t, 333, tp.spanLimits.LinkCountLimit)
|
||||
}
|
||||
|
||||
func TestNewTraceProviderWithSpanLimitConfigurationFromOptsAndEnvironmentVariable(t *testing.T) {
|
||||
envStore := ottest.NewEnvStore()
|
||||
defer func() {
|
||||
require.NoError(t, envStore.Restore())
|
||||
}()
|
||||
envStore.Record(env.SpanAttributesCountKey)
|
||||
envStore.Record(env.SpanEventCountKey)
|
||||
envStore.Record(env.SpanLinkCountKey)
|
||||
require.NoError(t, os.Setenv(env.SpanEventCountKey, "111"))
|
||||
require.NoError(t, os.Setenv(env.SpanAttributesCountKey, "222"))
|
||||
require.NoError(t, os.Setenv(env.SpanLinkCountKey, "333"))
|
||||
tp := NewTracerProvider(WithSpanLimits(SpanLimits{
|
||||
EventCountLimit: 1,
|
||||
AttributeCountLimit: 2,
|
||||
LinkCountLimit: 3,
|
||||
}))
|
||||
assert.Equal(t, 1, tp.spanLimits.EventCountLimit)
|
||||
assert.Equal(t, 2, tp.spanLimits.AttributeCountLimit)
|
||||
assert.Equal(t, 3, tp.spanLimits.LinkCountLimit)
|
||||
}
|
||||
|
||||
func TestNewTraceProviderWithInvalidSpanLimitConfigurationFromEnvironmentVariable(t *testing.T) {
|
||||
envStore := ottest.NewEnvStore()
|
||||
defer func() {
|
||||
require.NoError(t, envStore.Restore())
|
||||
}()
|
||||
envStore.Record(env.SpanAttributesCountKey)
|
||||
envStore.Record(env.SpanEventCountKey)
|
||||
envStore.Record(env.SpanLinkCountKey)
|
||||
require.NoError(t, os.Setenv(env.SpanEventCountKey, "-111"))
|
||||
require.NoError(t, os.Setenv(env.SpanAttributesCountKey, "-222"))
|
||||
require.NoError(t, os.Setenv(env.SpanLinkCountKey, "-333"))
|
||||
tp := NewTracerProvider()
|
||||
assert.Equal(t, 128, tp.spanLimits.EventCountLimit)
|
||||
assert.Equal(t, 128, tp.spanLimits.AttributeCountLimit)
|
||||
assert.Equal(t, 128, tp.spanLimits.LinkCountLimit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user