Skip to content

Commit

Permalink
Added defensive checks for null values in telemetry (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
nborges-aws authored Nov 26, 2024
1 parent 7f7f19a commit 55bba2a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,56 @@ public static void setManifestStartPoint(final Instant start) {
}

public static void emitSetupGetManifest(final Result result, final RecordLspSetupArgs args) {
args.setDuration(Duration.between(manifestStartPoint, Instant.now()).toMillis());
if (result == null || args == null) {
return;
}
if (manifestStartPoint != null) {
args.setDuration(Duration.between(manifestStartPoint, Instant.now()).toMillis());
}
emitSetupMetric(result, args, LanguageServerSetupStage.GET_MANIFEST);
if (result == Result.FAILED && args.getManifestLocation() == ManifestLocation.UNKNOWN) {
emitSetupAll(Result.FAILED, args);
}
}

public static void emitSetupGetServer(final Result result, final RecordLspSetupArgs args) {
if (result == null || args == null) {
return;
}
emitSetupMetric(result, args, LanguageServerSetupStage.GET_SERVER);
if (result == Result.FAILED && args.getLocation() == LanguageServerLocation.UNKNOWN) {
emitSetupAll(Result.FAILED, args);
}
}

public static void emitSetupValidate(final Result result, final RecordLspSetupArgs args) {
if (result == null || args == null) {
return;
}
emitSetupMetric(result, args, LanguageServerSetupStage.VALIDATE);
if (result == Result.FAILED && args.getLocation() != LanguageServerLocation.OVERRIDE) {
emitSetupAll(Result.FAILED, args);
}
}
public static void emitSetupInitialize(final Result result, final RecordLspSetupArgs args) {
args.setDuration(Duration.between(initStartPoint, Instant.now()).toMillis());
if (result == null || args == null) {
return;
}
if (initStartPoint != null) {
args.setDuration(Duration.between(initStartPoint, Instant.now()).toMillis());
}
emitSetupMetric(result, args, LanguageServerSetupStage.INITIALIZE);

//final step completing makes call to complete full process
emitSetupAll(result, args);
}
public static void emitSetupAll(final Result result, final RecordLspSetupArgs args) {
args.setDuration(Duration.between(allStartPoint, Instant.now()).toMillis());
if (result == null || args == null) {
return;
}
if (allStartPoint != null) {
args.setDuration(Duration.between(allStartPoint, Instant.now()).toMillis());
}
emitSetupMetric(result, args, LanguageServerSetupStage.ALL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import software.aws.toolkits.telemetry.TelemetryDefinitions.Result;
import software.aws.toolkits.telemetry.ToolkitTelemetry;
import java.time.Instant;
import java.util.Set;

public final class ToolkitTelemetryProvider {
private static final Set<String> NON_PASSIVE = Set.of("ellipsesMenu", "statusBar", "shortcut");

private ToolkitTelemetryProvider() {
//prevent instantiation
Expand All @@ -30,9 +32,9 @@ public static void emitExecuteCommandMetric(final ExecuteParams params) {

public static void emitOpenModuleEventMetric(final String module, final String source, final String failureReason) {
Result result = Result.SUCCEEDED;
boolean isPassive = (!source.equals("ellipsesMenu") && !source.equals("statusBar") && !source.equals("shortcut"));
boolean isPassive = (source != null && !NON_PASSIVE.contains(source));

if (!failureReason.equals("none")) {
if (failureReason != null && !failureReason.equals("none")) {
result = Result.FAILED;
ToolkitTelemetry.OpenModuleEvent().reason(failureReason);
}
Expand All @@ -47,7 +49,7 @@ public static void emitOpenModuleEventMetric(final String module, final String s
Activator.getTelemetryService().emitMetric(metadata);
}
public static void emitCloseModuleEventMetric(final String module, final String failureReason) {
Result result = (failureReason.equals("none")) ? Result.SUCCEEDED : Result.FAILED;
Result result = (failureReason == null || failureReason.equals("none")) ? Result.SUCCEEDED : Result.FAILED;
MetricDatum metadata = ToolkitTelemetry.CloseModuleEvent()
.module(mapModuleId(module))
.result(result)
Expand Down

0 comments on commit 55bba2a

Please sign in to comment.