Skip to content

Commit

Permalink
add SetAttribute(string,interface{}) (open-telemetry#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizthegrey authored Apr 28, 2020
1 parent 3809f7b commit ee30252
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type Span interface {

// Set span attributes
SetAttributes(...core.KeyValue)

// Set singular span attribute, with type inference.
SetAttribute(string, interface{})
}

// StartOption applies changes to StartConfig that sets options at span start time.
Expand Down
4 changes: 4 additions & 0 deletions api/trace/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func (mockSpan) SetError(v bool) {
func (mockSpan) SetAttributes(attributes ...core.KeyValue) {
}

// SetAttribute does nothing.
func (mockSpan) SetAttribute(k string, v interface{}) {
}

// End does nothing.
func (mockSpan) End(options ...trace.EndOption) {
}
Expand Down
4 changes: 4 additions & 0 deletions api/trace/noop_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func (NoopSpan) SetError(v bool) {
func (NoopSpan) SetAttributes(attributes ...core.KeyValue) {
}

// SetAttribute does nothing.
func (NoopSpan) SetAttribute(k string, v interface{}) {
}

// End does nothing.
func (NoopSpan) End(options ...EndOption) {
}
Expand Down
5 changes: 5 additions & 0 deletions api/trace/testtrace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"google.golang.org/grpc/codes"

"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/api/trace"
)

Expand Down Expand Up @@ -177,6 +178,10 @@ func (s *Span) SetAttributes(attrs ...core.KeyValue) {
}
}

func (s *Span) SetAttribute(k string, v interface{}) {
s.SetAttributes(key.Infer(k, v))
}

// Name returns the name most recently set on the Span, either at or after creation time.
// It cannot be change after End has been called on the Span.
func (s *Span) Name() string {
Expand Down
4 changes: 4 additions & 0 deletions bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
})
}

func (s *MockSpan) SetAttribute(k string, v interface{}) {
s.SetAttributes(otelkey.Infer(k, v))
}

func (s *MockSpan) applyUpdate(update otelcorrelation.MapUpdate) {
s.Attributes = s.Attributes.Apply(update)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/trace/mock_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (ms *MockSpan) SetError(v bool) {
func (ms *MockSpan) SetAttributes(attributes ...core.KeyValue) {
}

// SetAttribute does nothing.
func (ms *MockSpan) SetAttribute(k string, v interface{}) {
}

// End does nothing.
func (ms *MockSpan) End(options ...apitrace.EndOption) {
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"google.golang.org/grpc/codes"

"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/key"
apitrace "go.opentelemetry.io/otel/api/trace"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/internal"
Expand Down Expand Up @@ -100,6 +101,10 @@ func (s *span) SetAttributes(attributes ...core.KeyValue) {
s.copyToCappedAttributes(attributes...)
}

func (s *span) SetAttribute(k string, v interface{}) {
s.SetAttributes(key.Infer(k, v))
}

func (s *span) End(options ...apitrace.EndOption) {
if s == nil {
return
Expand Down

0 comments on commit ee30252

Please sign in to comment.