Skip to content

Commit fb47f47

Browse files
authored
Merge pull request #2758 from digma-ai/show-error-api-service
Support new action GoToError in the REST Plugin API Closes #2756
2 parents 73cbd9f + 92a0a48 commit fb47f47

File tree

10 files changed

+98
-2
lines changed

10 files changed

+98
-2
lines changed

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,5 @@ public interface AnalyticsProvider extends Closeable {
174174
DiscoveredDataResponse getDiscoveredData();
175175

176176
SpanInfoByUid resolveSpanByUid(String uid);
177+
EnvironmentInfoByErrorId resolveEnvironmentByErrorId(String errorId);
177178
}

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/RestAnalyticsProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ public SpanInfoByUid resolveSpanByUid(String uid) {
495495
return execute(() -> client.analyticsProvider.resolveSpanByUid(uid));
496496
}
497497

498+
@Override
499+
public EnvironmentInfoByErrorId resolveEnvironmentByErrorId(String errorId) {
500+
return execute(() -> client.analyticsProvider.resolveEnvironmentByErrorId(errorId));
501+
}
502+
498503
@Override
499504
public HttpResponse proxyCall(HttpRequest request) {
500505

@@ -1314,5 +1319,12 @@ Call<Void> setInsightCustomStartTime(
13141319
})
13151320
@GET("spans/spanCodeObjectId/{uid}")
13161321
Call<SpanInfoByUid> resolveSpanByUid(@Path("uid") String uid);
1322+
1323+
@Headers({
1324+
"Content-Type:application/json"
1325+
})
1326+
@GET("CodeAnalytics/codeObjects/error_environment")
1327+
Call<EnvironmentInfoByErrorId> resolveEnvironmentByErrorId(@Query("errorId") String errorId);
1328+
13171329
}
13181330
}

ide-common/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public HttpResponse proxyCall(HttpRequest request) throws AnalyticsServiceExcept
564564

565565

566566
@Nullable
567-
public SpanInfoByUid resolveSpanByUid(String uid) throws AnalyticsServiceException {
567+
public SpanInfoByUid resolveSpanByUid(@NotNull String uid) throws AnalyticsServiceException {
568568

569569
if (backendVersionOlderThen("0.3.155")) {
570570
return null;
@@ -574,6 +574,15 @@ public SpanInfoByUid resolveSpanByUid(String uid) throws AnalyticsServiceExcepti
574574

575575
}
576576

577+
@Nullable
578+
public EnvironmentInfoByErrorId resolveEnvironmentByErrorId(@NotNull String errorId) throws AnalyticsServiceException {
579+
if (backendVersionOlderThen("0.3.318")) {
580+
return null;
581+
}
582+
583+
return executeCatching(() -> analyticsProviderProxy.resolveEnvironmentByErrorId(errorId));
584+
}
585+
577586

578587
private boolean backendVersionOlderThen(String version) {
579588
String backendVersion = BackendInfoHolder.getInstance(project).getAbout().getApplicationVersion();
@@ -659,6 +668,8 @@ private AnalyticsProvider newAnalyticsProviderProxy(AnalyticsProvider obj) {
659668
new AnalyticsInvocationHandler(obj));
660669
}
661670

671+
672+
662673
/**
663674
* A proxy for cross-cutting concerns across all api methods.
664675
* In a proxy it's easier to log events, we have the method name, parameters etc.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ApiProjectService(val project: Project) : DisposableAdaptor {
3737
ACTION_GO_TO_HOME_PARAM_VALUE -> GoToHomeCommand()
3838
ACTION_GO_TO_SPAN_PARAM_VALUE -> GoToSpanCommand()
3939
ACTION_OPEN_REPORT_PARAM_VALUE -> OpenReportCommand()
40+
ACTION_GO_TO_ERROR_PARAM_VALUE -> GoToErrorCommand()
4041
else -> {
4142
throw RuntimeException("unknown action $action")
4243
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.digma.intellij.plugin.api
2+
3+
import com.intellij.openapi.project.Project
4+
import io.netty.handler.codec.http.QueryStringDecoder
5+
import org.digma.intellij.plugin.analytics.AnalyticsService
6+
import org.digma.intellij.plugin.common.objectToJsonNode
7+
import org.digma.intellij.plugin.log.Log
8+
import org.digma.intellij.plugin.scope.ScopeContext
9+
import org.digma.intellij.plugin.scope.ScopeManager
10+
import org.jetbrains.ide.RestService.Companion.getStringParameter
11+
import java.util.Objects
12+
13+
class GoToErrorCommand : AbstractApiCommand() {
14+
15+
override fun execute(project: Project, urlDecoder: QueryStringDecoder) {
16+
val errorId = getStringParameter(ERROR_ID_PARAM_NAME, urlDecoder)
17+
Objects.requireNonNull(errorId, "errorId parameter must not be null")
18+
19+
Log.log(
20+
logger::trace,
21+
"GoToError called with errorId={}, projectName={}, thread={}",
22+
errorId,
23+
project.name,
24+
Thread.currentThread().name
25+
)
26+
27+
//checked non-null above
28+
errorId!!
29+
30+
val environmentByErrorIdResponse = AnalyticsService.getInstance(project).resolveEnvironmentByErrorId(errorId)
31+
?: throw RuntimeException("could not find environment by error id $errorId")
32+
33+
val environmentId = environmentByErrorIdResponse.environmentId
34+
if (environmentId.isBlank()) {
35+
throw RuntimeException("could not find environment id for error id $errorId")
36+
}
37+
val contextPayload = objectToJsonNode(GoToErrorContextPayload(errorId = errorId))
38+
val scopeContext = ScopeContext("IDE/REST_API_CALL", contextPayload)
39+
40+
Log.log(
41+
logger::trace,
42+
"calling ScopeManager.changeToHome with ,scopeContext='{}',environmentId='{}', thread='{}'",
43+
scopeContext,
44+
environmentId,
45+
Thread.currentThread().name
46+
)
47+
48+
ScopeManager.getInstance(project).changeToHome(true, scopeContext, environmentId)
49+
50+
}
51+
52+
53+
data class GoToErrorContextPayload(val targetTab: String = "errors", val errorId: String)
54+
55+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class GoToSpanCommand : AbstractApiCommand() {
2828
Thread.currentThread().name
2929
)
3030

31+
//checked non-null above
32+
spanUid!!
3133

3234
val spanInfoByUid = AnalyticsService.getInstance(project).resolveSpanByUid(spanUid)
3335
?: throw RuntimeException("could not find span by uid $spanUid")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.digma.intellij.plugin.log.Log
99
import java.util.Objects
1010

1111
//http://localhost:63344/api/digma/show?action=GoToSpan&spanUid=995822fa-9d0d-11ef-9d3e-0adc1d604f09&targetTab=assets&projectName=spring-petclinic
12+
//http://localhost:63344/api/digma/show?action=GoToError&errorId=6dc7a826-fb37-11ef-8a3f-7215f134c660&projectName=spring-petclinic
1213
//http://localhost:63344/api/digma/show?action=GoToHome&environment_id=LOCAL%23ID%2325A68508-B8A3-4DF2-ACA3-ECDAAB203793&targetTab=assets&projectName=spring-petclinic
1314
//http://localhost:63344/api/digma/show?action=OpenReport&projectName=spring-petclinic
1415
class ShowAssetsHttpService : AbstractHttpService() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import org.digma.intellij.plugin.common.findActiveProject
1010
const val ACTION_PARAM_NAME = "action"
1111
const val TARGET_TAB_PARAM_NAME = "targetTab"
1212
const val SPAN_UID_PARAM_NAME = "spanUid"
13+
const val ERROR_ID_PARAM_NAME = "errorId"
1314
const val ENVIRONMENT_ID_PARAM_NAME = "environment_id"
1415
const val PROJECT_NAME_PARAM_NAME = "projectName"
1516

1617
const val ACTION_GO_TO_HOME_PARAM_VALUE = "GoToHome"
1718
const val ACTION_GO_TO_SPAN_PARAM_VALUE = "GoToSpan"
1819
const val ACTION_OPEN_REPORT_PARAM_VALUE = "OpenReport"
20+
const val ACTION_GO_TO_ERROR_PARAM_VALUE = "GoToError"
1921

2022

2123
fun findProjectOrNull(projectName: String): Project? {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.digma.intellij.plugin.model.rest.common
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
5+
import java.beans.ConstructorProperties
6+
7+
@JsonIgnoreProperties(ignoreUnknown = true)
8+
data class EnvironmentInfoByErrorId
9+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10+
@ConstructorProperties("environmentId")
11+
constructor(val environmentId: String)

ui-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14.2.4
1+
14.2.5

0 commit comments

Comments
 (0)