Skip to content

Commit

Permalink
Merge pull request #147 from GaloisInc/sc/user-profile-telemetry
Browse files Browse the repository at this point in the history
client, server: allow associating user information with telemetry
  • Loading branch information
samcowger authored Jan 27, 2025
2 parents 50e3197 + c51e092 commit 36855d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cn-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"type": "string",
"default": null,
"description": "Where to store telemetry. Changes take effect on server start/restart."
},
"CN.userID": {
"type": "string",
"default": null,
"description": "A user ID to associate with telemetry. Changes take effect on server start/restart."
}
}
},
Expand Down
15 changes: 13 additions & 2 deletions cn-lsp/lib/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module Config = struct
type t =
{ run_CN_on_save : bool [@key "runOnSave"]
; telemetry_dir : string option [@default None] [@key "telemetryDir"]
; user_id : string option [@default None] [@key "userID"]
}
[@@deriving yojson { strict = false }]
(* `strict = false` to account for extra configuration fields the client
Expand All @@ -55,7 +56,7 @@ module Config = struct
CN-specific settings *)
let section : string = "CN"

let default : t = { run_CN_on_save = false; telemetry_dir = None }
let default : t = { run_CN_on_save = false; telemetry_dir = None; user_id = None }
end

let sprintf = Printf.sprintf
Expand Down Expand Up @@ -306,7 +307,17 @@ class lsp_server (env : LspCn.cerb_env) =
method initialize_telemetry (dir : string) : unit =
match Storage.(create { root_dir = dir }) with
| Error _e -> Log.e "Unable to create telemetry storage"
| Ok storage -> telemetry_storage <- Some storage
| Ok storage ->
telemetry_storage <- Some storage;
(match server_config.user_id with
| None -> ()
| Some id ->
let profile = ProfileData.{ id } in
(match Storage.store_profile storage ~profile with
| Error _e -> Log.e "Unable to save user ID"
| Ok (Some prev) ->
Log.d (sprintf "Wrote new ID %s (overwrite existing ID %s)" id prev.id)
| Ok None -> Log.d (sprintf "Wrote new ID %s" id)))

method record_telemetry (event_data : EventData.t) : unit =
match server_config.telemetry_dir, telemetry_storage with
Expand Down

0 comments on commit 36855d3

Please sign in to comment.