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

ddtrace/tracer: account for resource, tags, and target_span when applying sampling rules #2407

Conversation

dianashevchenko
Copy link
Contributor

@dianashevchenko dianashevchenko commented Dec 1, 2023

What does this PR do?

This PR changes the sampling rule matching logic. Tests are updated accordingly.
Additionally, updated the MarshalJSON method of the SamplingRule.

What to remember when reviewing

  • three fields are added to the sampling rule - tags, resource, target_span
  • target_span is set only on trace rule
  • the only (at least intended) change in regexes is I added "target_span":"any", where it was applicable

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.

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!

@pr-commenter
Copy link

pr-commenter bot commented Dec 1, 2023

Benchmarks

Benchmark execution time: 2023-12-01 15:01:58

Comparing candidate commit 50bcd69 in PR branch shevchenko/extend-span-sampling with baseline commit 5ffad80 in branch shevchenko/tag-resource-sampling.

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

@dianashevchenko dianashevchenko marked this pull request as ready for review December 6, 2023 14:16
@dianashevchenko dianashevchenko requested a review from a team December 6, 2023 14:16
Copy link
Contributor

@knusbaum knusbaum left a comment

Choose a reason for hiding this comment

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

A couple comments.

I think there's some stuff I'm not familiar with in shevchenko/tag-resource-sampling such as TagsResourceRule that it would be helpful to have a PR up for as well.

@@ -87,6 +87,9 @@ type SamplingRule struct {

// match returns true when the span's details match all the expected values in the rule.
func (sr *SamplingRule) match(s *span) bool {
if sr.TargetRoot && s.root().SpanID != s.SpanID {
Copy link
Contributor

Choose a reason for hiding this comment

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

How likely is s.root() to return nil, or for s to be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Span can be newly created with all the necessary / fields / context filled out, but never nil. Subsequently, root wouldn't be nil. The match function is called only within sampling functionality on a trace / chunk, and thus span is never empty.

Comment on lines +108 to +112
v, ok := s.Meta[k]
if !ok || !regex.MatchString(v) {
return false
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this should match both Meta and Metrics.

It's not specified in the RFC how numbers should be represented. Maybe talk with the authors about how this should work.

@dianashevchenko dianashevchenko merged commit f45d036 into shevchenko/tag-resource-sampling Dec 18, 2023
51 checks passed
@dianashevchenko dianashevchenko deleted the shevchenko/extend-span-sampling branch December 18, 2023 16:39
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

2 participants