Skip to content

Commit ff92de4

Browse files
authored
Merge pull request #2279 from digma-ai/ui_error_support
UI error support
2 parents 6a140f9 + 7657239 commit ff92de4

File tree

10 files changed

+343
-51
lines changed

10 files changed

+343
-51
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/common/FrequencyDetector.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class FrequencyDetector(cacheExpirationTime: java.time.Duration) {
1818
val occurrences = counter.incrementAndGet()
1919
return occurrences > 1
2020
}
21-
22-
23-
24-
21+
fun isTooFrequentStackTrace(message: String, stacktrace: String): Boolean {
22+
val hash = stacktrace.hashCode()
23+
val counter = myCache.getOrCreate(message, hash.toString())
24+
val occurrences = counter.incrementAndGet()
25+
return occurrences > 1
26+
}
2527
fun isTooFrequentError(message: String, action: String): Boolean {
2628
val counter = myCache.getOrCreate(message, action)
2729
val occurrences = counter.incrementAndGet()

ide-common/src/main/kotlin/org/digma/intellij/plugin/errorreporting/ErrorReporter.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ open class ErrorReporter {
116116
)
117117
}
118118

119+
private fun isTooFrequent(message: String, stackTrace: String?): Boolean {
120+
if (!stackTrace.isNullOrEmpty()) {
121+
return frequencyDetector.isTooFrequentStackTrace(message, stackTrace)
122+
}
123+
return frequencyDetector.isTooFrequentError(message, "")
124+
}
125+
126+
open fun reportError(message: String, stackTrace: String?, details: Map<String, Any>, project: Project?, useFrequencyDetector: Boolean = true) {
127+
if (message.isNullOrEmpty() && stackTrace.isNullOrEmpty()) {
128+
reportError(
129+
project, "At least one of the following properties must be set: [message] or [stackTrace].", "reportError",
130+
mapOf(
131+
SEVERITY_PROP_NAME to SEVERITY_HIGH_TRY_FIX
132+
)
133+
)
134+
return
135+
}
136+
if (useFrequencyDetector && isTooFrequent(message, stackTrace)) {
137+
return
138+
}
139+
val projectToUse = project ?: findActiveProject()
140+
141+
projectToUse?.let {
142+
if (it.isDisposed) return
143+
ActivityMonitor.getInstance(it).registerError(null, message, details)
144+
}
145+
}
146+
119147
//this method is used to report an error that is not an exception. it should contain some details to say what the error is
120148
open fun reportError(project: Project?, message: String, action: String, details: Map<String, String>) {
121149

@@ -178,7 +206,6 @@ open class ErrorReporter {
178206
}
179207

180208

181-
182209
open fun reportAnalyticsServiceError(
183210
project: Project,
184211
message: String,

ide-common/src/main/kotlin/org/digma/intellij/plugin/posthog/ActivityMonitor.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
128128
}
129129

130130

131-
132-
133131
override fun dispose() {
134132
//nothing to do, used as parent disposable
135133
}
@@ -315,7 +313,7 @@ class ActivityMonitor(private val project: Project) : Disposable {
315313
}
316314

317315

318-
fun registerError(exception: Throwable?, message: String, extraDetails: Map<String, String> = mapOf()) {
316+
fun registerError(exception: Throwable?, message: String, extraDetails: Map<String, Any> = mapOf()) {
319317

320318
try {
321319
val osType = System.getProperty("os.name")
@@ -327,7 +325,7 @@ class ActivityMonitor(private val project: Project) : Disposable {
327325

328326
//Don't call directly, use ErrorReporter.reportError
329327

330-
val details = mutableMapOf(
328+
val details = mutableMapOf<String, Any>(
331329
"error.source" to "plugin",
332330
"action" to "unknown",
333331
"message" to message,
@@ -644,8 +642,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
644642
}
645643

646644

647-
648-
649645
//todo: remove at some point
650646
fun registerFirstTimePluginLoaded() {
651647
postHog?.capture(userId, "plugin first-loaded")
@@ -822,7 +818,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
822818
}
823819

824820

825-
826821
private fun registerSessionDetails() {
827822

828823
SessionMetadataProperties.getInstance().put(CURRENT_INSTALL_STATUS_KEY, InstallStatus.Active)
@@ -925,7 +920,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
925920
}
926921

927922

928-
929923
fun registerJiraFieldCopied(eventName: String, details: Map<String, Any>) {
930924

931925
PersistenceService.getInstance().setJiraFieldCopiedTimestamp()
@@ -991,7 +985,7 @@ class ActivityMonitor(private val project: Project) : Disposable {
991985

992986
fun reportApiPerformanceIssue(details: MutableMap<String, Any>) {
993987
capture(
994-
"api-performance-issue",details
988+
"api-performance-issue", details
995989
)
996990
}
997991

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/BaseMessageRouterHandler.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,20 @@ abstract class BaseMessageRouterHandler(protected val project: Project) : Common
146146
val trackingRequest = jsonToObject(request, SendTrackingEventRequest::class.java)
147147
trackingRequest.let {
148148
it.payload?.let { pl ->
149-
if (pl.data == null) {
150-
ActivityMonitor.getInstance(project).registerCustomEvent(pl.eventName)
149+
if (pl.eventName == "error") {
150+
pl.data?.let {
151+
val stackTrace = pl.data["exception.stack-trace"] as String?
152+
val message = pl.data["message"] as String
153+
ErrorReporter.getInstance().reportError(message, stackTrace, pl.data, project, false)
154+
}
151155
} else {
152-
ActivityMonitor.getInstance(project).registerCustomEvent(pl.eventName, pl.data)
156+
if (pl.data == null) {
157+
ActivityMonitor.getInstance(project).registerCustomEvent(pl.eventName)
158+
} else {
159+
ActivityMonitor.getInstance(project).registerCustomEvent(pl.eventName, pl.data)
160+
}
153161
}
162+
154163
}
155164
}
156165
}

src/main/resources/webview/dashboard/index.js

Lines changed: 67 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/webview/documentation/index.js

Lines changed: 66 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/webview/installationwizard/index.js

Lines changed: 65 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/webview/main/index.js

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/webview/recentactivity/index.js

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/webview/troubleshooting/index.js

Lines changed: 66 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)