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 WithStatus option for use with RecordError #2887

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

treuherz
Copy link

@treuherz treuherz commented May 5, 2022

Fixes #1677 by adding a functional option that sets the Status of a
span when calling RecordError.

I'm not completely sure about the way I've tweaked the interfaces here.
So that they can be passed to addEvent, the options to RecordError
either all need to be EventOption, which I've achieved by embedding
EventOption in ErrorOption. This results in needing to implement a
no-op applyEvent for our one "pure" ErrorOption, and a no-op
applyError on the existing EventOptions. The only alternative I
can see would be doing the embedding the other way around, but then I
think RecordError would need to filter through its options to figure
out which ones to forward to addEvent. Happy to take a steer from the
maintainers here.

This is made a bit more confusing by WithStackTrace. It's EventOption
but it only has any effect if passed to RecordError, not AddEvent
(see #2336). I think this should be changed to an ErrorOption as it's
currently easy to misuse. This would simplify RecordError a bit as we
wouldn't have to process the event options twice in order to catch the
stacktrace, but the existence of EventConfig.StackTrace() makes that
tricky to do while maintaining perfect backwards-compatibility.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 5, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: treuherz / name: Eli Treuherz (201ed00)

Fixes open-telemetry#1677 by adding a functional option that sets the Status of a
span when calling RecordError.
@codecov
Copy link

codecov bot commented May 5, 2022

Codecov Report

Merging #2887 (201ed00) into main (c7cf945) will decrease coverage by 0.1%.
The diff coverage is 33.3%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #2887     +/-   ##
=======================================
- Coverage   75.7%   75.6%   -0.2%     
=======================================
  Files        177     177             
  Lines      11819   11850     +31     
=======================================
+ Hits        8950    8960     +10     
- Misses      2636    2657     +21     
  Partials     233     233             
Impacted Files Coverage Δ
bridge/opentracing/internal/mock.go 63.8% <0.0%> (-3.3%) ⬇️
internal/global/trace.go 90.7% <0.0%> (+1.6%) ⬆️
trace/noop.go 70.0% <0.0%> (+3.3%) ⬆️
trace/trace.go 98.2% <ø> (ø)
trace/config.go 54.8% <14.2%> (-9.4%) ⬇️
sdk/trace/span.go 88.3% <92.8%> (+0.4%) ⬆️
exporters/jaeger/jaeger.go 90.3% <0.0%> (-0.9%) ⬇️
sdk/trace/batch_span_processor.go 82.1% <0.0%> (+1.8%) ⬆️

@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Add a `WithStatus` option to `go.opentelemetry.io/otel/trace` to allow setting the span status when calling `span.RecordError`. (#1677)
Copy link
Member

Choose a reason for hiding this comment

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

I think saying to the trace package should be enough here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the full package name go.opentelemetry.io/otel/trace. It addresses the ambiguity of which trace package is being discussed and provides new users who are searching the docs a universality recognized package name.

@@ -357,7 +357,7 @@ type Span interface {
// additional call to SetStatus is required if the Status of the Span should
// be set to Error, as this method does not change the Span status. If this
// span is not being recorded or err is nil then this method does nothing.
RecordError(err error, options ...EventOption)
RecordError(err error, options ...ErrorOption)
Copy link
Member

Choose a reason for hiding this comment

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

I think changing this may warrant a major release.

Copy link
Author

Choose a reason for hiding this comment

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

I think there must be an argument covariance/contravariance case I've missed here. I'll see if I can find a way of doing it and keeping full backwards compat.

setErrorStatus bool
}

func (cfg *ErrorConfig) SetErrorStatus() bool {
Copy link
Member

Choose a reason for hiding this comment

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

Calling this SetErrorStatus kind of hints at a setter, which this isn't. How about naming the variable hasErrorStatus, and this method HasErrorStatus?

Copy link
Author

Choose a reason for hiding this comment

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

Agreed, will fix

@@ -171,17 +171,14 @@ func (nonRecordingSpan) IsRecording() bool { return false }
// SetStatus does nothing.
func (nonRecordingSpan) SetStatus(codes.Code, string) {}

// SetError does nothing.
func (nonRecordingSpan) SetError(bool) {}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why this method is being removed? It may be a cleanup. But then, I think it'd be better to do the removal in its own PR.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, sorry about that. I removed it as it looked like it was defunct, then decided I shouldn't be doing things like that in the same PR but didn't clean up all my clean-ups!

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

We cannot accept changes to the public API of this package. For more information please refer to our versioning policy. Please revert all changes that introduce compatibility issues.

@treuherz
Copy link
Author

treuherz commented May 9, 2022

I understand, I'll have another stab at doing it backwards-compatibly.

I don't know if you're planning through to the next major release yet, but is it worth me submitting a separate MR that's deliberately not backwards-compatible and trying to clean up both this and the WithStackTrace issue I mentioned above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants