Skip to content

Commit

Permalink
Collect telemetry about add-on usage (#2187)
Browse files Browse the repository at this point in the history
### Motivation

Start collecting telemetry about when the different DSL functionalities we provide are used, so that we can get an idea of the adoption.

### Implementation

All we have to do is push telemetry notifications to the outgoing queue in the right format.
  • Loading branch information
vinistock authored Feb 11, 2025
2 parents 055d7a0 + b5d94a9 commit 2857c61
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ GEM
rubocop (~> 1.51)
rubocop-sorbet (0.8.7)
rubocop (>= 1)
ruby-lsp (0.23.9)
ruby-lsp (0.23.10)
language_server-protocol (~> 3.17.0)
prism (>= 1.2, < 2.0)
rbs (>= 3, < 4)
Expand Down
31 changes: 28 additions & 3 deletions lib/ruby_lsp/tapioca/addon.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: strict
# frozen_string_literal: true

RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.1", "< 0.24")
RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.10", "< 0.24")

begin
# The Tapioca add-on depends on the Rails add-on to add a runtime component to the runtime server. We can allow the
Expand Down Expand Up @@ -53,8 +53,11 @@ def activate(global_state, outgoing_queue)
workspace_path: @global_state.workspace_path,
)

send_usage_telemetry("activated")
run_gem_rbi_check
rescue IncompatibleApiError
send_usage_telemetry("incompatible_api_error")

# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
# changes
@outgoing_queue << Notification.window_log_message(
Expand All @@ -80,7 +83,7 @@ def version

sig { params(changes: T::Array[{ uri: String, type: Integer }]).void }
def workspace_did_change_watched_files(changes)
return unless T.must(@global_state).enabled_feature?(:tapiocaAddon)
return unless @global_state&.enabled_feature?(:tapiocaAddon)
return unless @rails_runner_client.connected?

has_route_change = T.let(false, T::Boolean)
Expand Down Expand Up @@ -124,19 +127,22 @@ def workspace_did_change_watched_files(changes)
@rails_runner_client.delegate_notification(
server_addon_name: "Tapioca",
request_name: "reload_workspace_compilers",
workspace_path: T.must(@global_state).workspace_path,
workspace_path: @global_state.workspace_path,
)
end

if has_route_change
send_usage_telemetry("route_dsl")
@rails_runner_client.delegate_notification(server_addon_name: "Tapioca", request_name: "route_dsl")
end

if has_fixtures_change
send_usage_telemetry("fixtures_dsl")
@rails_runner_client.delegate_notification(server_addon_name: "Tapioca", request_name: "fixtures_dsl")
end

if constants.any?
send_usage_telemetry("dsl")
@rails_runner_client.delegate_notification(
server_addon_name: "Tapioca",
request_name: "dsl",
Expand All @@ -147,6 +153,25 @@ def workspace_did_change_watched_files(changes)

private

sig { params(feature_name: String).void }
def send_usage_telemetry(feature_name)
return unless @outgoing_queue && @global_state

# Telemetry is not captured by default even if events are produced by the server
# See https://github.com/Shopify/ruby-lsp/tree/main/vscode#telemetry
@outgoing_queue << Notification.telemetry({
eventName: "tapioca_addon.feature_usage",
type: "data",
data: {
type: "counter",
attributes: {
label: feature_name,
machineId: @global_state.telemetry_machine_id,
},
},
})
end

sig { params(change: T::Hash[Symbol, T.untyped], path: String).returns(T::Boolean) }
def file_updated?(change, path)
case change[:type]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2857c61

Please sign in to comment.