|
| 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