-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't crash language servers if telemetry cannot be initialized
Fixes #1384 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
66f8c8e
commit 192c6c4
Showing
14 changed files
with
319 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
src/main/java/com/redhat/devtools/intellij/quarkus/TelemetryService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/redhat/devtools/intellij/quarkus/telemetry/NoOpTelemetryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
/** | ||
* No-Op implementation of telemetry service | ||
*/ | ||
public class NoOpTelemetryService implements TelemetryService { | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/com/redhat/devtools/intellij/quarkus/telemetry/RedHatTelemetryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
import com.intellij.ide.plugins.PluginManager; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder; | ||
import com.redhat.devtools.intellij.telemetry.core.util.Lazy; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Red Hat Telemetry Service, used when <a href="https://github.com/redhat-developer/intellij-redhat-telemetry">intellij-redhat-telemetry</a> is available | ||
*/ | ||
public class RedHatTelemetryService implements TelemetryService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(RedHatTelemetryService.class); | ||
|
||
private final Lazy<TelemetryMessageBuilder> builder = new Lazy<>(() -> new TelemetryMessageBuilder(PluginManager.getPluginByClass(this.getClass()))); | ||
|
||
private boolean hasError; | ||
@Override | ||
public void send(TelemetryEventName eventName, Map<String, String> properties) { | ||
TelemetryMessageBuilder.ActionMessage action = action(eventName, properties); | ||
if (action == null) { | ||
return; | ||
} | ||
asyncSend(action); | ||
} | ||
|
||
@Override | ||
public @Nullable TelemetryMessageBuilder.ActionMessage action(TelemetryEventName eventName, Map<String, String> properties) { | ||
TelemetryMessageBuilder builder = getMessageBuilder(); | ||
if (builder == null) { | ||
return null; | ||
} | ||
TelemetryMessageBuilder.ActionMessage action = builder.action(eventName.getEventName()); | ||
if (properties != null) { | ||
properties.forEach((k, v) -> { | ||
action.property(k, v); | ||
}); | ||
} | ||
return action; | ||
} | ||
|
||
@Nullable | ||
private TelemetryMessageBuilder getMessageBuilder() { | ||
if (hasError) { | ||
return null; | ||
} | ||
try { | ||
return builder.get(); | ||
} | ||
catch(Exception e) { | ||
hasError = true; | ||
return null; | ||
} | ||
} | ||
|
||
public static void asyncSend(TelemetryMessageBuilder.ActionMessage message) { | ||
ApplicationManager.getApplication().executeOnPooledThread(() -> { | ||
try{ | ||
message.send(); | ||
} catch (Exception e) { | ||
LOGGER.error("Failed to send Telemetry data : {}", e.getMessage()); | ||
} | ||
}); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/redhat/devtools/intellij/quarkus/telemetry/TelemetryEventName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.redhat.devtools.intellij.quarkus.telemetry; | ||
|
||
import static com.redhat.devtools.intellij.quarkus.telemetry.TelemetryService.LSP_PREFIX; | ||
import static com.redhat.devtools.intellij.quarkus.telemetry.TelemetryService.MODEL_PREFIX; | ||
import static com.redhat.devtools.intellij.quarkus.telemetry.TelemetryService.UI_PREFIX; | ||
import static com.redhat.devtools.intellij.quarkus.telemetry.TelemetryService.RUN_PREFIX; | ||
|
||
public enum TelemetryEventName { | ||
|
||
// LSP event names | ||
LSP_START_MICROPROFILE_SERVER(LSP_PREFIX + "start"), | ||
LSP_START_QUTE_SERVER(LSP_PREFIX + "startQute"), | ||
|
||
// Model event names | ||
MODEL_REMOVE_LIBRARY(MODEL_PREFIX + "removeLibrary"), | ||
MODEL_ADD_LIBRARY(MODEL_PREFIX + "addLibrary"), | ||
|
||
// UI event names | ||
UI_WIZARD(UI_PREFIX + "wizard"), | ||
UI_OPEN_APPLICATION(UI_PREFIX + "openApplication"), | ||
UI_OPEN_DEV_UI(UI_PREFIX + "openDevUI"), | ||
|
||
// Run event names | ||
RUN_RUN(RUN_PREFIX + "run"); | ||
|
||
private final String eventName; | ||
|
||
TelemetryEventName(String eventName) { | ||
this.eventName = eventName; | ||
} | ||
|
||
|
||
public String getEventName() { | ||
return eventName; | ||
} | ||
|
||
} |
Oops, something went wrong.