Skip to content

Conversation

kayagokalp
Copy link
Member

@kayagokalp kayagokalp commented Jul 28, 2025

Description

Add telemetry opt-out support to forc-tracing

This adds fuel-telemetry to forc-tracing (not quite - dependency is currently pointing to Github) with opt-out functionality for upstream tools like fuelup.

Usage

First, add it to the forc-tracing dependency:

[dependencies]
forc-tracing = { version = "0.47", features = ["telemetry"] }

Then use the telemetry::* glob, followed by the usual tracing macros, but with a _telemetry postfix:

use forc_tracing::{
    init_tracing_subscriber, println_green, println_red, println_yellow, telemetry::*,
};

fn main() {
    init_tracing_subscriber(Default::default());

    println_red("Stop");
    println_yellow("Slow down");
    println_green("Go");

    error_telemetry!("Error message for InfluxDB");
    warn_telemetry!("Warn message for InfluxDB");
    info_telemetry!("Info message for InfluxDB");
    debug_telemetry!("Debug message for InfluxDB");
    trace_telemetry!("Trace message for InfluxDB");
}

This will output the following (note DEBUG and TRACE messages are filtered out because of RUST_LOG=info):

> RUST_LOG=info ./target/debug/example
Stop
Slow down
Go

We can then peek into telemetry files like the following:

> cat ~/.fuelup/tmp/*.telemetry.* | while read line; do echo "$line" | base64 -d; echo; done
2025-03-06T19:53:24.923452000Z ERROR aarch64-apple-darwin:Darwin:23.6.0 forc-tracing:0.66.8:src/main.rs 0e3480f5-faab-48b8-a935-21ce90a6f028 auto: Error message for InfluxDB
2025-03-06T19:53:24.925348000Z  WARN aarch64-apple-darwin:Darwin:23.6.0 forc-tracing:0.66.8:src/main.rs 0e3480f5-faab-48b8-a935-21ce90a6f028 auto: Warn message for InfluxDB
2025-03-06T19:53:24.925434000Z  INFO aarch64-apple-darwin:Darwin:23.6.0 forc-tracing:0.66.8:src/main.rs 0e3480f5-faab-48b8-a935-21ce90a6f028 auto: Info message for InfluxDB
2025-03-06T19:53:31.335690000Z  INFO aarch64-apple-darwin:Darwin:23.6.0 systeminfo_watcher:0.1.0:src/systeminfo_watcher.rs ec63b355-7862-47db-9ae3-de0cfcc094c8 poll_systeminfo: cpu_arch="arm64" cpu_brand="Apple M2 Pro" cpu_count=10 global_cpu_usage=15.85 total_memory=34359738368 free_memory=23388143616 free_memory_percentage=0.68 os_long_name="macOS 14.6.1 Sonoma" kernel_version="23.6.0" uptime=2482559 vm="" ci="" load_average_1m=4.52 load_average_5m=4.17 load_average_15m=3.86

New: Telemetry Opt-Out Support

This PR also adds opt-out functionality for telemetry, allowing upstream tools like fuelup to disable telemetry collection:

Changes:

  • Added --disable-telemetry CLI flag to main forc binary
  • Added FORC_DISABLE_TELEMETRY environment variable support
  • Updated all telemetry macros to respect the disable flag
  • Added init_telemetry() function for proper initialization

Opt-out Usage:

# Disable via CLI flag
forc --disable-telemetry build

# Disable via environment variable  
FORC_DISABLE_TELEMETRY=1 forc build

# For upstream tools like fuelup
export FORC_DISABLE_TELEMETRY=1
fuelup toolchain install latest

Code example with opt-out:

use forc_tracing::{init_telemetry, init_tracing_subscriber, TracingSubscriberOptions};

fn main() {
    let options = TracingSubscriberOptions {
        disable_telemetry: Some(true),
        ..Default::default()
    };
    
    init_tracing_subscriber(options.clone());
    init_telemetry(&options);
    
    // Telemetry macros will now be no-ops when disabled
    error_telemetry!("This won't be sent to telemetry if disabled");
}

The implementation ensures telemetry is opt-out by default but can be easily disabled through either CLI flags or environment variables, making it suitable for upstream tool integration.

@kayagokalp kayagokalp marked this pull request as draft July 28, 2025 01:29
@kayagokalp kayagokalp marked this pull request as ready for review August 19, 2025 22:58
@kayagokalp kayagokalp marked this pull request as draft August 19, 2025 23:04
@kayagokalp kayagokalp marked this pull request as ready for review August 26, 2025 05:04
@kayagokalp kayagokalp requested a review from a team August 26, 2025 05:05
zees-dev
zees-dev previously approved these changes Sep 16, 2025
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging Related to logging (tracing, stdout, stderr, log-files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants