cx-query-spans
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpans Query Skill
Spans 查询技能
Query and analyze distributed tracing data using the command with DataPrime syntax.
cx spans使用命令结合DataPrime语法查询和分析分布式追踪数据。
cx spansUnderstanding Spans in Coralogix
理解Coralogix中的Spans
Spans are the fundamental unit of tracing data. Traces are not stored as single entities - they are logical groupings of spans that share the same . To analyze a trace, you query its constituent spans.
traceIDThis means:
- Metadata () and labels (
$m.*) are predictable - you can always filter on timestamp, duration, service name, and operation name without discovery.$l.* - User data () contains trace identifiers (
$d.*,traceID,spanID) and application-specific tags/attributes that vary by service. Always verify customparentSpanIDfields before assuming they exist.$d
Spans是追踪数据的基本单元。Traces不会作为单个实体存储——它们是共享同一的Spans的逻辑分组。要分析一个trace,你需要查询其组成的Spans。
traceID这意味着:
- **元数据()和标签(
$m.*)**是可预测的——你无需进行发现操作,即可始终基于时间戳、时长、服务名称和操作名称进行过滤。$l.* - **用户数据()**包含追踪标识符(
$d.*、traceID、spanID)以及因服务而异的应用特定标签/属性。在假设自定义parentSpanID字段存在之前,务必先进行验证。$d
CLI Command
CLI命令
bash
cx spans '<dataprime_query>'The is automatically injected - do not include it in the query.
source spansbash
cx spans '<dataprime_query>'source spansOptions
选项
| Flag | Default | Description |
|---|---|---|
| | Start time (ISO 8601 or relative, e.g. |
| | End time |
| | Maximum number of results |
| | Storage tier: |
| | Output format: |
| 标志 | 默认值 | 描述 |
|---|---|---|
| | 开始时间(ISO 8601格式或相对时间,例如 |
| | 结束时间 |
| | 最大结果数量 |
| | 存储层级: |
| | 输出格式: |
Span Data Model
Span数据模型
Standard Fields (Always Available)
标准字段(始终可用)
| Field | Description |
|---|---|
| Span start timestamp |
| Span duration in microseconds (see Duration Units) |
| Application name - highest-level label. Meaning varies by customer (environment, team, region) but it always exists. |
| Subsystem name - second-level label. Typically maps to a component. |
| Service name - the logical service unit emitting the span. |
| Operation name - the span title (e.g. "POST /checkout", "db.query"). |
| Trace ID - groups spans into a single trace. |
| Unique span identifier. |
| Parent span ID (empty string for root spans). |
| Application-specific tags and attributes (see Field Discovery). |
Note on label fields: The meaning ofand$l.applicationNamevaries by customer - they may represent environments, teams, regions, or something else entirely. Don't assume what they map to. Use$l.subsystemNameor sample queries to verify actual values.cx search-fields
| 字段 | 描述 |
|---|---|
| Span开始时间戳 |
| Span时长(单位为微秒,详见时长单位) |
| 应用名称——最高层级的标签。其含义因客户而异(可能代表环境、团队、区域等),但始终存在。 |
| 子系统名称——第二层级的标签。通常对应某个组件。 |
| 服务名称——生成Span的逻辑服务单元。 |
| 操作名称——Span的标题(例如"POST /checkout"、"db.query")。 |
| Trace ID——将Spans分组为单个trace。 |
| 唯一的Span标识符。 |
| 父Span的ID(根Span为空字符串)。 |
| 应用特定的标签和属性(详见字段发现)。 |
关于标签字段的说明:和$l.applicationName的含义因客户而异——它们可能代表环境、团队、区域或其他内容。不要假设它们的映射关系。使用$l.subsystemName或示例查询来验证实际值。cx search-fields
Duration Units
时长单位
$m.duration- 500ms =
500000 - 1s =
1000000 - 1min =
60000000
When presenting duration values, always convert to human-readable units (milliseconds, seconds, or minutes) and include the unit. Never display raw microsecond values or the "µs" symbol.
dataprime
undefined$m.duration- 500ms =
500000 - 1s =
1000000 - 1min =
60000000
在展示时长值时,务必转换为人类可读的单位(毫秒、秒或分钟)并标注单位。切勿显示原始微秒值或"µs"符号。
dataprime
undefinedComputed field for milliseconds
计算毫秒级时长字段
create latency_ms from $m.duration / 1000
undefinedcreate latency_ms from $m.duration / 1000
undefinedError Detection
错误检测
Spans do not have a field like logs. Errors are typically indicated by:
$m.severity- - the most common convention (OpenTelemetry/Jaeger)
$d.tags.error == true - Status codes in custom fields (e.g. ,
$d.http.status_code)$d.grpc.status_code - Other application-specific error tags
The exact field depends on the instrumentation library used. If returns no results, inspect sample spans with to discover how errors are tagged:
$d.tags.error-o jsonbash
cx spans "filter \$l.serviceName == 'api'" --limit 5 -o jsonSpans不像日志那样拥有字段。错误通常通过以下方式标识:
$m.severity- ——最常见的约定(OpenTelemetry/Jaeger)
$d.tags.error == true - 自定义字段中的状态码(例如、
$d.http.status_code)$d.grpc.status_code - 其他应用特定的错误标签
具体字段取决于所使用的工具库。如果未返回结果,请使用参数查看示例Span,以发现错误的标记方式:
$d.tags.error-o jsonbash
cx spans "filter \$l.serviceName == 'api'" --limit 5 -o jsonQuerying Spans
查询Spans
Essential Examples
基础示例
bash
undefinedbash
undefinedGet all spans for a trace
获取某个trace的所有Spans
cx spans "filter $d.traceID == '4f6a8f3c2e8a1b97'"
cx spans "filter $d.traceID == '4f6a8f3c2e8a1b97'"
Find spans for a service
查找某个服务的Spans
cx spans "filter $l.serviceName == 'checkout-service'"
cx spans "filter $l.serviceName == 'checkout-service'"
Find slow spans (> 1 second)
查找缓慢的Spans(时长>1秒)
cx spans 'filter $m.duration > 1000000'
cx spans 'filter $m.duration > 1000000'
Find error spans
查找错误Spans
cx spans 'filter $d.tags.error == true'
cx spans 'filter $d.tags.error == true'
Aggregate latency by operation
按操作聚合延迟
cx spans 'groupby $l.operationName aggregate avg($m.duration) as avg_latency | orderby avg_latency desc'
cx spans 'groupby $l.operationName aggregate avg($m.duration) as avg_latency | orderby avg_latency desc'
Wider time range
更宽的时间范围
cx spans "filter $l.serviceName == 'api'" --start now-6h
undefinedcx spans "filter $l.serviceName == 'api'" --start now-6h
undefinedWildfind Policy
Wildfind策略
Avoid by default. It scans all fields and is expensive.
wildfindThe one exception: when the user provides a specific string and you don't know which field contains it:
bash
cx spans "wildfind 'connection refused'"In all other cases, use with known fields or discover field names first with .
filtercx search-fieldsTip:can also serve as a last-resort field discovery method - whenwildfinddoesn't find what you need, runcx search-fieldswith a known value, then inspect the matching spans to see which fields contain it.wildfind
默认情况下避免使用。它会扫描所有字段,开销很大。
wildfind唯一例外:当用户提供特定字符串,但你不知道该字符串存在于哪个字段时:
bash
cx spans "wildfind 'connection refused'"在其他所有情况下,请使用结合已知字段,或先使用发现字段名称。
filtercx search-fields提示:也可以作为最后的字段发现方法——当wildfind找不到你需要的内容时,使用已知值运行cx search-fields,然后查看匹配的Spans,确认该值存在于哪些字段中。wildfind
Field Discovery
字段发现
Skip discovery when:
- The query only uses standard fields (,
$m.duration,$l.serviceName,$l.operationName)$d.traceID - The user explicitly names the fields they want
- The fields have already been discovered earlier in the conversation
For customer-specific fields that need discovery, use one of these approaches:
$d.*无需进行发现操作的场景:
- 查询仅使用标准字段(、
$m.duration、$l.serviceName、$l.operationName)$d.traceID - 用户明确指定了他们需要的字段
- 字段已在对话前期完成发现
对于需要发现的客户特定字段,可使用以下方法之一:
$d.*1. Infer from Source Code (Preferred)
1. 从源代码推断(首选)
If you have access to the application's source code, examine OpenTelemetry instrumentation, span attribute definitions, and tracing middleware to identify field names directly.
如果你有权访问应用的源代码,请检查OpenTelemetry工具库、Span属性定义和追踪中间件,直接识别字段名称。
2. Semantic Search
2. 语义搜索
bash
cx search-fields "customer identifier" --dataset spans
cx search-fields "order ID" --dataset spans
cx search-fields "http response code" --dataset spansReturns DataPrime paths with similarity scores. Note: only has access to the most common fields. If it doesn't find what you need, fall back to sample query inspection.
cx search-fieldsbash
cx search-fields "customer identifier" --dataset spans
cx search-fields "order ID" --dataset spans
cx search-fields "http response code" --dataset spans返回带有相似度评分的DataPrime路径。注意:仅能访问最常见的字段。如果未找到所需内容,请回退到示例查询检查。
cx search-fields3. Sample Query Inspection
3. 示例查询检查
bash
cx spans "filter \$l.serviceName == 'api'" --limit 5 -o jsonInspect the JSON output to see all available fields in the actual data. This is especially useful for discovering fields in unstructured or deeply nested data that semantic search may not cover.
bash
cx spans "filter \$l.serviceName == 'api'" --limit 5 -o json查看JSON输出,了解实际数据中的所有可用字段。这对于发现非结构化或深度嵌套数据中的字段尤为有用,这类字段可能无法被语义搜索覆盖。
Troubleshooting
故障排除
If a query returns no results, change one thing at a time:
- Extend the time range: or
--start now-6h--start now-24h - Relax filters: remove the most restrictive condition
- Check field availability: the field you're filtering by may only exist in a subset of spans - a span matching one filter may not have the field from another filter
- Verify field names: run a sample query with to inspect the actual schema
-o json - Check service names: service names are case-sensitive
- Try archive tier: for older data
--tier archive --start now-30d
如果查询未返回结果,请每次只修改一个因素:
- 扩展时间范围:使用或
--start now-6h--start now-24h - 放宽过滤条件:移除最严格的条件
- 检查字段可用性:你过滤的字段可能仅存在于部分Spans中——匹配某个过滤条件的Span可能不包含另一个过滤条件中的字段
- 验证字段名称:运行带参数的示例查询,检查实际的 schema
-o json - 检查服务名称:服务名称区分大小写
- 尝试归档层级:对于较旧的数据,使用
--tier archive --start now-30d
References
参考资料
- skill - Full query language reference: commands, operators, aggregations, text extraction, type conversions
cx-dataprime - Advanced Usage - Investigation workflows, common query patterns, latency analysis, trace debugging
For inline DataPrime help:
bash
cx dataprime list # List all commands and functions
cx dataprime show filter # Detailed help for a specific command- 技能——完整的查询语言参考:命令、运算符、聚合、文本提取、类型转换
cx-dataprime - 高级用法——调查工作流、常见查询模式、延迟分析、trace调试
如需DataPrime内嵌帮助:
bash
cx dataprime list # 列出所有命令和函数
cx dataprime show filter # 查看特定命令的详细帮助Related Skills
相关技能
- - Aggregated latency metrics, histograms, counters (PromQL)
cx-metrics-query - - Detailed log messages correlated with spans (DataPrime)
cx-query-logs - - Gateway skill for choosing the right data source
cx-telemetry-querying
- ——聚合延迟指标、直方图、计数器(PromQL)
cx-metrics-query - ——与Spans关联的详细日志消息(DataPrime)
cx-query-logs - ——用于选择正确数据源的网关技能
cx-telemetry-querying