Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Span attribute drop logic does not comply with the specification. #2554

Closed
MrAlias opened this issue Jan 26, 2022 · 3 comments · Fixed by #2576
Closed

Span attribute drop logic does not comply with the specification. #2554

MrAlias opened this issue Jan 26, 2022 · 3 comments · Fixed by #2576
Assignees
Labels
area:trace Part of OpenTelemetry tracing bug Something isn't working
Projects

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Jan 26, 2022

Description

Currently the trace SDK drops attributes based on a least-recently-used algorithm: the most recently unique attributes added are kept and the oldest not updated attributes are dropped when capacity is reached. However, the specification states:

for each unique attributes key, addition of which would result in exceeding the limit, SDK MUST discard that key/value pair

Meaning if a user adds an attribute after capacity is reached that attribute (if it has a unique key) should be dropped. This is not the behavior currently implemented.

Environment

  • opentelemetry-go version: v1.3.0

Steps To Reproduce

package trace // import "go.opentelemetry.io/otel/sdk/trace"

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"go.opentelemetry.io/otel/attribute"
)

func TestSpanAttributeCapacityDropOrder(t *testing.T) {
	// The tracing specification states:
	//
	//   For each unique attribute key, addition of which would result in
	//   exceeding the limit, SDK MUST discard that key/value pair
	//
	// Therefore, adding attributes after the capacity is reached should
	// result in those attributes being dropped.

	const (
		instName = "TestSpanAttributeCapacityDropOrder"
		spanName = "test span"
	)

	te := NewTestExporter()
	tp := NewTracerProvider(
		WithSyncer(te),
		WithSpanLimits(SpanLimits{AttributeCountLimit: 1}),
	)
	attrs := []attribute.KeyValue{
		attribute.String("key1", "value1"),
		attribute.String("key2", "value2"),
	}

	_, span := tp.Tracer(instName).Start(context.Background(), spanName)
	span.SetAttributes(attrs[0])
	// These should be dropped based on limits.
	span.SetAttributes(attrs[1])
	span.SetAttributes(attrs...)
	span.End()

	got, ok := te.GetSpan(spanName)
	require.Truef(t, ok, "span %s not exported", spanName)
	assert.Equal(t, attrs[:1], got.attributes)
}

Expected behavior

The included test should pass and the first attributes a user passes should be preserved.

@MrAlias MrAlias added bug Something isn't working area:trace Part of OpenTelemetry tracing labels Jan 26, 2022
@MrAlias MrAlias added this to Needs triage in Bugs via automation Jan 26, 2022
@MrAlias MrAlias moved this from Needs triage to High priority in Bugs Jan 26, 2022
@jmacd
Copy link
Contributor

jmacd commented Jan 26, 2022

I think this behavior snuck in from the OpenCensus-Go library. I'd be glad to see it go! 😁

@jmacd
Copy link
Contributor

jmacd commented Jan 26, 2022

@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 26, 2022

See also open-telemetry/opentelemetry-specification#2248

Right. We are compliant with this currently (1), but it is important to consider this when resolving this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:trace Part of OpenTelemetry tracing bug Something isn't working
Projects
Archived in project
Bugs
  
Closed
2 participants