Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

- Added `Marshler` config option to `otlphttp` to enable otlp over json or protobufs. (#1586)
- Added non-empty string check for trace `Attribute` keys. (#1659)

### Removed

- Removed the exported `SimpleSpanProcessor` and `BatchSpanProcessor` structs.
Expand Down
4 changes: 3 additions & 1 deletion sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ func (s *span) copyToCappedAttributes(attributes ...attribute.KeyValue) {
s.mu.Lock()
defer s.mu.Unlock()
for _, a := range attributes {
if a.Value.Type() != attribute.INVALID {
// Ensure attributes conform to the specification:
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.1/specification/common/common.md#attributes
if a.Value.Type() != attribute.INVALID && a.Key != "" {
Comment thread
mrveera marked this conversation as resolved.
s.attributes.add(a)
}
}
Expand Down
35 changes: 35 additions & 0 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,41 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
}
}

func TestSetSpanAttributesWithInvalidKey(t *testing.T) {
te := NewTestExporter()
cfg := Config{SpanLimits: SpanLimits{}}
tp := NewTracerProvider(WithConfig(cfg), WithSyncer(te), WithResource(resource.Empty()))

span := startSpan(tp, "SpanToSetInvalidKeyOrValue")
span.SetAttributes(
attribute.Bool("", true),
attribute.Bool("key1", false),
)
got, err := endSpan(te, span)
if err != nil {
t.Fatal(err)
}

want := &export.SpanSnapshot{
SpanContext: trace.SpanContext{
TraceID: tid,
TraceFlags: 0x1,
},
ParentSpanID: sid,
Name: "span0",
Attributes: []attribute.KeyValue{
attribute.Bool("key1", false),
},
SpanKind: trace.SpanKindInternal,
HasRemoteParent: true,
DroppedAttributeCount: 0,
InstrumentationLibrary: instrumentation.Library{Name: "SpanToSetInvalidKeyOrValue"},
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("SetSpanAttributesWithInvalidKey: -got +want %s", diff)
}
}

func TestEvents(t *testing.T) {
te := NewTestExporter()
tp := NewTracerProvider(WithSyncer(te), WithResource(resource.Empty()))
Expand Down