-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(telemetry): track when the run query button is clicked INTELLIJ-…
…178 (#114)
- Loading branch information
Showing
10 changed files
with
173 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...etbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/observability/probe/QueryRunProbe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.mongodb.jbplugin.observability.probe | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.intellij.psi.PsiElement | ||
import com.mongodb.jbplugin.meta.service | ||
import com.mongodb.jbplugin.mql.Node | ||
import com.mongodb.jbplugin.mql.components.HasSourceDialect | ||
import com.mongodb.jbplugin.observability.TelemetryEvent | ||
import com.mongodb.jbplugin.observability.TelemetryService | ||
import com.mongodb.jbplugin.observability.useLogMessage | ||
|
||
private val logger: Logger = logger<QueryRunProbe>() | ||
|
||
/** | ||
* This probe is emitted when the user requests to run a query through the gutter icon | ||
* action. | ||
*/ | ||
@Service | ||
class QueryRunProbe { | ||
fun queryRunRequested( | ||
query: Node<PsiElement>, | ||
console: TelemetryEvent.QueryRunEvent.Console, | ||
trigger: TelemetryEvent.QueryRunEvent.TriggerLocation | ||
) { | ||
val telemetry by service<TelemetryService>() | ||
|
||
var dialect = query.component<HasSourceDialect>() ?: return | ||
val event = TelemetryEvent.QueryRunEvent(dialect.name, console, trigger) | ||
telemetry.sendEvent(event) | ||
|
||
logger.info( | ||
useLogMessage("Query run requested.") | ||
.mergeTelemetryEventProperties(event) | ||
.build() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ains-plugin/src/test/kotlin/com/mongodb/jbplugin/observability/probe/QueryRunProbeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.mongodb.jbplugin.observability.probe | ||
|
||
import com.intellij.openapi.application.Application | ||
import com.intellij.psi.PsiElement | ||
import com.mongodb.jbplugin.fixtures.IntegrationTest | ||
import com.mongodb.jbplugin.fixtures.mockLogMessage | ||
import com.mongodb.jbplugin.fixtures.withMockedService | ||
import com.mongodb.jbplugin.mql.Node | ||
import com.mongodb.jbplugin.mql.components.HasSourceDialect | ||
import com.mongodb.jbplugin.observability.TelemetryEvent | ||
import com.mongodb.jbplugin.observability.TelemetryService | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
|
||
@IntegrationTest | ||
internal class QueryRunProbeTest { | ||
@Test | ||
fun `should send a QueryRunEvent event`(application: Application) { | ||
val telemetryService = mock<TelemetryService>() | ||
val dialect = HasSourceDialect.DialectName.entries.toTypedArray().random() | ||
val console = TelemetryEvent.QueryRunEvent.Console.entries.toTypedArray().random() | ||
val triggerLocation = TelemetryEvent.QueryRunEvent.TriggerLocation.entries.toTypedArray().random() | ||
|
||
val query = Node<PsiElement?>(null, listOf(HasSourceDialect(dialect))) as Node<PsiElement> | ||
|
||
application.withMockedService(telemetryService) | ||
.withMockedService(mockLogMessage()) | ||
|
||
val probe = QueryRunProbe() | ||
|
||
probe.queryRunRequested(query, console, triggerLocation) | ||
|
||
verify(telemetryService).sendEvent( | ||
TelemetryEvent.QueryRunEvent( | ||
dialect, | ||
console, | ||
triggerLocation | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters