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

datadog: Add tracer option to check error eligibility in the span #1438

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

vaihtovirta
Copy link
Contributor

@vaihtovirta vaihtovirta commented Apr 9, 2024

What was changed

Added an option to datadog tracer that allows to determine whether an error is eligible to be added to the DD span.

Similar functionality in gorm dd instrumentation: WithErrorCheck

Why?

Not all errors need to be reported to Datadog (intermediate retry error, validation error, etc).
Users can filter out such errors via specifying a custom function via the option.

Checklist

  1. How was this tested:
    I've added simple unit tests.

  2. Any docs updates needed?
    I didn't find docs related to temporal datadog tracer in the repository, but potentially this page can mention the new option: https://docs.temporal.io/dev-guide/go/observability#useful-resources

@vaihtovirta vaihtovirta requested a review from a team as a code owner April 9, 2024 20:04
@CLAassistant
Copy link

CLAassistant commented Apr 9, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me, will want @Quinn-With-Two-Ns's thoughts.

Comment on lines 50 to 51
// ErrCheckFn can be set to a custom function to determine if an error should be traced.
ErrCheckFn func(err error) bool
Copy link
Member

Choose a reason for hiding this comment

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

Fn not an abbreviation we usually use. How about:

Suggested change
// ErrCheckFn can be set to a custom function to determine if an error should be traced.
ErrCheckFn func(err error) bool
// CheckError can be set to a custom function to determine if an error should be traced.
CheckError func(error) bool

Or maybe even better and more flexible:

Suggested change
// ErrCheckFn can be set to a custom function to determine if an error should be traced.
ErrCheckFn func(err error) bool
// OnFinish sets finish options. If unset, this will use [tracer.WithError] if
// [interceptor.TracerFinishSpanOptions.Error] is non-nil and not
// [workflow.IsContinueAsNewError].
OnFinish func(*interceptor.TracerFinishSpanOptions) []tracer.FinishOption

@Quinn-With-Two-Ns, preference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the naming, will be waiting for the final decision regarding the more flexible option.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to using TracerFinishSpanOptions to allow us to add more fields in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented 👌

t.Span.Finish(opts...)
}

func (t *tracerSpan) shouldErrBeTraced(err error) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Can just inline this, no need for a separate method (but no biggie)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

err := options.Error
isErrEligible := err != nil &&
!workflow.IsContinueAsNewError(err) &&
t.CheckError != nil && t.CheckError(err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.CheckError != nil && t.CheckError(err)
(t.CheckError == nil || t.CheckError(err))

Otherwise no error will ever be tracked unless they set the option. Alternatively you could just default check error to be a default impl that checks for continue-as-new error and tell users that so if they override, they can choose whether continue-as-new is counted.

Comment on lines +65 to +75
if opts.OnFinish == nil {
opts.OnFinish = func(options *interceptor.TracerFinishSpanOptions) []tracer.FinishOption {
var finishOpts []tracer.FinishOption

if err := options.Error; err != nil && !workflow.IsContinueAsNewError(err) {
finishOpts = append(finishOpts, tracer.WithError(err))
}

return finishOpts
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of having if-else statement in the Finish function, I've decided to set a default function in the constructor.

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 this is a good approach

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Comment on lines +65 to +75
if opts.OnFinish == nil {
opts.OnFinish = func(options *interceptor.TracerFinishSpanOptions) []tracer.FinishOption {
var finishOpts []tracer.FinishOption

if err := options.Error; err != nil && !workflow.IsContinueAsNewError(err) {
finishOpts = append(finishOpts, tracer.WithError(err))
}

return finishOpts
}
}
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 this is a good approach

Copy link
Contributor

@Quinn-With-Two-Ns Quinn-With-Two-Ns left a comment

Choose a reason for hiding this comment

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

LGTM, I think you just need to rebase and that would fix the feature tests

@vaihtovirta vaihtovirta force-pushed the datadog-err-check-fn-option branch from 7a32eca to e62646d Compare April 12, 2024 15:18
@cretz cretz merged commit c4bf074 into temporalio:master Apr 12, 2024
13 checks passed
@vaihtovirta vaihtovirta deleted the datadog-err-check-fn-option branch April 13, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants