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

Support sending custom tags when using pollDBStats #3067

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

Conversation

KaibutsuX
Copy link

What does this PR do?

Motivation

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.
  • 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.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@KaibutsuX KaibutsuX requested review from a team as code owners January 6, 2025 19:19
contrib/database/sql/option.go Outdated Show resolved Hide resolved
Comment on lines +41 to +49
statsd.Gauge(MaxOpenConnections, float64(stat.MaxOpenConnections), tags, 1)
statsd.Gauge(OpenConnections, float64(stat.OpenConnections), tags, 1)
statsd.Gauge(InUse, float64(stat.InUse), tags, 1)
statsd.Gauge(Idle, float64(stat.Idle), tags, 1)
statsd.Gauge(WaitCount, float64(stat.WaitCount), tags, 1)
statsd.Timing(WaitDuration, stat.WaitDuration, tags, 1)
statsd.Gauge(MaxIdleClosed, float64(stat.MaxIdleClosed), tags, 1)
statsd.Gauge(MaxIdleTimeClosed, float64(stat.MaxIdleTimeClosed), tags, 1)
statsd.Gauge(MaxLifetimeClosed, float64(stat.MaxLifetimeClosed), tags, 1)
Copy link
Member

Choose a reason for hiding this comment

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

@mtoffl01 Was there any reason behind not allowing tags from the beginning?

Checking the code, I see that for the purpose of this PR, it should be enough to set DD_TAGS or OTEL_PROPAGATORS (if using OTel) to set these global tags.

WDYT @KaibutsuX?

Copy link
Author

Choose a reason for hiding this comment

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

I don't have enough context or documentation to know what DD_TAGS is or how I would set it as an end-user.

Copy link
Member

Choose a reason for hiding this comment

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

DD_TAGS is properly explained in our Go tracer public documentation.

We understand this should be enough to achieve what you are trying with this PR.

Copy link
Author

Choose a reason for hiding this comment

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

That links says: "A list of default tags to be added to every span and profile." From my tracing through the code, I could not see that this same list of user-supplied tags was included in these metrics used in pollDBStats

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we understand it may not that be clear from the code. Sorry about that. It inherits the global tags from the tracer config, set by globalconfig.SetStatsTags, which is initialized by newConfig, and retrieved when setting up the DB statsd client.

We'll update the public documentation to make sure it reflects this detail.

@mtoffl01
Copy link
Contributor

Hi @KaibutsuX ,

As @darccio pointed out, tags set in DD_TAGS are applied to DBStats metrics. We are updating the Go tracer public documentation to include "metrics" in the list of data to which tags are applied to, so this should be clear for future readers.

Are you trying to pass your global tags down to DBStats metrics, or are you looking to apply a unique set of tags specifically to those metrics? If the former, DD_TAGS will do the trick. If the latter, this feature is not currently supported, but we'd be happy to learn more about your use case so we can consider implementing it.

Thank you!

@KaibutsuX
Copy link
Author

@mtoffl01 I will see if using DD_TAGS works as expected.

You may want to also update the documentation for DD_TAGS as it is marked as an array, but in go code it accepts a map[string]interface{} which implicitly only respects the entries that can be asserted as strings. Further, it's unclear that the labels will be formatted as labelKey:labelValue.(string) especially since the documentation explicitly says that DD_TAGS supports multiple values as csv using commas or spaces.

@mtoffl01
Copy link
Contributor

Hi @KaibutsuX ,

Thanks for the tip! We will change the Default value in the docs and update the description to specify that keys and values should be string-convertible types. In the meantime, keep us posted on your success with DD_TAGS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-info waiting for answer from issue creator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants