Add username to splunk event information#2337
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds username tracking to Splunk telemetry events for better usage monitoring in corporate environments. The username is captured from the system's user information and automatically included in all telemetry events sent to Splunk.
Key changes:
- Username is now captured and added to every Splunk event payload
- Removed automatic flush after each event send operation
- Updated tests to verify username inclusion in event data
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/telemetry/src/backends/splunk.ts | Adds username capture via os.userInfo() and includes it in event payloads |
| packages/telemetry/src/client.ts | Removes automatic flush call after sending events |
| packages/telemetry/tests/backends/splunk.spec.ts | Adds os module mocking and updates test assertions to verify username in events |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private username = os.userInfo().username; | ||
|
|
There was a problem hiding this comment.
The username is captured once during class initialization. If the process runs under different user contexts or if os.userInfo() throws an exception (e.g., in certain containerized environments), this could cause runtime errors or capture incorrect data. Consider wrapping this in a try-catch block or making it a method that can handle errors gracefully.
| private username = os.userInfo().username; | |
| /** | |
| * Safely retrieves the current username. | |
| * Returns 'unknown' if os.userInfo() throws or username is unavailable. | |
| */ | |
| private getUsername(): string { | |
| try { | |
| return os.userInfo().username || 'unknown'; | |
| } catch (e) { | |
| return 'unknown'; | |
| } | |
| } |
There was a problem hiding this comment.
@dividedmind I think suggestion is minor but worthful change, just in case. At least unless use cases totally rule it out (but I'd still add failsafe variant anyway)
|
Deprecated by #2339 |
Splunk telemetry is typically used in corporate environments where username is useful for tracking usage.