Skip to content

Commit

Permalink
fix: Don't crash language servers if telemetry cannot be initialized
Browse files Browse the repository at this point in the history
Fixes #1384

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Sep 5, 2024
1 parent 66f8c8e commit 53c43d8
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
Expand All @@ -35,6 +34,8 @@
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;
import com.redhat.devtools.intellij.quarkus.search.QuarkusModuleComponent;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -110,22 +111,22 @@ public static void updateClasspathWithQuarkusDeployment(Module module, ProgressI
Library library = table.getLibraryByName(QuarkusConstants.QUARKUS_DEPLOYMENT_LIBRARY_NAME);
while (library != null) {
table.removeLibrary(library);
try {
TelemetryService.instance().action(TelemetryService.MODEL_PREFIX + "removeLibrary");
} catch (Exception e) {

}
// Send "model-removeLibrary" telemetry event
TelemetryManager.instance()
.send(TelemetryEventName.MODEL_REMOVE_LIBRARY);

library = table.getLibraryByName(QuarkusConstants.QUARKUS_DEPLOYMENT_LIBRARY_NAME);
}
progressIndicator.checkCanceled();
progressIndicator.setText("Adding in ''" + module.getName() + "'' Quarkus deployment dependencies to classpath...");
List<VirtualFile>[] files = toolDelegate.getDeploymentFiles(module, progressIndicator);
LOGGER.info("Adding library to " + module.getName() + " previousHash=" + previousHash + " newHash=" + actualHash);
try {
TelemetryService.instance().action(TelemetryService.MODEL_PREFIX + "addLibrary").send();
} catch (Exception e) {

}
// Send "model-addLibrary" telemetry event
TelemetryManager.instance()
.send(TelemetryEventName.MODEL_ADD_LIBRARY);

addLibrary(model, files);
});
component.setHash(actualHash);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private Set<MavenArtifact> resolveDeploymentArtifacts(Module module, MavenProjec
}
}
}
} catch (MavenProcessCanceledException | RuntimeException e) {
} catch (Exception e) {
LOGGER.warn(e.getLocalizedMessage(), e);
}
return deploymentArtifacts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
import com.redhat.devtools.lsp4ij.server.JavaProcessCommandBuilder;
import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider;
import com.redhat.devtools.intellij.lsp4mp4ij.settings.UserDefinedMicroProfileSettings;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -55,11 +55,8 @@ public QuarkusServer(Project project) {
commands.add("-DrunAsync=true");
super.setCommands(commands);

try {
TelemetryService.instance().action(TelemetryService.LSP_PREFIX + "start").send();
} catch (Exception e) {
LOGGER.error("Error while consuming telemetry service", e);
}
TelemetryManager.instance()
.send(TelemetryEventName.LSP_START_MICROPROFILE_SERVER);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
import com.redhat.devtools.intellij.quarkus.QuarkusConstants;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -86,15 +87,18 @@ public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
TelemetryMessageBuilder.ActionMessage telemetry = TelemetryService.instance().action(TelemetryService.UI_PREFIX + "wizard");
TelemetryMessageBuilder.ActionMessage telemetryMessage = TelemetryManager.instance()
.action(TelemetryEventName.UI_WIZARD);
try {
processDownload();
Module module = super.createModule(moduleModel);
wizardContext.getUserData(QuarkusConstants.WIZARD_TOOL_KEY).processImport(module);
telemetry.send();
// Send "ui-wizard" telemetry event with no error
TelemetryManager.instance().asyncSend(telemetryMessage);
return module;
} catch (IOException | InvalidDataException | ModuleWithNameAlreadyExists | JDOMException | ConfigurationException e) {
telemetry.error(e).send();
// Send "ui-wizard" telemetry event with error
TelemetryManager.instance().asyncSend(telemetryMessage != null ? telemetryMessage.error(e) : null);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -121,24 +122,36 @@ private void allocateLocalPort() {
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
TelemetryMessageBuilder.ActionMessage telemetry = TelemetryService.instance().action(TelemetryService.RUN_PREFIX + "run");
telemetry.property("kind", executor.getId());
BuildToolDelegate toolDelegate = BuildToolDelegate.getDelegate(getModule());
Module module = getModule();

TelemetryMessageBuilder.ActionMessage telemetryMessage = TelemetryManager.instance()
.action(TelemetryEventName.RUN_RUN);

if (telemetryMessage != null) {
telemetryMessage.property("kind", executor.getId());
}
BuildToolDelegate toolDelegate = BuildToolDelegate.getDelegate(module);
allocateLocalPort();
RunProfileState state = null;
if (toolDelegate != null) {
telemetry.property("tool", toolDelegate.getDisplay());
if (telemetryMessage != null) {
telemetryMessage.property("tool", toolDelegate.getDisplay());
}
// Create a Gradle or Maven run configuration in memory
RunnerAndConfigurationSettings settings = toolDelegate.getConfigurationDelegate(getModule(), this);
RunnerAndConfigurationSettings settings = toolDelegate.getConfigurationDelegate(module, this);
if (settings != null) {
long groupId = ExecutionEnvironment.getNextUnusedExecutionId();
state = doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId, null);
}
} else {
telemetry.property("tool", "not found");
if (telemetryMessage != null) {
telemetryMessage.property("tool", "not found");
}
}
telemetry.send();
if (executor.getId() == DefaultDebugExecutor.EXECUTOR_ID) {
// Send "run-run" telemetry event
TelemetryManager.instance().asyncSend(telemetryMessage);

if (executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), QUARKUS_CONFIGURATION, false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProject;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProjectManager;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -81,17 +83,19 @@ public boolean updatePresentation(@NotNull PresentationData presentation, @NotNu
public void run() {
// Open Quarkus application in a Web Browser
super.run();
// Send event with telemetry
TelemetryService.instance().action(TelemetryService.UI_PREFIX + "openApplication").send();
// Send "ui-openApplication" telemetry event
TelemetryManager.instance()
.send(TelemetryEventName.UI_OPEN_APPLICATION);
}
});
links.put(devUILabel, new SimpleColoredComponent.BrowserLauncherTag(devUIUrl) {
@Override
public void run() {
// Open DevUI in a Web Browser
super.run();
// Send event with telemetry
TelemetryService.instance().action(TelemetryService.UI_PREFIX + "openDevUI").send();
// Send "ui-openDevUI" telemetry event
TelemetryManager.instance()
.send(TelemetryEventName.UI_OPEN_DEV_UI);
}
});
node.putUserData(RunDashboardCustomizer.NODE_LINKS, links);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.quarkus.telemetry;

/**
* Quarkus telemetry event name.
*/
public enum TelemetryEventName {

// LSP event names
LSP_START_MICROPROFILE_SERVER(Constants.LSP_PREFIX + "start"),
LSP_START_QUTE_SERVER(Constants.LSP_PREFIX + "startQute"),

// Model event names
MODEL_REMOVE_LIBRARY(Constants.MODEL_PREFIX + "removeLibrary"),
MODEL_ADD_LIBRARY(Constants.MODEL_PREFIX + "addLibrary"),

// UI event names
UI_WIZARD(Constants.UI_PREFIX + "wizard"),
UI_OPEN_APPLICATION(Constants.UI_PREFIX + "openApplication"),
UI_OPEN_DEV_UI(Constants.UI_PREFIX + "openDevUI"),

// Run event names
RUN_RUN(Constants.RUN_PREFIX + "run");

private static class Constants {
public static final String LSP_PREFIX = "lsp-";
public static final String UI_PREFIX = "ui-";
public static final String MODEL_PREFIX = "model-";
public static final String RUN_PREFIX = "run-";
}

private final String eventName;

TelemetryEventName(String eventName) {
this.eventName = eventName;
}


public String getEventName() {
return eventName;
}

}
Loading

0 comments on commit 53c43d8

Please sign in to comment.