Skip to content

contrib/gomongodb.org/mongo-driver: add optional query tag truncation #3679

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

colinking
Copy link

@colinking colinking commented Jun 20, 2025

What does this PR do?

This PR adds support for a WithMaxQuerySize option to the MongoDB module that configures truncation on the mongodb.query span tag.

Ideally, we default to enabling truncation. However, this PR currently maintains backwards-compatibility by defaulting to no truncation. I'll defer to the DataDog team on whether we can change this default.

I've also ported this behavior to the mongo-driver.v2 module.

Fixes #3672

Motivation

See: #3672

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 golangci-lint run locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

### What does this PR do?

This PR adds support for a `WithMaxQuerySize` method to the MongoDB package that enables truncation on the `mongodb.query` span tag.

I also ported this behavior to the new `mongo-driver.v2` package which supports the v2 release of the Mongo drivers.

Opening this PR here first for feedback from our team and then will open on the upstream repo.

The default is to not truncate query span tags, to avoid breaking changes. I'll ask in the upstream PR about whether we could truncate by default instead.

### Motivation

This reduces the memory footprint of tracing Mongo applications that write large documents.
@colinking colinking marked this pull request as ready for review June 20, 2025 17:33
@colinking colinking requested review from a team as code owners June 20, 2025 17:33
This PR updates the behavior of `WithMaxQuerySize` when `max=0` to avoid attaching the query tag entirely. This is more intuitive ("max query size of zero") and gives folks a way to disable serializing the command entirely.
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.

[BUG]: MongoDB query span tag should be truncated
1 participant