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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- No longer set the links for a `Span` in `go.opentelemetry.io/otel/sdk/trace` that is configured to be a new root.
This is unspecified behavior that the OpenTelemetry community plans to standardize in the future.
To prevent backwards incompatible changes when it is specified, these links are removed. (#1726)
- Setting error status while recording error with Span from oteltest package. (#1729)

## [0.19.0] - 2021-03-18

Expand Down
1 change: 0 additions & 1 deletion oteltest/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (s *Span) RecordError(err error, opts ...trace.EventOption) {
errTypeString = errType.String()
}

s.SetStatus(codes.Error, "")
opts = append(opts, trace.WithAttributes(
errorTypeKey.String(errTypeString),
errorMessageKey.String(err.Error()),
Expand Down
30 changes: 1 addition & 29 deletions oteltest/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,39 +167,11 @@ func TestSpan(t *testing.T) {
},
}}
e.Expect(subject.Events()).ToEqual(expectedEvents)
e.Expect(subject.StatusCode()).ToEqual(codes.Error)
e.Expect(subject.StatusCode()).ToEqual(codes.Unset)
e.Expect(subject.StatusMessage()).ToEqual("")
}
})

t.Run("sets span status if provided", func(t *testing.T) {
t.Parallel()

e := matchers.NewExpecter(t)

tracer := tp.Tracer(t.Name())
_, span := tracer.Start(context.Background(), "test")

subject, ok := span.(*oteltest.Span)
e.Expect(ok).ToBeTrue()

errMsg := "test error message"
testErr := ottest.NewTestError(errMsg)
testTime := time.Now()
subject.RecordError(testErr, trace.WithTimestamp(testTime))

expectedEvents := []oteltest.Event{{
Timestamp: testTime,
Name: "error",
Attributes: map[attribute.Key]attribute.Value{
attribute.Key("error.type"): attribute.StringValue("go.opentelemetry.io/otel/internal/internaltest.TestError"),
attribute.Key("error.message"): attribute.StringValue(errMsg),
},
}}
e.Expect(subject.Events()).ToEqual(expectedEvents)
e.Expect(subject.StatusCode()).ToEqual(codes.Error)
})

t.Run("cannot be set after the span has ended", func(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 4 additions & 1 deletion trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ type Span interface {
// true if the Span is active and events can be recorded.
IsRecording() bool

// RecordError records an error as a Span event.
// RecordError will record err as a span event for this span. An additional call to
// SetStatus is required if the Status of the Span should be set to Error, this method
// does not change the Span status. If this span is not being recorded or err is nil
// than this method does nothing.
RecordError(err error, options ...EventOption)

// SpanContext returns the SpanContext of the Span. The returned
Expand Down