Agent Skillszerx-lab/zap › add-telemetry

add-telemetry

GitHub

指导在Warp代码库中添加遥测事件以追踪用户行为或系统状态。涵盖定义事件、实现TelemetryEvent trait及配置启用状态,用于功能监控与调试。

.agents/skills/add-telemetry/SKILL.md zerx-lab/zap

Trigger Scenarios

需要添加新功能的行为追踪 为系统事件配置监控指标 排查问题时注入遥测数据

Install

npx skills add zerx-lab/zap --skill add-telemetry -g -y
More Options

Non-standard path

npx skills add https://github.com/zerx-lab/zap/tree/main/.agents/skills/add-telemetry -g -y

Use without installing

npx skills use zerx-lab/zap@add-telemetry

指定 Agent (Claude Code)

npx skills add zerx-lab/zap --skill add-telemetry -a claude-code -g -y

安装 repo 全部 skill

npx skills add zerx-lab/zap --all -g -y

预览 repo 内 skill

npx skills add zerx-lab/zap --list

SKILL.md

Frontmatter
{
    "name": "add-telemetry",
    "description": "Add telemetry events to track user behavior or system events in the Warp codebase. Use when instrumenting new features, debugging issues, or measuring product metrics."
}

add-telemetry

Overview

Warp uses a trait-based telemetry system where feature-specific enums implement the TelemetryEvent trait. This approach keeps telemetry events organized by domain rather than in one giant enum.

Important: Before implementing telemetry, collaborate with the user to:

  • Define what events should be tracked and when
  • Determine what data should be included in each event
  • Clarify the purpose and expected usage of the telemetry

Adding telemetry code is straightforward, but designing meaningful instrumentation requires careful thought.

Steps

1. Identify or create a telemetry module

Find an existing feature-specific telemetry file (e.g., app/src/antivirus/telemetry.rs) or create a new one for your feature area.

2. Define the telemetry event enum

Add a new variant to an enum that implements TelemetryEvent, or create a new enum:

use serde_json::{json, Value};
use strum_macros::{EnumDiscriminants, EnumIter};
use warp_core::telemetry::{EnablementState, TelemetryEvent, TelemetryEventDesc};

#[derive(Debug, EnumDiscriminants)]
#[strum_discriminants(derive(EnumIter))]
pub enum YourFeatureTelemetryEvent {
    ActionStarted {
        duration_ms: u64,
    },
    ActionCompleted {
        success: bool,
        error: Option<String>,
    },
}

3. Implement the TelemetryEvent trait

EnablementState allows you to control when events are sent:

  • EnablementState::Always - Always send the event
  • EnablementState::Flag(FeatureFlag::YourFeature) - Only send when the feature flag is enabled
  • EnablementState::Channel(Channel::Dev) - Only send in specific build channels
impl TelemetryEvent for YourFeatureTelemetryEvent {
    fn name(&self) -> &'static str {
        YourFeatureTelemetryEventDiscriminants::from(self).name()
    }

    fn payload(&self) -> Option<Value> {
        match self {
            Self::ActionStarted { duration_ms } => Some(json!({
                "duration_ms": duration_ms,
            })),
            Self::ActionCompleted { success, error } => Some(json!({
                "success": success,
                "error": error,
            })),
        }
    }

    fn description(&self) -> &'static str {
        YourFeatureTelemetryEventDiscriminants::from(self).description()
    }

    fn enablement_state(&self) -> EnablementState {
        YourFeatureTelemetryEventDiscriminants::from(self).enablement_state()
    }

    fn contains_ugc(&self) -> bool {
        match self {
            Self::ActionStarted { .. } => false,
            Self::ActionCompleted { .. } => false,
        }
    }

    fn event_descs() -> impl Iterator<Item = Box<dyn TelemetryEventDesc>> {
        warp_core::telemetry::enum_events::<Self>()
    }
}

4. Implement TelemetryEventDesc for the discriminants

impl TelemetryEventDesc for YourFeatureTelemetryEventDiscriminants {
    fn name(&self) -> &'static str {
        match self {
            Self::ActionStarted => "YourFeature.Action.Started",
            Self::ActionCompleted => "YourFeature.Action.Completed",
        }
    }

    fn description(&self) -> &'static str {
        match self {
            Self::ActionStarted => "User started the action",
            Self::ActionCompleted => "User completed the action",
        }
    }

    fn enablement_state(&self) -> EnablementState {
        match self {
            Self::ActionStarted | Self::ActionCompleted => EnablementState::Always,
            // Or gate behind a feature flag:
            // EnablementState::Flag(FeatureFlag::YourFeature)
        }
    }
}

5. Register the telemetry event

At the end of your telemetry module, register the event:

warp_core::register_telemetry_event!(YourFeatureTelemetryEvent);

6. Send telemetry events from your code

Use send_telemetry_from_ctx! in views or models with a ViewContext or ModelContext:

use warp_core::send_telemetry_from_ctx;

// In a view update or model method
send_telemetry_from_ctx!(
    YourFeatureTelemetryEvent::ActionStarted {
        duration_ms: 150,
    },
    ctx
);

For code with only AppContext, use send_telemetry_from_app_ctx! instead.

7. Test locally

Run Warp with the log_named_telemetry_events feature flag to see telemetry events logged to the console:

cargo run --features log_named_telemetry_events

Best Practices

  • Keep telemetry enums feature-specific rather than adding to a global enum
  • Set contains_ugc() to true if the payload includes user-generated content
  • Use descriptive event names following the pattern Feature.Action.Result
  • Include only necessary data in payloads to minimize bandwidth and storage
  • Consider privacy implications when deciding what data to include
  • Avoid exhaustive matching with wildcards; handle all variants explicitly

Example Reference

See app/src/antivirus/telemetry.rs for a complete example of a feature-specific telemetry implementation.

Version History

  • 5d87445 Current 2026-07-24 17:35

Same Skill Collection

.agents/skills/add-feature-flag/SKILL.md
.agents/skills/dedupe-issue-local/SKILL.md
.agents/skills/diagnose-ci-failures/SKILL.md
.agents/skills/fix-errors/SKILL.md
.agents/skills/implement-specs/SKILL.md
.agents/skills/promote-feature/SKILL.md
.agents/skills/remove-feature-flag/SKILL.md
.agents/skills/resolve-merge-conflicts/SKILL.md
.agents/skills/review-pr-local/SKILL.md
.agents/skills/review-pr/SKILL.md
.agents/skills/rust-unit-tests/SKILL.md
.agents/skills/spec-driven-implementation/SKILL.md
.agents/skills/triage-issue-local/SKILL.md
.agents/skills/update-skill/SKILL.md
.agents/skills/warp-integration-test/SKILL.md
.agents/skills/warp-ui-guidelines/SKILL.md
.agents/skills/write-product-spec/SKILL.md
.agents/skills/write-tech-spec/SKILL.md
resources/bundled/mcp_skills/figma/figma-code-connect-components/SKILL.md
resources/bundled/mcp_skills/figma/figma-create-design-system-rules/SKILL.md
resources/bundled/mcp_skills/figma/figma-create-new-file/SKILL.md
resources/bundled/mcp_skills/figma/figma-generate-library/SKILL.md
resources/bundled/mcp_skills/figma/figma-implement-design/SKILL.md
resources/bundled/skills/add-mcp-server/SKILL.md
resources/bundled/skills/create-skill/SKILL.md
resources/bundled/skills/create-tab-config/SKILL.md
resources/bundled/skills/feedback/SKILL.md
resources/bundled/skills/modify-settings/SKILL.md
resources/bundled/skills/pr-comments/SKILL.md
resources/bundled/skills/tab-configs/SKILL.md
resources/bundled/skills/update-tab-config/SKILL.md
resources/channel-gated-skills/dogfood/triage-vulnerabilities/SKILL.md
resources/bundled/mcp_skills/figma/edit-figma-design/SKILL.md
resources/bundled/mcp_skills/figma/figma-generate-design/SKILL.md
resources/bundled/mcp_skills/figma/figma-use/SKILL.md
resources/bundled/skills/claude-api/SKILL.md

Metadata

Files
0
Version
5d87445
Hash
3a255d5c
Indexed
2026-07-24 17:35

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 20:47
浙ICP备14020137号-1 $mapa de visitantes$