Skip to content

Commit

Permalink
Replace recordingSpan attributes implementation with slice of attribu…
Browse files Browse the repository at this point in the history
…tes (#2576)

* Replace recordingSpan attributes implementation

Instead of an LRU strategy for cap-ing span attributes, comply with the
specification and drop last added. To do this, the attributesmap is
replaced with a slice of attributes.

* Remove attributesmap files

* Refine addition algorithm

Unify duplicated code.

Fix deduplication algorithm.

Fix droppedAttributes to always be returned, even if the span has no
attributes.

* Unify span SetAttributes tests

* Doc fix to attr drop order in changelog

* Test span and snapshot attrs

* fix lint

* Add tests for recordingSpan method defaults

* Comment why pre-allocation is not done

* Correct grammar in recordingSpan allocation comment

* Update sdk/trace/tracer.go

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
  • Loading branch information
MrAlias and Aneurysm9 committed Feb 7, 2022
1 parent b60d53d commit 98bb105
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 303 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -31,6 +31,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Specify explicit buckets in Prometheus example. (#2493)
- W3C baggage will now decode urlescaped values. (#2529)
- Baggage members are now only validated once, when calling `NewMember` and not also when adding it to the baggage itself. (#2522)
- The order attributes are dropped from spans in the `go.opentelemetry.io/otel/sdk/trace` package when capacity is reached is fixed to be in compliance with the OpenTelemetry specification.
Instead of dropping the least-recently-used attribute, the last added attribute is dropped.
This drop order still only applies to attributes with unique keys not already contained in the span.
If an attribute is added with a key already contained in the span, that attribute is updated to the new value being added. (#2576)

### Removed

Expand Down
91 changes: 0 additions & 91 deletions sdk/trace/attributesmap.go

This file was deleted.

103 changes: 0 additions & 103 deletions sdk/trace/attributesmap_test.go

This file was deleted.

23 changes: 23 additions & 0 deletions sdk/trace/benchmark_test.go
Expand Up @@ -16,6 +16,7 @@ package trace_test

import (
"context"
"fmt"
"testing"
"time"

Expand All @@ -24,6 +25,28 @@ import (
"go.opentelemetry.io/otel/trace"
)

func BenchmarkSpanSetAttributesOverCapacity(b *testing.B) {
tp := sdktrace.NewTracerProvider(
sdktrace.WithSpanLimits(sdktrace.SpanLimits{AttributeCountLimit: 1}),
)
tracer := tp.Tracer("BenchmarkSpanSetAttributesOverCapacity")
ctx := context.Background()
attrs := make([]attribute.KeyValue, 128)
for i := range attrs {
key := fmt.Sprintf("key-%d", i)
attrs[i] = attribute.Bool(key, true)
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "/foo")
span.SetAttributes(attrs...)
span.End()
}
}

func BenchmarkStartEndSpan(b *testing.B) {
traceBenchmark(b, "Benchmark StartEndSpan", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
Expand Down

0 comments on commit 98bb105

Please sign in to comment.