Skip to content

Concept

In tracing (especially distributed tracing, such as in OpenTelemetry), the terms resource, scope, and span each represent specific concepts in how trace data is structured and organized:

🧱 Span — the basic unit of trace

  • A span represents a single operation within a trace.
  • It's the core unit in a trace and has:
    • A name (e.g., "HTTP GET /api/users")
    • A start and end timestamp
    • Attributes (key-value pairs)
    • Parent-child relationships (to form the hierarchy of a trace)
    • Optionally, events and status

📌 Example: A span could represent a function call, an HTTP request, or a DB query.

json
"span" : {
    "traceId" : "1cb33ab03e6864be0bde9716a49be89b",
    "spanId" : "78817076c9cd460b",
    "traceState" : "",
    "parentSpanId" : "6472d7eccbd5f820",
    "name" : "/hello",
    "kind" : "Server",
    "startTimeUnixNano" : 1747908105861,
    "endTimeUnixNano" : 1747908106545,
    "attributes" : {
        "baggage key:client" : "cli",
        "baggage key:method" : "repl",
        "http.flavor" : "1.1",
        "http.host" : "demo-server:7080",
        "http.method" : "GET",
        "http.scheme" : "http",
        "http.server_name" : "/hello",
        "http.status_code" : 200,
        "http.target" : "/hello",
        "http.user_agent" : "Go-http-client/1.1",
        "http.wrote_bytes" : 11,
        "net.host.name" : "demo-server",
        "net.host.port" : 7080,
        "net.peer.ip" : "192.168.97.6",
        "net.peer.port" : 34214,
        "net.transport" : "ip_tcp",
        "server-attribute" : "foo"
    },
}

🧭 Scope (a.k.a. Instrumentation Scope)

  • A scope groups spans that are generated by the same instrumentation library.
  • It helps identify which library (and version) created a span.
  • Contains metadata like:
    • name (e.g., "io.opentelemetry.http")
    • version (e.g., "1.0.1")

📌 Example: All HTTP client spans created by opentelemetry-go v1.5.0 share the same scope.

json
"scope" : {
    "name" : "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
    "version" : "semver:0.37.0",
    "attributes" : { },
    "droppedAttributesCount" : 0
},

🧩 Resource

  • A resource describes the entity producing telemetry data.
  • It provides context about the service (or host) — like service name, host, environment, etc.
  • Shared by all spans from the same producer.

🛠️ Common resource attributes:

  • service.name (e.g., "user-service")
  • host.name (e.g., "prod-server-123")
  • cloud.provider, os.type, k8s.pod.name, etc.

📌 Example: A Kubernetes pod generating spans will have a resource with details about the pod, namespace, and node.

json
"resource" : {
    "attributes" : {
        "host.name" : "183ac322db40",
        "process.command_args" : [
            "/app/main"
        ],
        "process.executable.name" : "main",
        "process.executable.path" : "/app/main",
        "process.owner" : "root",
        "process.pid" : 1,
        "process.runtime.description" : "go version go1.18.10 linux/arm64",
        "process.runtime.name" : "go",
        "process.runtime.version" : "go1.18.10",
        "service.name" : "demo-server",
        "telemetry.sdk.language" : "go",
        "telemetry.sdk.name" : "opentelemetry",
        "telemetry.sdk.version" : "1.11.2"
    },
    "droppedAttributesCount" : 0
},

🧬 Trace Hierarchy Example:

bash
Resource: { service.name="payment-service" }
 └── Scope: { name="otel-instrumentation-http", version="1.1.0" }
      └── Span: "HTTP GET /pay"
      └── Span: "Call to payment gateway"
 └── Scope: { name="otel-instrumentation-db", version="0.31.0" }
      └── Span: "SELECT * FROM transactions"