-
Notifications
You must be signed in to change notification settings - Fork 52
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 61379ce
Showing
14 changed files
with
357 additions
and
76 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 { | ||
} |
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
/******************************************************************************* | ||
* 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.NotNull; | ||
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; | ||
} | ||
} | ||
|
||
@Override | ||
public void asyncSend(@Nullable TelemetryMessageBuilder.ActionMessage message) { | ||
if (message == null) { | ||
return; | ||
} | ||
ApplicationManager.getApplication().executeOnPooledThread(() -> { | ||
try{ | ||
message.send(); | ||
} catch (Exception e) { | ||
LOGGER.warn("Failed to send Telemetry data : {}", e.getMessage()); | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.