From 0ae7fa11cfad0ba20772f913e44d557e5ef6d10a Mon Sep 17 00:00:00 2001 From: Nicolas Borges Date: Tue, 26 Nov 2024 17:26:54 -0500 Subject: [PATCH] added safety checks on LSP telemetry emissions --- .../LanguageServerTelemetryProvider.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/telemetry/LanguageServerTelemetryProvider.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/telemetry/LanguageServerTelemetryProvider.java index 728a32bf..b95006a6 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/telemetry/LanguageServerTelemetryProvider.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/telemetry/LanguageServerTelemetryProvider.java @@ -34,7 +34,12 @@ 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); @@ -42,6 +47,9 @@ public static void emitSetupGetManifest(final Result result, final RecordLspSetu } 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); @@ -49,20 +57,33 @@ public static void emitSetupGetServer(final Result result, final RecordLspSetupA } 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); }