|
7 | 7 |
|
8 | 8 | import com.datadog.debugger.sink.Snapshot;
|
9 | 9 | import datadog.trace.bootstrap.debugger.CapturedContext;
|
| 10 | +import datadog.trace.bootstrap.debugger.EvaluationError; |
10 | 11 | import datadog.trace.bootstrap.debugger.MethodLocation;
|
11 | 12 | import datadog.trace.bootstrap.debugger.ProbeId;
|
12 | 13 | import java.util.stream.Stream;
|
@@ -134,12 +135,35 @@ private static Stream<Arguments> statusValues() {
|
134 | 135 | public void fillSnapshot_shouldSend_exit() {
|
135 | 136 | LogProbe logProbe = createLog(null).evaluateAt(MethodLocation.EXIT).build();
|
136 | 137 | CapturedContext entryContext = new CapturedContext();
|
137 |
| - entryContext.evaluate(PROBE_ID.getEncodedId(), logProbe, "", 0, MethodLocation.ENTRY); |
138 |
| - entryContext.getStatus(PROBE_ID.getEncodedId()); |
| 138 | + prepareContext(entryContext, logProbe, MethodLocation.ENTRY); |
| 139 | + CapturedContext exitContext = new CapturedContext(); |
| 140 | + prepareContext(exitContext, logProbe, MethodLocation.EXIT); |
| 141 | + Snapshot snapshot = new Snapshot(Thread.currentThread(), logProbe, 10); |
| 142 | + assertTrue(logProbe.fillSnapshot(entryContext, exitContext, null, snapshot)); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void fillSnapshot_shouldSend_evalErrors() { |
| 147 | + LogProbe logProbe = createLog(null).evaluateAt(MethodLocation.EXIT).build(); |
| 148 | + CapturedContext entryContext = new CapturedContext(); |
| 149 | + LogProbe.LogStatus logStatus = prepareContext(entryContext, logProbe, MethodLocation.ENTRY); |
| 150 | + logStatus.addError(new EvaluationError("expr", "msg1")); |
| 151 | + logStatus.setLogTemplateErrors(true); |
| 152 | + entryContext.addThrowable(new RuntimeException("errorEntry")); |
139 | 153 | CapturedContext exitContext = new CapturedContext();
|
140 |
| - exitContext.evaluate(PROBE_ID.getEncodedId(), logProbe, "", 0, MethodLocation.EXIT); |
| 154 | + logStatus = prepareContext(exitContext, logProbe, MethodLocation.EXIT); |
| 155 | + logStatus.addError(new EvaluationError("expr", "msg2")); |
| 156 | + logStatus.setLogTemplateErrors(true); |
| 157 | + exitContext.addThrowable(new RuntimeException("errorExit")); |
141 | 158 | Snapshot snapshot = new Snapshot(Thread.currentThread(), logProbe, 10);
|
142 | 159 | assertTrue(logProbe.fillSnapshot(entryContext, exitContext, null, snapshot));
|
| 160 | + assertEquals(2, snapshot.getEvaluationErrors().size()); |
| 161 | + assertEquals("msg1", snapshot.getEvaluationErrors().get(0).getMessage()); |
| 162 | + assertEquals("msg2", snapshot.getEvaluationErrors().get(1).getMessage()); |
| 163 | + assertEquals( |
| 164 | + "errorEntry", snapshot.getCaptures().getEntry().getCapturedThrowable().getMessage()); |
| 165 | + assertEquals( |
| 166 | + "errorExit", snapshot.getCaptures().getReturn().getCapturedThrowable().getMessage()); |
143 | 167 | }
|
144 | 168 |
|
145 | 169 | private LogProbe.Builder createLog(String template) {
|
|
0 commit comments