Skip to content

feat(telemetry): runtime endpoint config + opt-in by default (#73)#190

Open
quangdang46 wants to merge 1 commit into
masterfrom
feat/telemetry-runtime-endpoint-opt-in
Open

feat(telemetry): runtime endpoint config + opt-in by default (#73)#190
quangdang46 wants to merge 1 commit into
masterfrom
feat/telemetry-runtime-endpoint-opt-in

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

What

Two related changes that move telemetry from "baked-in URL, on by default" to "runtime-resolved URL, opt-in by default":

This addresses issue #73: #73

Changes

  • src/telemetry.rs:
    • Drop the const TELEMETRY_ENDPOINT pointing at upstream's Cloudflare Worker.
    • Add telemetry_endpoint() runtime resolver. Resolution order:
      1. JCODE_TELEMETRY_ENDPOINT environment variable.
      2. endpoint = "..." in ${JCODE_HOME:-~/.jcode}/telemetry.toml.
      3. None — telemetry is disabled (the fork's default).
    • Empty / whitespace-only values resolve to None so JCODE_TELEMETRY_ENDPOINT="" reliably disables telemetry without needing the separate JCODE_NO_TELEMETRY knob.
    • is_enabled() now requires telemetry_endpoint().is_some(). Existing JCODE_NO_TELEMETRY / DO_NOT_TRACK / no_telemetry marker short-circuits still apply.
    • post_payload() resolves the endpoint at send time; if None, returns false immediately so no event leaves the process without an explicit endpoint.
  • src/telemetry/tests.rs: 3 regression tests:
    • telemetry_endpoint_returns_none_without_config
    • telemetry_endpoint_picks_up_env_var (incl. whitespace → None)
    • telemetry_endpoint_picks_up_telemetry_toml

Tests

$ cargo test -p jcode --lib telemetry::tests::telemetry_endpoint
test result: ok. 3 passed; 0 failed

Notes

Ports upstream PR 1jehuang#77.

Two related changes that move telemetry from "baked-in URL, on by
default" to "runtime-resolved URL, opt-in by default":

1. Drop the const TELEMETRY_ENDPOINT pointing at upstream's Cloudflare
   Worker. Replace it with a runtime resolver telemetry_endpoint()
   that reads, in order:
     a. JCODE_TELEMETRY_ENDPOINT environment variable
     b. endpoint = "..." in ${JCODE_HOME:-~/.jcode}/telemetry.toml
     c. None
   Empty / whitespace-only values resolve to None so a user can
   disable telemetry by setting JCODE_TELEMETRY_ENDPOINT="" without
   needing the separate JCODE_NO_TELEMETRY knob.

2. is_enabled() now requires telemetry_endpoint().is_some(). The pre-
   existing JCODE_NO_TELEMETRY / DO_NOT_TRACK / no_telemetry marker
   short-circuits still apply on top.

3. post_payload() resolves the endpoint at send time and returns false
   if the resolver yields None, so even if a caller bypasses
   is_enabled(), no event leaves the process without an explicitly
   configured endpoint.

Three tests in src/telemetry/tests.rs pin the contract:
- telemetry_endpoint_returns_none_without_config
- telemetry_endpoint_picks_up_env_var (incl. whitespace -> None)
- telemetry_endpoint_picks_up_telemetry_toml

Ports upstream PR 1jehuang#77.
Closes #73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant