-
Notifications
You must be signed in to change notification settings - Fork 42
feat(telemetry): local JSONL sink with per-session files #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EhabY
wants to merge
5
commits into
main
Choose a base branch
from
telemetry/local-jsonl-sink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5e640dc
feat(telemetry): local JSONL sink with per-session files
EhabY 20d3006
refactor(telemetry): pull settings into src/settings, simplify sink a…
EhabY 359fd45
fix(telemetry): address review feedback on local JSONL sink
EhabY 85b3cbc
fix(telemetry): second round of review feedback on local JSONL sink
EhabY 405c5d1
refactor(telemetry): self-review polish on local sink
EhabY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
| import type { WorkspaceConfiguration } from "vscode"; | ||
|
EhabY marked this conversation as resolved.
|
||
|
|
||
| import type { TelemetryLevel } from "../telemetry/event"; | ||
|
|
||
| export const TELEMETRY_LEVEL_SETTING = "coder.telemetry.level"; | ||
| export const LOCAL_SINK_SETTING = "coder.telemetry.local"; | ||
|
|
||
| /** Telemetry level. Falls back to `local` for unknown or invalid values. */ | ||
| export function readTelemetryLevel( | ||
| cfg: Pick<WorkspaceConfiguration, "get">, | ||
| ): TelemetryLevel { | ||
| const value = cfg.get<string>(TELEMETRY_LEVEL_SETTING); | ||
| return value === "off" || value === "local" ? value : "local"; | ||
| } | ||
|
|
||
| export interface LocalSinkConfig { | ||
| readonly flushIntervalMs: number; | ||
| readonly flushBatchSize: number; | ||
| readonly bufferLimit: number; | ||
| readonly maxFileBytes: number; | ||
| readonly maxAgeDays: number; | ||
| readonly maxTotalBytes: number; | ||
| } | ||
|
|
||
| export const LOCAL_SINK_DEFAULTS: LocalSinkConfig = { | ||
| flushIntervalMs: 15_000, | ||
| flushBatchSize: 100, | ||
| bufferLimit: 500, | ||
| maxFileBytes: 5 * 1024 * 1024, | ||
| maxAgeDays: 30, | ||
| maxTotalBytes: 100 * 1024 * 1024, | ||
| }; | ||
|
|
||
| // Defense in depth: VS Code does not enforce JSON schema at runtime, so users | ||
| // can drop in any value via settings.json. Mirrors the minimums in package.json. | ||
| const LOCAL_SINK_MINIMUMS: LocalSinkConfig = { | ||
| flushIntervalMs: 1000, | ||
| flushBatchSize: 1, | ||
| bufferLimit: 10, | ||
| maxFileBytes: 4096, | ||
| maxAgeDays: 1, | ||
| maxTotalBytes: 4096, | ||
| }; | ||
|
|
||
| /** Per-field: missing, non-numeric, or below-minimum values fall back to defaults. */ | ||
| export function readLocalSinkConfig( | ||
| cfg: Pick<WorkspaceConfiguration, "get">, | ||
| ): LocalSinkConfig { | ||
| const raw = cfg.get(LOCAL_SINK_SETTING); | ||
| const obj = | ||
| raw && typeof raw === "object" && !Array.isArray(raw) | ||
| ? (raw as Record<string, unknown>) | ||
| : {}; | ||
| const read = (key: keyof LocalSinkConfig): number => { | ||
| const value = obj[key]; | ||
| return typeof value === "number" && value >= LOCAL_SINK_MINIMUMS[key] | ||
| ? value | ||
| : LOCAL_SINK_DEFAULTS[key]; | ||
| }; | ||
| return { | ||
| flushIntervalMs: read("flushIntervalMs"), | ||
| flushBatchSize: read("flushBatchSize"), | ||
| bufferLimit: read("bufferLimit"), | ||
| maxFileBytes: read("maxFileBytes"), | ||
| maxAgeDays: read("maxAgeDays"), | ||
| maxTotalBytes: read("maxTotalBytes"), | ||
| }; | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.