metrics-knowledge

Instrument Go services with ByteDance Metrics SDK and query monitoring data.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill metrics-knowledge-yuezhen-huang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: metrics-knowledge
Source: https://github.com/yuezhen-huang/my-bytedance-skillhub/tree/main/metrics-knowledge
Command: npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill metrics-knowledge-yuezhen-huang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go developers at ByteDance need to emit monitoring metrics from their services and query collected data, but must choose between SDK versions (V2, V3, V4), understand agent prerequisites, and handle query quota and region configuration correctly. ## Core Features & Use Cases - SDK Instrumentation Guidance: Complete examples for emitting Counter, RateCounter, Store, Timer, and Histogram metrics using the gopkg/metrics V2, V3, and V4 clients. - Metrics Query SDK: Instructions for initializing the metrics-query client, building queries, and handling quota, region, and authentication errors. - Version Selection & Migration: Feature comparison of V2/V3/V4, incompatibility notes, and upgrade recommendations including Metrics-2.0 multi-tenant and multi-value metric support. - Use Case: A developer adding latency monitoring to a new Go microservice can follow the V4 guide to create a client, emit a multi-value Timer metric, verify emission with strace, and then query the data via the metrics-query SDK. ## Quick Start Ask the AI to show how to instrument a Go service with the Metrics V4 SDK and emit a timer metric with tags.

Frequently Asked Questions about metrics-knowledge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I emit metrics from a Go service with the ByteDance Metrics SDK?

Install code.byted.org/gopkg/metrics/v4, create a client with m.NewClient, define a metric with NewMetricWithOps, then call metric.WithTags(...).Emit(...) with types like Incr, Store, Observe, or Stat. Keep the client and metric as global variables rather than recreating them per emission.

What is the difference between Metrics SDK V2, V3, and V4?

V4 is the recommended latest version using codec-2.0 encoding with native Metrics-2.0 support and 10%-100% better performance. V3 fixed V2's data loss issues with over 50% performance gains. V2 is an early version not recommended for new projects.

How do I query Metrics data from Go code?

Use the code.byted.org/inf/metrics-query SDK: create a client with mq.NewClient using your app name and secret, build queries with mq.NewQuery, and execute via client.NewRequest with a region and time interval. Note that each metric consumes one query quota.

Why does the Metrics SDK query return 401 Authorization failure?

The 401 token missing error means fetching a token from QueryProxy failed, usually because the application APP_NAME was not created in the region of the real query route. Create the app in the target region to resolve it.

How do I verify Metrics SDK instrumentation is working?

Use strace to trace the process write system calls: run strace -f -s 65535 -p $pid and grep for your metric name. If you see the SDK writing data, the instrumentation is working correctly.

What are the limitations when creating metrics with the V4 SDK?

A single V4 client supports at most 1024 metrics, does not allow duplicate metric names, empty metric names, or duplicate tag keys, and enforces stricter string format rules. NewClient and NewMetric also return errors that must be handled, unlike V3.