Skip to content

feat: send telemetry when hint in editor was clicked (#869) #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ open class ResourceEditorFactory protected constructor(
private fun createTelemetry(file: VirtualFile): TelemetryMessageBuilder.ActionMessage {
val isLocalFile = ResourceFile.isResourceFile(file)
return getTelemetryMessageBuilder().action(
"${TelemetryService.NAME_PREFIX_EDITOR} open ${
"${TelemetryService.NAME_PREFIX_EDITOR}open ${
if (isLocalFile) {
"cluster file"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.redhat.devtools.intellij.common.validation.KubernetesTypeInfo
import com.redhat.devtools.intellij.kubernetes.balloon.StringInputBalloon
import com.redhat.devtools.intellij.kubernetes.editor.inlay.base64.Base64Presentations.InlayPresentationsFactory
import com.redhat.devtools.intellij.kubernetes.editor.inlay.base64.Base64Presentations.create
import com.redhat.devtools.intellij.kubernetes.editor.util.getBinaryData
import com.redhat.devtools.intellij.kubernetes.editor.util.getDataValue
import com.redhat.devtools.intellij.kubernetes.editor.util.getKey
import com.redhat.devtools.intellij.kubernetes.editor.util.isKubernetesResource
import com.redhat.devtools.intellij.kubernetes.model.util.trimWithEllipsis
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService
import org.jetbrains.concurrency.runAsync
import java.awt.event.MouseEvent

Expand Down Expand Up @@ -97,12 +98,7 @@ object Base64Presentations {
override fun create(adapter: Base64ValueAdapter): InlayPresentation? {
val decoded = adapter.getDecoded() ?: return null
val offset = adapter.getStartOffset() ?: return null
val onClick = StringInputBalloon(
decoded,
onValidValue(adapter::set, editor.project),
editor
)::show
val presentation = create(decoded, onClick, factory) ?: return null
val presentation = create(decoded, { event -> onClick(adapter.element, decoded, adapter, event) }, factory) ?: return null
sink.addInlineElement(offset, false, presentation, false)
return presentation
}
Expand All @@ -120,6 +116,19 @@ object Base64Presentations {
)
}

private fun onClick(element: PsiElement, decoded: String, adapter: Base64ValueAdapter, event: MouseEvent) {
runAsync {
TelemetryService.instance.action("${TelemetryService.NAME_PREFIX_EDITOR_HINT}base64Hint")
.property(TelemetryService.PROP_PROPERTY_NAME, element.getKey()?.text)
.send()
}
StringInputBalloon(
decoded,
onValidValue(adapter::set, editor.project),
editor
).show(event)
}

private fun onValidValue(setter: (value: String, wrapAt: Int) -> Unit, project: Project?)
: (value: String) -> Unit {
return { value ->
Expand All @@ -130,7 +139,6 @@ object Base64Presentations {
}
}
}

}

class BinaryPresentationsFactory(element: PsiElement, sink: InlayHintsSink, editor: Editor, factory: PresentationFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.redhat.devtools.intellij.kubernetes.editor.util.getValue
import com.redhat.devtools.intellij.kubernetes.editor.util.setValue
import org.jetbrains.yaml.psi.YAMLKeyValue

class Base64ValueAdapter(private val element: PsiElement) {
class Base64ValueAdapter(val element: PsiElement) {

private companion object {
private val CONTENT_REGEX = Regex("[^\"\n |]*", RegexOption.MULTILINE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import com.redhat.devtools.intellij.kubernetes.editor.util.getLabels
import com.redhat.devtools.intellij.kubernetes.editor.util.getSelector
import com.redhat.devtools.intellij.kubernetes.editor.util.getTemplate
import com.redhat.devtools.intellij.kubernetes.editor.util.hasTemplate
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService
import com.redhat.devtools.intellij.kubernetes.usage.LabelsFilter
import com.redhat.devtools.intellij.kubernetes.usage.SelectorsFilter
import org.jetbrains.concurrency.runAsync
import java.awt.Point
import java.awt.event.MouseEvent
import javax.swing.Icon
Expand Down Expand Up @@ -156,6 +158,11 @@ object SelectorPresentations {
return { event, point ->
val project = editor.project
if (project != null) {
runAsync {
TelemetryService.instance.action("${TelemetryService.NAME_PREFIX_EDITOR_HINT}selector")
.property(TelemetryService.PROP_PROPERTY_NAME, hintedKeyValue.getKey()?.text)
.send()
}
ShowUsagesAction.startFindUsages(hintedKeyValue, RelativePoint(event), editor)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ import io.fabric8.kubernetes.api.model.HasMetadata
object TelemetryService {

const val NAME_PREFIX_EDITOR = "editor-"
const val NAME_PREFIX_EDITOR_HINT = "${NAME_PREFIX_EDITOR}hint_clicked-"
const val NAME_PREFIX_NAMESPACE = "current_namespace-"
const val NAME_PREFIX_CONTEXT = "current_context-"

const val PROP_RESOURCE_KIND = "resource_kind"
const val PROP_IS_OPENSHIFT = "is_openshift"
const val PROP_KUBERNETES_VERSION = "kubernetes_version"
const val PROP_OPENSHIFT_VERSION = "openshift_version"
const val PROP_PROPERTY_NAME = "property_name"

val instance: TelemetryMessageBuilder by lazy {
return@lazy if (!ApplicationManager.getApplication().isUnitTestMode) {
Expand Down
Loading