Skip to content

feat(contrib/IBM/sarama): add WithErrorCheck option - #5244

Draft
thatliuser wants to merge 3 commits into
DataDog:mainfrom
thatliuser:main
Draft

feat(contrib/IBM/sarama): add WithErrorCheck option#5244
thatliuser wants to merge 3 commits into
DataDog:mainfrom
thatliuser:main

Conversation

@thatliuser

Copy link
Copy Markdown

What does this PR do?

Adds a WithErrorCheck option to the IBM/sarama wrapper which allows library users to drop specific errors from being sent to DataDog.

Motivation

Implements the feature described in discussion #5243. Similar features have been merged for other wrappers such as in #773, #806, #1315.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Unsure? Have a question? Request a review!

@thatliuser
thatliuser requested review from a team as code owners August 22, 2026 02:20
@thatliuser
thatliuser requested review from rarguelloF and removed request for a team August 22, 2026 02:20
@thatliuser
thatliuser marked this pull request as draft August 22, 2026 02:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4b4034576

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

err := p.SyncProducer.SendMessages(msgs)
for i, span := range spans {
finishProducerSpan(span, msgs[i].Partition, msgs[i].Offset, err)
finishProducerSpan(span, msgs[i].Partition, msgs[i].Offset, err, p.cfg)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Evaluate each batch message's error separately

When SendMessages returns sarama.ProducerErrors, err aggregates failures from the entire batch, but this passes that same aggregate to every message's checker. For a batch containing both an ignorable error and a real failure, a typical checker such as !errors.Is(err, ignoredErr) suppresses the aggregate—and therefore marks every span successful, including the span for the real failure. Match each ProducerError.Msg to its input message and finish each span with only that message's error.

Useful? React with 👍 / 👎.

// span right away because there's no way to know when it will
// be done
span.Finish()
finishSpan(span, nil, cfg)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve async spans until errors can be checked

When Producer.Return.Successes is false—the default async-producer mode—this finishes the span immediately and never inserts it into spans. If the broker later emits a ProducerError, the error path cannot find the span, so WithErrorCheck is never invoked and even a checker returning true leaves the failed produce span marked successful. The new test masks this case by always enabling successes; the option must either support error outcomes in the default mode or explicitly reject/document that configuration.

Useful? React with 👍 / 👎.

Comment on lines +141 to +144
// WithErrorCheck specifies a function fn which determines whether the passed
// error should be marked as an error. The fn is called whenever a Kafka producer
// request finishes with an error.
func WithErrorCheck(fn func(err error) bool) OptionFn {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the new tracer customization in CONTRIBUTING

This public option introduces a new way for users to customize which producer failures mark spans as errors, but the commit does not update CONTRIBUTING.md to describe the feature or its usage constraints. Add the required documentation for this significant tracer customization, including the async-producer limitation and batch-error behavior.

AGENTS.md reference: AGENTS.md:L21-L24

Useful? React with 👍 / 👎.

@darccio

darccio commented Aug 28, 2026

Copy link
Copy Markdown
Member

/gardener shadow

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.

2 participants