-
Notifications
You must be signed in to change notification settings - Fork 258
OpenTelemetry: Specify span kind and don't set error type for benign exception #2048
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package opentelemetry | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/otel" | ||
|
@@ -14,6 +15,7 @@ import ( | |
|
||
"go.temporal.io/sdk/interceptor" | ||
"go.temporal.io/sdk/log" | ||
"go.temporal.io/sdk/temporal" | ||
) | ||
|
||
// DefaultTextMapPropagator is the default OpenTelemetry TextMapPropagator used | ||
|
@@ -196,8 +198,13 @@ func (t *tracer) StartSpan(opts *interceptor.TracerStartSpanOptions) (intercepto | |
} | ||
} | ||
|
||
spanKind := trace.SpanKindServer | ||
if opts.Outbound { | ||
spanKind = trace.SpanKindClient | ||
} | ||
|
||
// Create span | ||
span := t.options.SpanStarter(ctx, t.options.Tracer, opts.Operation+":"+opts.Name, trace.WithTimestamp(opts.Time)) | ||
span := t.options.SpanStarter(ctx, t.options.Tracer, opts.Operation+":"+opts.Name, trace.WithTimestamp(opts.Time), trace.WithSpanKind(spanKind)) | ||
|
||
// Set tags | ||
if len(opts.Tags) > 0 { | ||
|
@@ -241,12 +248,22 @@ type tracerSpan struct { | |
} | ||
|
||
func (t *tracerSpan) Finish(opts *interceptor.TracerFinishSpanOptions) { | ||
if opts.Error != nil { | ||
if opts.Error != nil && !isBenignApplicationError(opts.Error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our implementation may not have been doing the right thing here because we are not calling |
||
t.SetStatus(codes.Error, opts.Error.Error()) | ||
} | ||
t.End() | ||
} | ||
|
||
func isBenignApplicationError(err error) bool { | ||
var appErr *temporal.ApplicationError | ||
if temporal.IsApplicationError(err) { | ||
if errors.As(err, &appErr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per #1925 (comment), we should only look at the top-level error to determine whether benign. Mimic the |
||
return appErr.Category() == temporal.ApplicationErrorCategoryBenign | ||
} | ||
} | ||
return false | ||
} | ||
|
||
type textMapCarrier map[string]string | ||
|
||
func (t textMapCarrier) Get(key string) string { return t[key] } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"go.temporal.io/sdk/temporal" | ||
|
||
"github.com/opentracing/opentracing-go" | ||
|
||
|
@@ -164,9 +165,19 @@ type tracerSpanRef struct{ opentracing.SpanContext } | |
type tracerSpan struct{ opentracing.Span } | ||
|
||
func (t *tracerSpan) Finish(opts *interceptor.TracerFinishSpanOptions) { | ||
if opts.Error != nil { | ||
if opts.Error != nil && !isBenignApplicationError(opts.Error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open tracing is deprecated, not sure we should bother fixing it here/ do a release to publish this |
||
// Standard tag that can be bridged to OpenTelemetry | ||
t.SetTag("error", "true") | ||
} | ||
t.Span.Finish() | ||
} | ||
|
||
func isBenignApplicationError(err error) bool { | ||
var appErr *temporal.ApplicationError | ||
if temporal.IsApplicationError(err) { | ||
if errors.As(err, &appErr) { | ||
return appErr.Category() == temporal.ApplicationErrorCategoryBenign | ||
} | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this line up roughly with what other SDKs like dotnet or python do?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so (though I think I just spotted a bug in Python for outbound signal child workflow)