Skip to content

Commit 6624508

Browse files
committed
Report exceptions to Sentry instead of GitHub
1 parent 31cc015 commit 6624508

File tree

6 files changed

+96
-2
lines changed

6 files changed

+96
-2
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.21'
2626
implementation 'fr.opensagres.js:minimatch.java:1.1.0'
2727
implementation 'io.github.cdimascio:dotenv-kotlin:6.2.2'
28+
implementation 'io.sentry:sentry:5.4.3'
2829

2930
implementation 'com.graphql-java:java-dataloader:2.2.3'
3031
implementation 'org.reactivestreams:reactive-streams:1.0.2'

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
<highlightErrorFilter
201201
implementation="com.intellij.lang.jsgraphql.ide.highlighting.GraphQLVariablesHighlightErrorFilter"/>
202202

203-
<errorHandler implementation="com.intellij.lang.jsgraphql.GraphQLGithubErrorReporter"/>
203+
<errorHandler implementation="com.intellij.lang.jsgraphql.ide.diagnostic.GraphQLSentryErrorReporter"/>
204204

205205
<!-- Keys -->
206206
<registryKey key="graphql.search.scope.libraries" defaultValue="true"

resources/messages/GraphQLMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ graphql.inspection.group.schema=Schema
7171

7272
# Error reporter
7373
graphql.report.to.issue.tracker=Report to GraphQL Issue Tracker
74+
graphql.report.to.sentry=Report to GraphQL Plugin
7475

7576
# Settings
7677
graphql.settings.frameworks=Frameworks

src/main/com/intellij/lang/jsgraphql/GraphQLGithubErrorReporter.java renamed to src/main/com/intellij/lang/jsgraphql/ide/diagnostic/GraphQLGithubErrorReporter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package com.intellij.lang.jsgraphql;
1+
package com.intellij.lang.jsgraphql.ide.diagnostic;
22

33
import com.intellij.ide.BrowserUtil;
44
import com.intellij.ide.plugins.IdeaPluginDescriptor;
55
import com.intellij.ide.plugins.PluginManagerCore;
6+
import com.intellij.lang.jsgraphql.GraphQLBundle;
67
import com.intellij.openapi.application.ApplicationInfo;
78
import com.intellij.openapi.diagnostic.ErrorReportSubmitter;
89
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.intellij.lang.jsgraphql.ide.diagnostic;
2+
3+
import io.sentry.Sentry;
4+
import io.sentry.SentryEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public class GraphQLSentryClient {
8+
private static class Lazy {
9+
private static final GraphQLSentryClient ourClient = new GraphQLSentryClient();
10+
}
11+
12+
public static GraphQLSentryClient getInstance() {
13+
return Lazy.ourClient;
14+
}
15+
16+
public GraphQLSentryClient() {
17+
Sentry.init(options -> options.setDsn("https://[email protected]/6097822"));
18+
}
19+
20+
public void captureEvent(@NotNull SentryEvent event) {
21+
Sentry.captureEvent(event);
22+
}
23+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.intellij.lang.jsgraphql.ide.diagnostic;
2+
3+
import com.intellij.diagnostic.IdeaReportingEvent;
4+
import com.intellij.ide.plugins.IdeaPluginDescriptor;
5+
import com.intellij.lang.jsgraphql.GraphQLBundle;
6+
import com.intellij.openapi.application.ApplicationInfo;
7+
import com.intellij.openapi.diagnostic.ErrorReportSubmitter;
8+
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
9+
import com.intellij.openapi.diagnostic.SubmittedReportInfo;
10+
import com.intellij.openapi.util.NlsActions;
11+
import com.intellij.openapi.util.SystemInfo;
12+
import com.intellij.util.Consumer;
13+
import io.sentry.SentryEvent;
14+
import io.sentry.SentryLevel;
15+
import io.sentry.protocol.Message;
16+
import org.jetbrains.annotations.NotNull;
17+
import org.jetbrains.annotations.Nullable;
18+
19+
import java.awt.*;
20+
21+
public class GraphQLSentryErrorReporter extends ErrorReportSubmitter {
22+
23+
@Override
24+
public @NlsActions.ActionText @NotNull String getReportActionText() {
25+
return GraphQLBundle.message("graphql.report.to.sentry");
26+
}
27+
28+
@Override
29+
public boolean submit(IdeaLoggingEvent @NotNull [] events,
30+
@Nullable String additionalInfo,
31+
@NotNull Component parentComponent,
32+
@NotNull Consumer<? super SubmittedReportInfo> consumer) {
33+
GraphQLSentryClient client = GraphQLSentryClient.getInstance();
34+
35+
for (IdeaLoggingEvent event : events) {
36+
if (!(event instanceof IdeaReportingEvent)) {
37+
continue;
38+
}
39+
IdeaReportingEvent reportingEvent = (IdeaReportingEvent) event;
40+
SentryEvent sentryEvent = new SentryEvent(reportingEvent.getData().getThrowable());
41+
42+
Message message = new Message();
43+
String exceptionMessage = event.getThrowableText().lines().findFirst().orElse(event.getMessage());
44+
message.setMessage(exceptionMessage);
45+
sentryEvent.setMessage(message);
46+
sentryEvent.setLevel(SentryLevel.ERROR);
47+
48+
IdeaPluginDescriptor plugin = reportingEvent.getPlugin();
49+
if (plugin != null) {
50+
sentryEvent.setRelease(plugin.getVersion());
51+
sentryEvent.setEnvironment(plugin.getName());
52+
}
53+
54+
String ideaVersion = ApplicationInfo.getInstance().getBuild().asString();
55+
sentryEvent.setTag("IDE", ideaVersion);
56+
sentryEvent.setTag("OS", SystemInfo.getOsNameAndVersion());
57+
58+
if (additionalInfo != null) {
59+
sentryEvent.setExtra("Additional info", additionalInfo);
60+
}
61+
62+
client.captureEvent(sentryEvent);
63+
}
64+
65+
consumer.consume(new SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.NEW_ISSUE));
66+
return true;
67+
}
68+
}

0 commit comments

Comments
 (0)