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

tracer: support dot notation for tags with array values #2253

Merged
merged 7 commits into from Nov 28, 2023

Conversation

katiehockman
Copy link
Contributor

@katiehockman katiehockman commented Oct 6, 2023

What does this PR do?

Improves array support in tag values by automatically encoding arrays with dot notation.

With the following code snippet:

span := tracer.StartSpan("somename", tracer.Tag("custom", []string{"foo", "bar"}))

Before (just a string):
Screenshot 2023-10-06 at 2 53 53 PM

After (an array):
Screenshot 2023-10-06 at 2 53 45 PM

Note that this only supports one level of array nesting. Any more, and the user will need to do this manually.

AIT-8525

Motivation

This supports more precise search queries and filtering. For example, with the previous code, a DD_APM_REPLACE_TAG with custom would have removed the entire array. Now, a DD_APM_REPLACE_TAG with custom will do nothing. A customer will instead specify the index, e.g. a DD_APM_REPLACE_TAG with custom.1, to only redact the indices they want, or do custom.* to redact them all.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • 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.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@katiehockman katiehockman added this to the Triage milestone Oct 6, 2023
@katiehockman katiehockman requested a review from a team October 6, 2023 18:57
@pr-commenter
Copy link

pr-commenter bot commented Oct 6, 2023

Benchmarks

Benchmark execution time: 2023-11-20 16:34:14

Comparing candidate commit d97386a in PR branch katie.hockman/otel-span-arrays with baseline commit 9cf50b3 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 39 metrics, 2 unstable metrics.

Copy link

github-actions bot commented Nov 1, 2023

This PR is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Stuck for more than 1 month label Nov 1, 2023
@katiehockman
Copy link
Contributor Author

Adding a comment to un-mark this as stale. I still want to do this, but I haven't had time to manually test it yet.

@github-actions github-actions bot removed the stale Stuck for more than 1 month label Nov 2, 2023
@katiehockman
Copy link
Contributor Author

Because these changes will cause reflect to be called on every tag, there is a small performance cost if the code is reached. For example, if the code is above the Stringer check, then it adds a check every time a tag is added to see if it's a slice.

benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer
                  │   old.txt   │              new.txt               │
                  │   sec/op    │   sec/op     vs base               │
SetTagMetric-10     42.37n ± 2%   42.74n ± 3%       ~ (p=0.631 n=10)
SetTagString-10     39.99n ± 3%   39.81n ± 3%       ~ (p=0.579 n=10)
SetTagStringer-10   54.71n ± 2%   56.82n ± 2%  +3.87% (p=0.000 n=10)
SetTagField-10      18.61n ± 1%   18.55n ± 2%       ~ (p=0.361 n=10)
geomean             36.24n        36.60n       +0.97%

I'm not terribly concerned by 2 nanoseconds, but it could in theory add up if someone has many tags. I moved the check to be as low down the list of checks as possible so it's hopefully not hit in most cases (I expect the majority of tags are strings, ints, floats).

@katiehockman
Copy link
Contributor Author

The parametric tests caught a bug in the way we were encoding the value, which should now be fixed. The system-tests PR is here: DataDog/system-tests#1841

@katiehockman
Copy link
Contributor Author

katiehockman commented Nov 14, 2023

And the failing parametric test in this PR is because it relies on old behavior. DataDog/system-tests#1841 will skip that test and enable the new one.

@katiehockman katiehockman enabled auto-merge (squash) November 28, 2023 21:47
@katiehockman katiehockman merged commit ee63bf7 into main Nov 28, 2023
50 of 51 checks passed
@katiehockman katiehockman deleted the katie.hockman/otel-span-arrays branch November 28, 2023 21:47
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.

None yet

3 participants