Course contentsShow
← System Design
Lesson 1233 of 1,91931. Observability: TracingFree lesson

Span Tags and Attributes

Adding metadata to spans using tags for filtering and searching, including service name, HTTP method, and error flags.

Span Tags and Attributes

What You'll Learn

You'll learn how to enrich spans with metadata tags and attributes that make traces searchable, filterable, and vastly more useful for debugging distributed systems.

The Core Idea

Think of a span as a shipping package moving through your distributed system. Tags and attributes are like stickers you place on that package: "Priority Mail," "Fragile," "Contains Electronics." These labels don't change what's inside, but they make it incredibly easy to find, sort, and understand packages later.

In distributed tracing, tags (also called attributes) are key-value pairs attached to spans. They capture important context about the operation: which service performed it, what HTTP method was used, whether it succeeded or failed, user IDs, database query types—anything that helps you understand and filter traces later.

Common Span Tags

When you instrument your services, you typically add tags like:

  • service.name: Which microservice created this span (e.g., "payment-service")
  • http.method: The HTTP verb used (GET, POST, PUT, etc.)
  • http.status_code: Response status (200, 404, 500)
  • error: Boolean flag marking failed operations (true/false)
  • db.statement: The actual SQL query executed
  • user.id: Who triggered this request

These tags transform raw traces into powerful diagnostic tools. Instead of manually sifting through thousands of spans, you can query: "Show me all failed payment operations" (error=true AND service.name=payment-service) or "Find slow database queries" (db.statement exists AND duration > 1s).

Why This Matters

Without tags, traces are just timing data. With tags, they become searchable stories about what happened, where, why, and to whom. Tags enable your tracing backend to index, filter, and aggregate spans—turning observability from "what's slow?" into "why did user 12345's checkout fail?"

Key Takeaway:
Span tags and attributes add searchable metadata to traces, enabling powerful filtering by service name, HTTP method, error status, and other contextual dimensions that transform raw timing data into actionable insights.