Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public Status evaluate(
ProbeImplementation probeImplementation,
String thisClassName,
long startTimestamp,
MethodLocation methodLocation) {
MethodLocation methodLocation,
boolean singleProbe) {
Status status =
statusByProbeId.computeIfAbsent(
probeImplementation.getProbeId().getEncodedId(),
Expand All @@ -311,7 +312,7 @@ public Status evaluate(
boolean shouldEvaluate =
MethodLocation.isSame(methodLocation, probeImplementation.getEvaluateAt());
if (shouldEvaluate) {
probeImplementation.evaluate(this, status, methodLocation);
probeImplementation.evaluate(this, status, methodLocation, singleProbe);
}
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ public static void evalContext(
}
CapturedContext.Status status =
context.evaluate(
probeImplementation, callingClass.getTypeName(), startTimestamp, methodLocation);
probeImplementation,
callingClass.getTypeName(),
startTimestamp,
methodLocation,
false);
needFreeze |= status.shouldFreezeContext();
}
// only freeze the context when we have at lest one snapshot probe, and we should send
Expand Down Expand Up @@ -343,7 +347,11 @@ public static void evalContext(
}
CapturedContext.Status status =
context.evaluate(
probeImplementation, callingClass.getTypeName(), startTimestamp, methodLocation);
probeImplementation,
callingClass.getTypeName(),
startTimestamp,
methodLocation,
true);
boolean needFreeze = status.shouldFreezeContext();
// only freeze the context when we have at lest one snapshot probe, and we should send
// snapshot
Expand Down Expand Up @@ -371,7 +379,7 @@ public static void evalContextAndCommit(
continue;
}
context.evaluate(
probeImplementation, callingClass.getTypeName(), -1, MethodLocation.DEFAULT);
probeImplementation, callingClass.getTypeName(), -1, MethodLocation.DEFAULT, false);
probeImplementations.add(probeImplementation);
}
for (ProbeImplementation probeImplementation : probeImplementations) {
Expand All @@ -395,7 +403,8 @@ public static void evalContextAndCommit(
if (probeImplementation == null) {
return;
}
context.evaluate(probeImplementation, callingClass.getTypeName(), -1, MethodLocation.DEFAULT);
context.evaluate(
probeImplementation, callingClass.getTypeName(), -1, MethodLocation.DEFAULT, true);
probeImplementation.commit(context, line);
} catch (Exception ex) {
LOGGER.debug("Error in evalContextAndCommit: ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public interface ProbeImplementation {
String getStrTags();

void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation methodLocation);
CapturedContext context,
CapturedContext.Status status,
MethodLocation methodLocation,
boolean singleProbe);

void commit(
CapturedContext entryContext,
Expand Down Expand Up @@ -82,7 +85,10 @@ public String getStrTags() {

@Override
public void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation methodLocation) {}
CapturedContext context,
CapturedContext.Status status,
MethodLocation methodLocation,
boolean singleProbe) {}

@Override
public void commit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public CapturedContext.Status createStatus() {

@Override
public void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation methodLocation) {
CapturedContext context,
CapturedContext.Status status,
MethodLocation methodLocation,
boolean singleProbe) {
ExceptionProbeStatus exceptionStatus;
if (status instanceof ExceptionProbeStatus) {
exceptionStatus = (ExceptionProbeStatus) status;
Expand Down Expand Up @@ -108,7 +111,7 @@ public void evaluate(
exceptionStatus.setForceSampling(true);
}
exceptionStatus.setCapture(true);
super.evaluate(context, status, methodLocation);
super.evaluate(context, status, methodLocation, singleProbe);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public InstrumentationResult.Status instrument(

@Override
public boolean isReadyToCapture() {
if (isLineProbe() && !hasCondition()) {
if (!hasCondition()) {
// we are sampling here to avoid creating CapturedContext when the sampling result is negative
return ProbeRateLimiter.tryProbe(id);
}
Expand All @@ -494,20 +494,25 @@ public boolean isReadyToCapture() {

@Override
public void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation methodLocation) {
CapturedContext context,
CapturedContext.Status status,
MethodLocation methodLocation,
boolean singleProbe) {
if (!(status instanceof LogStatus)) {
throw new IllegalStateException("Invalid status: " + status.getClass());
}
LogStatus logStatus = (LogStatus) status;
if (isLineProbe() && !hasCondition()) {
// sampling was already done in isReadToCapture so we assume that if we are executing the
// current method it means the status should be sampled
if (!logStatus.getDebugSessionStatus().isDisabled()) {
logStatus.setSampled(true);
if (!hasCondition()) {
if (singleProbe) {
// sampling was already done in isReadToCapture so we assume that if we are executing the
// current method it means the status should be sampled
if (!logStatus.getDebugSessionStatus().isDisabled()) {
logStatus.setSampled(true);
}
} else {
// sample when no condition associated
sample(logStatus, methodLocation);
}
} else if (!hasCondition()) {
// sample when no condition associated
sample(logStatus, methodLocation);
}
logStatus.setCondition(evaluateCondition(context, logStatus));
CapturedContext.CapturedThrowable throwable = context.getCapturedThrowable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ public ProbeLocation getLocation() {

@Override
public void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation methodLocation) {}
CapturedContext context,
CapturedContext.Status status,
MethodLocation methodLocation,
boolean singleProbe) {}

@Override
public void commit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public InstrumentationResult.Status instrument(

@Override
public void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation methodLocation) {
CapturedContext context,
CapturedContext.Status status,
MethodLocation methodLocation,
boolean singleProbe) {
for (Decoration decoration : decorations) {
if (decoration.when != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public TriggerProbe setProbeCondition(ProbeCondition probeCondition) {

@Override
public void evaluate(
CapturedContext context, CapturedContext.Status status, MethodLocation location) {
CapturedContext context,
CapturedContext.Status status,
MethodLocation location,
boolean singleProbe) {

Sampling sampling = getSampling();
if (sampling == null || !sampling.inCoolDown()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void roundTripCapturedValue() throws IOException, URISyntaxException {
new ProbeImplementation.NoopProbeImplementation(PROBE_ID, PROBE_LOCATION),
String.class.getTypeName(),
-1,
MethodLocation.EXIT);
MethodLocation.EXIT,
false);
snapshot.setExit(context);
String buffer = adapter.toJson(snapshot);
Snapshot deserializedSnapshot = adapter.fromJson(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ private void evalAndCommitProbe(RuntimeException exception, ExceptionProbe excep
exceptionProbe.buildLocation(null);
CapturedContext capturedContext = new CapturedContext();
capturedContext.addThrowable(exception);
capturedContext.evaluate(exceptionProbe, "", System.currentTimeMillis(), MethodLocation.EXIT);
capturedContext.evaluate(
exceptionProbe, "", System.currentTimeMillis(), MethodLocation.EXIT, false);
exceptionProbe.commit(CapturedContext.EMPTY_CAPTURING_CONTEXT, capturedContext, emptyList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ private int runTrace(TracerAPI tracer, boolean captureSnapshot, Integer line, St

CapturedContext entryContext = capturedContext(span, logProbe);
CapturedContext exitContext = capturedContext(span, logProbe);
logProbe.evaluate(entryContext, new LogStatus(logProbe), MethodLocation.ENTRY);
logProbe.evaluate(exitContext, new LogStatus(logProbe), MethodLocation.EXIT);
logProbe.evaluate(entryContext, new LogStatus(logProbe), MethodLocation.ENTRY, false);
logProbe.evaluate(exitContext, new LogStatus(logProbe), MethodLocation.EXIT, false);

int budget =
logProbe.isCaptureSnapshot()
Expand Down Expand Up @@ -193,8 +193,8 @@ private boolean fillSnapshot(DebugSessionStatus status) {

CapturedContext entryContext = capturedContext(span, logProbe);
CapturedContext exitContext = capturedContext(span, logProbe);
logProbe.evaluate(entryContext, new LogStatus(logProbe), MethodLocation.ENTRY);
logProbe.evaluate(exitContext, new LogStatus(logProbe), MethodLocation.EXIT);
logProbe.evaluate(entryContext, new LogStatus(logProbe), MethodLocation.ENTRY, false);
logProbe.evaluate(exitContext, new LogStatus(logProbe), MethodLocation.EXIT, false);

return logProbe.fillSnapshot(
entryContext, exitContext, emptyList(), new Snapshot(currentThread(), logProbe, 3));
Expand All @@ -204,7 +204,11 @@ private boolean fillSnapshot(DebugSessionStatus status) {
private static CapturedContext capturedContext(AgentSpan span, ProbeDefinition probeDefinition) {
CapturedContext context = new CapturedContext();
context.evaluate(
probeDefinition, "Log Probe test", System.currentTimeMillis(), MethodLocation.DEFAULT);
probeDefinition,
"Log Probe test",
System.currentTimeMillis(),
MethodLocation.DEFAULT,
false);
return context;
}

Expand Down Expand Up @@ -283,7 +287,7 @@ private void fillStatus(

private LogStatus prepareContext(
CapturedContext context, LogProbe logProbe, MethodLocation methodLocation) {
context.evaluate(logProbe, "", 0, methodLocation);
context.evaluate(logProbe, "", 0, methodLocation, false);
return (LogStatus) context.getStatus(PROBE_ID.getEncodedId());
}

Expand Down
Loading