agentleFS
gabriellstgabriellst/codm/.claude/skills/trace-analysis/SKILL.md

trace-analysis

Skill4 starsChanged 2 months agoMITView on GitHub

Use when debugging issues with Grafana Tempo traces, analyzing request flows, finding slow operations, or investigating errors. Use this skill for any production debugging that requires trace analysis, span inspection, or performance investigation.

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check error details in span attributes:

    line 136
  2. Distinctive:

    Look at input that caused the error:

    line 141
  3. Distinctive:

    Check call hierarchy in trace view:

    line 151
  4. Very specific:

    Check component order: router → middleware → controller → service → repository

    line 163
  5. Very specific:

    Verify data transformation via method.input.json and method.output.json

    line 164
  6. Distinctive:

    Look for: error status codes, long durations between spans, gaps in the trace, and unexpected span attributes.

    line 200
  7. Very specific:

    Read span attributes (input, output, error.message) to understand what went wrong.

    line 203
  8. Very specific:

    Check OTEL_COLLECTOR_TRACE_URL in Config

    line 226
  9. Very specific:

    Verify startTelemetry() called at startup

    line 227
  10. Very specific:

    Check if class is resolved via DI container (auto-traced via autoTrace)

    line 228
  11. Very specific:

    Check method.result.keys for object structure

    line 234

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Trace Analysis

Analyze distributed traces in Grafana Tempo using span attributes from packages/api/typescript/src/shared/utils/Tracing.ts.

When to Use

  • Debugging production errors or unexpected behavior
  • Investigating slow API responses
  • Analyzing request flows across services
  • Finding error patterns in specific endpoints

When NOT to Use

  • Local development debugging (use console logs or debugger)
  • Investigating frontend-only issues
  • Database performance issues (use Grafana dashboards instead)

Available Span Attributes

Class/Component

AttributeTypeDescription
class.namestringClass name (e.g., CreateUserUseCase)
class.componentstringComponent type: router, middleware, controller, service, repository, handler, factory, event, mediator
class.modulestringContext/module name (e.g., user, appointment)

Method

AttributeTypeDescription
method.namestringMethod name (e.g., execute, save)
method.typestringasync or sync
method.args.countnumberNumber of arguments passed
method.input.jsonstringJSON stringified input arguments
method.output.jsonstringJSON stringified return value
method.duration.msnumberExecution time in milliseconds
method.timestamp.startnumberUnix timestamp when method started
method.timestamp.endnumberUnix timestamp when method ended

Result

AttributeTypeDescription
method.result.typestringtypeof result (object, string, etc.)
method.result.has_valuebooleanWhether method returned a value
method.result.constructorstringResult object's constructor name
method.result.keysstringComma-separated object keys

Error

AttributeTypeDescription
method.error.typestringError constructor name (e.g., BaseError)
method.error.messagestringError message
method.error.stackstringFull stack trace

TraceQL Queries

Find Errors

// All errors in a module
{ class.module = "appointment" && status = error }

// Specific error type
{ method.error.type = "ValidationError" }

// Errors containing message
{ method.error.message =~ ".*not found.*" }

Performance Analysis

// Slow operations (>1000ms)
{ method.duration.ms > 1000 }

// Slow repository calls
{ class.component = "repository" && method.duration.ms > 500 }

// Slow use cases in specific module
{ class.component = "usecase" && class.module = "user" && method.duration.ms > 2000 }

Filter by Component Layer

// All controller calls
{ class.component = "controller" }

// Repository operations for a module
{ class.component = "repository" && class.module = "appointment" }

// Event handlers
{ class.component = "handler" }

Find Specific Operations

// Specific class and method
{ class.name = "CreateUserUseCase" && method.name = "execute" }

// All save operations
{ method.name = "save" }

// Search by input content
{ method.input.json =~ ".*email@example.com.*" }

Trace Flow Analysis

// Full request trace for a module
{ class.module = "appointment" } | select(class.name, method.name, method.duration.ms)

// Compare async vs sync methods
{ method.type = "async" && class.component = "service" }

Debugging Workflows

Investigating a Failed Request

  1. Find the error span:
    { status = error && class.module = "<module>" }
  2. Check error details in span attributes:
    • method.error.type - What error class
    • method.error.message - Error description
    • method.error.stack - Stack trace
  3. Look at input that caused the error:
    • method.input.json - Arguments passed

Performance Investigation

  1. Find slow operations:
    { method.duration.ms > 1000 }
  2. Check call hierarchy in trace view:
    • Which component is slowest?
    • Which method within that component?
  3. Analyze pattern:
    { class.name = "SlowClass" } | rate() by (method.name)

Request Flow Analysis

  1. Get full trace for a request
  2. Check component order: router → middleware → controller → service → repository
  3. Verify data transformation via method.input.json and method.output.json

Grafana Dashboard Queries

Error Rate by Module

sum(rate(traces_spanmetrics_calls_total{status="STATUS_CODE_ERROR"}[5m])) by (class_module)

P95 Latency by Component

histogram_quantile(0.95, sum(rate(traces_spanmetrics_latency_bucket[5m])) by (le, class_component))

Throughput by Use Case

sum(rate(traces_spanmetrics_calls_total{class_component="usecase"}[5m])) by (class_name)

Debugging Process

Step 1: Identify the Symptom

Determine what you're investigating: error responses (5xx), slow requests, missing data, or unexpected behavior.

Step 2: Choose Query Strategy

SymptomStrategy
Known requestSearch by traceId
Error on endpointFilter by http.route + status = error
Slow responsesFilter by duration > 1s + http.route
Missing dataSearch by entity ID in span attributes

Step 3: Analyze Spans

Look for: error status codes, long durations between spans, gaps in the trace, and unexpected span attributes.

Step 4: Identify Root Cause

Read span attributes (input, output, error.message) to understand what went wrong.

Complete Debugging Example

Problem: API returns 500 on POST /appointments

// Step 1: Search error spans
{ resource.service.name = "template-api" } && status = error && span.http.route = "POST /appointments"

// Step 2: Found error span with attributes:
//   error.message: "DOCTOR_NOT_AVAILABLE"
//   input: { doctorId: "abc-123", date: "2024-03-15" }
//   module: "service"

// Step 3: Root cause — doctor availability not checked before scheduling
// Fix: Add availability validation in CreateAppointment use case

Common Issues

Missing Traces

  • Check OTEL_COLLECTOR_TRACE_URL in Config
  • Verify startTelemetry() called at startup
  • Check if class is resolved via DI container (auto-traced via autoTrace)

Truncated Data

  • method.input.json and method.output.json are truncated at 10000 characters
  • Shows [truncated] suffix when exceeded
  • Check method.result.keys for object structure

Unserializable Data

  • Shows [unserializable] for circular references or special objects
  • Common with streams, Buffers, complex class instances

References

  • packages/api/typescript/src/shared/utils/Tracing.ts - Tracing implementation
  • packages/api/typescript/src/shared/utils/Config.ts - OTEL configuration

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.