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

Add Span#RecordError method to simplify adding error events to spans #473

Merged
merged 10 commits into from
Feb 28, 2020

Conversation

Aneurysm9
Copy link
Member

Fixes #248.

I wonder whether Tracer#WithSpan should invoke this new method with the result of the user-provided function.

@lizthegrey
Copy link
Member

span.Error() feels slightly weird to me. ReportError() or SetError() as per original bug? dunno, curious what other approvers think.

@paivagustavo
Copy link
Member

Agree with @lizthegrey.

And since this is an implementation of the OpenTelemetry specs, I think we shouldn't be adding new methods to the Span API before changing the specs, I don't know the exactly process for these changes but I'm sure others could help.

@paivagustavo paivagustavo added pkg:API Related to an API package area:trace Part of OpenTelemetry tracing labels Feb 11, 2020
@Aneurysm9
Copy link
Member Author

Understandable. I had thought that since #248 wasn't tagged as "blocked on spec" and the new method related specifically to Go error handling it might not require spec changes. I'd be happy to help draft and shepherd changes to the spec through the process if someone can point me in the right direction and maybe show some examples of similar changes that have made it through the process.

@lizthegrey
Copy link
Member

am discussing at spec meeting now (you're welcome to join)

@lizthegrey
Copy link
Member

someone filled me in, what we want is open-telemetry/opentelemetry-specification#427

@lizthegrey
Copy link
Member

We're clear to use our judgment for 0.3, but we may need to change it between here and 0.4

@Aneurysm9
Copy link
Member Author

Ok, so based on a brief reading of open-telemetry/opentelemetry-specification#427 it looks like the direction to go would be changing this to span.RecordError() and adding an event rather than setting an attribute and status code. If that seems appropriate I'll take another swing at this.

@lizthegrey
Copy link
Member

I think that setting the attribute/status code is actually fine, because otherwise it'll require more complex cross-span/event correlation where just setting an attribute would do. I'll chime in to that effect on the upstream spec discussion

@jmacd
Copy link
Contributor

jmacd commented Feb 11, 2020

changing this to span.RecordError() and adding an event rather than setting an attribute and status code.

+1

The implementation in the SDK package now relies on existing API methods.
@Aneurysm9 Aneurysm9 changed the title Add Span#Error method to simplify setting an error status and message. Add Span#RecordError method to simplify adding error events to spans Feb 12, 2020
@wingyplus
Copy link
Contributor

I try with Jaeger exporter on my forked of gomongowrapper, it's seems like it's needs to called SetStatus to mark span to be an error. So I start thinking that ErrorConfig should accept status code to make it configurable. And then set status in RecordError if status is not zero. Not sure what do you think?

@Aneurysm9
Copy link
Member Author

That's a good point and something lost when moving from status/attributes to recording an event. I've added a WithErrorStatus(codes.Code) option that will set the span status if given a value != codes.OK.

Copy link
Member

@krnowak krnowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some nitpicking.

api/trace/api.go Outdated Show resolved Hide resolved
api/trace/api.go Outdated Show resolved Hide resolved
api/trace/context_test.go Outdated Show resolved Hide resolved
api/trace/noop_span.go Outdated Show resolved Hide resolved
internal/trace/mock_span.go Outdated Show resolved Hide resolved
sdk/trace/trace_test.go Outdated Show resolved Hide resolved
sdk/trace/trace_test.go Outdated Show resolved Hide resolved
sdk/trace/trace_test.go Outdated Show resolved Hide resolved
sdk/trace/trace_test.go Outdated Show resolved Hide resolved
sdk/trace/trace_test.go Outdated Show resolved Hide resolved
Aneurysm9 and others added 3 commits February 17, 2020 21:22
Co-Authored-By: Krzesimir Nowak <qdlacz@gmail.com>
* Ensure complete and unique error type is recorded for defined types
* Avoid duplicating logic under test in tests
Copy link
Member

@krnowak krnowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing (honest!), otherwise looks good.

api/trace/testtrace/span_test.go Outdated Show resolved Hide resolved
}

if cfg.Status != codes.OK {
s.SetStatus(cfg.Status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line raises questions for me about the SetStatus API, which is tangential to this PR. The Span.Status field has two fields, the code (passed here) and a message. This should probably set the same err.Error() as used for the event message, but the SetStatus API doesn't accept a message string (which is a separate matter).

This has me wondering whether we want to use RecordError(..., WithStatusCode()) as the conventional pattern for recording an error and setting the status. I'm not sure I'd pick this approach -- I'm inclined for there to be two methods, one to record an error event, and one to record an error event plus set the status (i.e., two methods RecordErrorEvent and RecordErrorStatus).

@rghetia rghetia merged commit ca3f74d into open-telemetry:master Feb 28, 2020
@Aneurysm9 Aneurysm9 deleted the OTG-248 branch February 28, 2020 22:33
@pellared pellared added this to the untracked milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:trace Part of OpenTelemetry tracing pkg:API Related to an API package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal for a Span#Error
8 participants