Skip to content

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

Merged
dianashevchenko merged 4 commits into
shevchenko/tag-resource-samplingfrom
shevchenko/extend-span-sampling
Dec 18, 2023
Merged

ddtrace/tracer: account for resource, tags, and target_span when applying sampling rules#2407
dianashevchenko merged 4 commits into
shevchenko/tag-resource-samplingfrom
shevchenko/extend-span-sampling

Conversation

@dianashevchenko

@dianashevchenko dianashevchenko commented Dec 1, 2023

Copy link
Copy Markdown
Contributor

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

pr-commenter Bot commented Dec 1, 2023

Copy link
Copy Markdown

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

@knusbaum knusbaum left a comment

Copy link
Copy Markdown
Contributor

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.


// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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.

2 participants