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 @@ -82,6 +82,7 @@ public class MetricInstrumenter extends Instrumenter {
private final MetricProbe metricProbe;
private int durationStartVar = -1;
private LabelNode durationStartLabel;
private InstrumentationResult.Status status = InstrumentationResult.Status.INSTALLED;

public MetricInstrumenter(
MetricProbe metricProbe,
Expand Down Expand Up @@ -116,7 +117,13 @@ public InstrumentationResult.Status instrument() {
throw new IllegalArgumentException(
"Invalid evaluateAt attribute: " + definition.getEvaluateAt());
}
return InstrumentationResult.Status.INSTALLED;
return status;
}

@Override
protected void reportError(String message) {
super.reportError(message);
status = InstrumentationResult.Status.ERROR;
}

private void addFinallyHandler(LabelNode endLabel) {
Expand Down Expand Up @@ -185,7 +192,7 @@ protected InsnList getBeforeReturnInsnList(AbstractInsnNode node) {
case Opcodes.ARETURN:
storeOpCode = Opcodes.ASTORE;
loadOpCode = Opcodes.ALOAD;
returnType = OBJECT_TYPE;
returnType = Type.getReturnType(this.methodNode.desc);
break;
default:
throw new UnsupportedOperationException("Unsupported opcode: " + node.getOpcode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,25 @@ public void methodSyntheticReturnGaugeMetric() throws IOException, URISyntaxExce
assertArrayEquals(new String[] {METRIC_PROBEID_TAG}, listener.lastTags);
}

@Test
public void methodSyntheticReturnLenGaugeMetric() throws IOException, URISyntaxException {
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot32";
String METRIC_NAME = "syn_gauge";
MetricProbe metricProbe =
createMetricBuilder(METRIC_ID, METRIC_NAME, GAUGE)
.where(CLASS_NAME, "processArg", "(String)")
.valueScript(new ValueScript(DSL.len(DSL.ref("@return")), "len(@return)"))
.evaluateAt(MethodLocation.EXIT)
.build();
MetricForwarderListener listener = installMetricProbes(metricProbe);
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
int result = Reflect.on(testClass).call("main", "foobar").get();
assertEquals(42, result);
assertTrue(listener.gauges.containsKey(METRIC_NAME));
assertEquals(6, listener.gauges.get(METRIC_NAME).longValue());
assertArrayEquals(new String[] {METRIC_PROBEID_TAG}, listener.lastTags);
}

@Test
public void methodSyntheticReturnInvalidType() throws IOException, URISyntaxException {
final String CLASS_NAME = "CapturedSnapshot06";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.datadog.debugger;

public class CapturedSnapshot32 {
public static int main(String arg) throws Exception {
arg = processArg(arg);
return 42;
}

public static String processArg(String arg) {
if (arg.startsWith("-")) {
arg = arg.substring(1);
}
return arg;
}
}
Loading