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

Replace recordingSpan attributes implementation with map of attributes #2555

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed

- Jaeger exporter takes into additional 70 bytes overhead into consideration when sending UDP packets (#2489, #2512)
- The attributes returned from the `ReadOnlySpan` and `ReadWriteSpan` in `go.opentelemetry.io/otel/sdk/trace` are unordered.
Multiple calls to retrieve these attributes will return a slice of them that is not guaranteed to be in the same order.
If these attributes need to be consistently ordered, the `sort` package can be used.
Given these attributes will have unique keys `sort.Slice(attr, func(i, j int) bool { return attr[i].Key < attr[j].Key })` can be used to sort `attr` stably. (#2555)

### Deprecated

Expand All @@ -30,6 +34,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Change the `otlpmetric.Client` interface's `UploadMetrics` method to accept a single `ResourceMetrics` instead of a slice of them. (#2491)
- Specify explicit buckets in Prometheus example. (#2493)
- W3C baggage will now decode urlescaped values. (#2529)
- 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. (#2555)

### Removed

Expand Down
33 changes: 17 additions & 16 deletions exporters/otlp/otlptrace/otlptracegrpc/client_test.go
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"fmt"
"net"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -297,34 +298,34 @@ func TestNew_withMultipleAttributeTypes(t *testing.T) {

expected := []*commonpb.KeyValue{
{
Key: "Int",
Key: "Bool",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 1,
Value: &commonpb.AnyValue_BoolValue{
BoolValue: true,
},
},
},
{
Key: "Int64",
Key: "Float64",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 3,
Value: &commonpb.AnyValue_DoubleValue{
DoubleValue: 2.22,
},
},
},
{
Key: "Float64",
Key: "Int",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_DoubleValue{
DoubleValue: 2.22,
Value: &commonpb.AnyValue_IntValue{
IntValue: 1,
},
},
},
{
Key: "Bool",
Key: "Int64",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_BoolValue{
BoolValue: true,
Value: &commonpb.AnyValue_IntValue{
IntValue: 3,
},
},
},
Expand All @@ -339,10 +340,10 @@ func TestNew_withMultipleAttributeTypes(t *testing.T) {
}

// Verify attributes
if !assert.Len(t, rss[0].Attributes, len(expected)) {
t.Fatalf("attributes count: got %d, want %d\n", len(rss[0].Attributes), len(expected))
}
for i, actual := range rss[0].Attributes {
attr := rss[0].Attributes
require.Len(t, attr, len(expected))
sort.Slice(attr, func(i, j int) bool { return attr[i].Key < attr[j].Key })
for i, actual := range attr {
if a, ok := actual.Value.Value.(*commonpb.AnyValue_DoubleValue); ok {
e, ok := expected[i].Value.Value.(*commonpb.AnyValue_DoubleValue)
if !ok {
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 @@ -35,6 +36,28 @@ func BenchmarkStartEndSpan(b *testing.B) {
})
}

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 BenchmarkSpanWithAttributes_4(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
Expand Down