Skip to content

Commit

Permalink
Pass machine ID to server for telemetry (#3157)
Browse files Browse the repository at this point in the history
### Motivation

Pass the unique machine identifier to the server as an initialization option, so that it can be used to estimate number of unique users on server telemetry events.

Reminder that we [do not collect any telemetry by default](https://github.com/Shopify/ruby-lsp/tree/main/vscode#telemetry), unless a VS Code extension implements the `getTelemetrySenderObject` command.

### Implementation

Started passing the value from the extension and saving it in the global state.

### Automated Tests

Added a test.
  • Loading branch information
vinistock committed Feb 10, 2025
1 parent 1b72201 commit 2fee8ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class GlobalState
sig { returns(URI::Generic) }
attr_reader :workspace_uri

sig { returns(T.nilable(String)) }
attr_reader :telemetry_machine_id

sig { void }
def initialize
@workspace_uri = T.let(URI::Generic.from_path(path: Dir.pwd), URI::Generic)
Expand All @@ -57,6 +60,7 @@ def initialize
@client_capabilities = T.let(ClientCapabilities.new, ClientCapabilities)
@enabled_feature_flags = T.let({}, T::Hash[Symbol, T::Boolean])
@mutex = T.let(Mutex.new, Mutex)
@telemetry_machine_id = T.let(nil, T.nilable(String))
end

sig { type_parameters(:T).params(block: T.proc.returns(T.type_parameter(:T))).returns(T.type_parameter(:T)) }
Expand Down Expand Up @@ -175,6 +179,7 @@ def apply_options(options)
enabled_flags = options.dig(:initializationOptions, :enabledFeatureFlags)
@enabled_feature_flags = enabled_flags if enabled_flags

@telemetry_machine_id = options.dig(:initializationOptions, :telemetryMachineId)
notifications
end

Expand Down
8 changes: 8 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ def test_falls_back_to_internal_integration_for_formatters_if_rubocop_has_no_add
assert_equal("rubocop_internal", state.formatter)
end

def test_saves_telemetry_machine_id
state = GlobalState.new
assert_nil(state.telemetry_machine_id)

state.apply_options({ initializationOptions: { telemetryMachineId: "test_machine_id" } })
assert_equal("test_machine_id", state.telemetry_machine_id)
end

private

def stub_direct_dependencies(dependencies)
Expand Down
1 change: 1 addition & 0 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function collectClientOptions(
indexing: configuration.get("indexing"),
addonSettings: configuration.get("addonSettings"),
enabledFeatureFlags: enabledFeatureFlags(),
telemetryMachineId: vscode.env.machineId,
},
};
}
Expand Down

0 comments on commit 2fee8ba

Please sign in to comment.