|
41 | 41 | import datadog.trace.bootstrap.debugger.MethodLocation; |
42 | 42 | import datadog.trace.bootstrap.debugger.ProbeId; |
43 | 43 | import datadog.trace.bootstrap.debugger.ProbeImplementation; |
| 44 | +import datadog.trace.bootstrap.debugger.ProbeRateLimiter; |
44 | 45 | import datadog.trace.bootstrap.debugger.util.Redaction; |
45 | 46 | import datadog.trace.core.CoreTracer; |
46 | 47 | import java.io.IOException; |
@@ -78,6 +79,7 @@ public void setUp() { |
78 | 79 | public void after() { |
79 | 80 | super.after(); |
80 | 81 | Redaction.clearUserDefinedTypes(); |
| 82 | + ProbeRateLimiter.resetAll(); |
81 | 83 | } |
82 | 84 |
|
83 | 85 | @Test |
@@ -188,6 +190,11 @@ public void methodTagEvalError() throws IOException, URISyntaxException { |
188 | 190 | assertNull(span.getTags().get("tag1")); |
189 | 191 | assertEquals( |
190 | 192 | "Cannot dereference field: noarg", span.getTags().get("_dd.di.tag1.evaluation_error")); |
| 193 | + assertEquals(1, mockSink.getSnapshots().size()); |
| 194 | + Snapshot snapshot = mockSink.getSnapshots().get(0); |
| 195 | + assertEquals(1, snapshot.getEvaluationErrors().size()); |
| 196 | + assertEquals( |
| 197 | + "Cannot dereference field: noarg", snapshot.getEvaluationErrors().get(0).getMessage()); |
191 | 198 | } |
192 | 199 |
|
193 | 200 | @Test |
@@ -588,6 +595,43 @@ public void typeRedactionConditions() throws IOException, URISyntaxException { |
588 | 595 | snapshot.getEvaluationErrors().get(2).getMessage()); |
589 | 596 | } |
590 | 597 |
|
| 598 | + @Test |
| 599 | + public void ensureCallingSamplingTagEvalError() throws IOException, URISyntaxException { |
| 600 | + doSamplingTest(this::methodTagEvalError, 1, 1); |
| 601 | + } |
| 602 | + |
| 603 | + @Test |
| 604 | + public void ensureCallingSamplingMethodInvalidCondition() throws IOException, URISyntaxException { |
| 605 | + doSamplingTest(this::methodActiveSpanInvalidCondition, 1, 1); |
| 606 | + } |
| 607 | + |
| 608 | + @Test |
| 609 | + public void ensureCallingSamplingLineInvalidCondition() throws IOException, URISyntaxException { |
| 610 | + doSamplingTest(this::lineActiveSpanInvalidCondition, 1, 1); |
| 611 | + } |
| 612 | + |
| 613 | + @Test |
| 614 | + public void ensureCallingSamplingKeywordRedactionConditions() |
| 615 | + throws IOException, URISyntaxException { |
| 616 | + doSamplingTest(this::keywordRedactionConditions, 1, 1); |
| 617 | + } |
| 618 | + |
| 619 | + private void doSamplingTest( |
| 620 | + CapturingTestBase.TestMethod testRun, int expectedGlobalCount, int expectedProbeCount) |
| 621 | + throws IOException, URISyntaxException { |
| 622 | + MockSampler probeSampler = new MockSampler(); |
| 623 | + MockSampler globalSampler = new MockSampler(); |
| 624 | + ProbeRateLimiter.setSamplerSupplier(rate -> rate < 101 ? probeSampler : globalSampler); |
| 625 | + ProbeRateLimiter.setGlobalSnapshotRate(1000); |
| 626 | + try { |
| 627 | + testRun.run(); |
| 628 | + } finally { |
| 629 | + ProbeRateLimiter.setSamplerSupplier(null); |
| 630 | + } |
| 631 | + assertEquals(expectedGlobalCount, globalSampler.getCallCount()); |
| 632 | + assertEquals(expectedProbeCount, probeSampler.getCallCount()); |
| 633 | + } |
| 634 | + |
591 | 635 | private SpanDecorationProbe.Decoration createDecoration(String tagName, String valueDsl) { |
592 | 636 | List<SpanDecorationProbe.Tag> tags = |
593 | 637 | asList( |
|
0 commit comments