From 90e9f755cbed4709bce6156587bcba65feac09fd Mon Sep 17 00:00:00 2001 From: amircodota <25413470+amircodota@users.noreply.github.com> Date: Mon, 27 Nov 2023 22:37:31 +0200 Subject: [PATCH] DEV2-4344 add workspace tracing (#693) --- .../tabnineCommon/capabilities/Capability.java | 2 ++ .../lifecycle/WorkspaceListenerService.kt | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Common/src/main/java/com/tabnineCommon/capabilities/Capability.java b/Common/src/main/java/com/tabnineCommon/capabilities/Capability.java index 2d2a261c..b3c01227 100644 --- a/Common/src/main/java/com/tabnineCommon/capabilities/Capability.java +++ b/Common/src/main/java/com/tabnineCommon/capabilities/Capability.java @@ -23,4 +23,6 @@ public enum Capability { FORCE_REGISTRATION, @SerializedName("plugin.feature.tabnine_chat") TABNINE_CHAT, + @SerializedName("plugin.feature.workspace_trace") + WORKSPACE_TRACE, } diff --git a/Common/src/main/java/com/tabnineCommon/lifecycle/WorkspaceListenerService.kt b/Common/src/main/java/com/tabnineCommon/lifecycle/WorkspaceListenerService.kt index 18422296..3e96c209 100644 --- a/Common/src/main/java/com/tabnineCommon/lifecycle/WorkspaceListenerService.kt +++ b/Common/src/main/java/com/tabnineCommon/lifecycle/WorkspaceListenerService.kt @@ -6,7 +6,10 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.roots.ProjectRootManager import com.intellij.util.concurrency.AppExecutorUtil +import com.tabnineCommon.binary.requests.analytics.EventRequest import com.tabnineCommon.binary.requests.fileLifecycle.Workspace +import com.tabnineCommon.capabilities.CapabilitiesService +import com.tabnineCommon.capabilities.Capability import com.tabnineCommon.general.DependencyContainer import java.io.File import java.net.URL @@ -42,11 +45,21 @@ class WorkspaceListenerService { if (rootPaths.isNullOrEmpty()) return Logger.getInstance(javaClass).info("All root paths collected: $rootPaths") + sendEvent("workspace_sending_request", mapOf("root_paths_len" to rootPaths.size.toString())) binaryRequestFacade.executeRequest(Workspace(rootPaths)) } + private fun sendEvent(name: String, properties: Map?) { + if (CapabilitiesService.getInstance().isCapabilityEnabled(Capability.WORKSPACE_TRACE)) { + binaryRequestFacade.executeRequest(EventRequest(name, properties)) + } + } + fun getWorkspaceRootPaths(project: Project): List? { + sendEvent("workspace_starting", mapOf()) + if (project.isDisposed) { + sendEvent("workspace_project_disposed", mapOf()) Logger.getInstance(javaClass).warn("Project ${project.name} is disposed, skipping root paths resolution") return null } @@ -55,10 +68,13 @@ class WorkspaceListenerService { for (contentRootUrl in ProjectRootManager.getInstance(project).contentRootUrls) { val url = URL(contentRootUrl) if (url.protocol != "file") { + sendEvent("workspace_protocol_not_file", mapOf("path" to url.toString())) + Logger.getInstance(javaClass).debug("$url in project ${project.name} has unsupported protocol (${url.protocol})") continue } if (File(url.path).list()?.isEmpty() != false) { + sendEvent("workspace_empty_path", mapOf("path" to url.path)) Logger.getInstance(javaClass).debug("${url.path} in project ${project.name} is empty, skipping") continue } @@ -66,6 +82,7 @@ class WorkspaceListenerService { } val dedupedRootPaths = dedupRootPaths(rootPaths) + sendEvent("workspace_after_dedup", mapOf("before_len" to rootPaths.size.toString(), "after_len" to dedupedRootPaths.size.toString())) Logger.getInstance(javaClass).debug("Root paths for project ${project.name} found: $dedupedRootPaths") return dedupedRootPaths