Distributed Tracing and Context Propagation

    1

    Designs distributed tracing architectures: OpenTelemetry spans, W3C trace context, tail sampling, and trace storage.

    $5

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseOpenClawOpenClaw+21 more

    Distributed Tracing and Context Propagation

    Example session with this skill installed

    Design distributed tracing, W3C context propagation, and sampling architecture contracts for our Core Checkout & Payment Flow.

    • Subject: checkout-payment-pipeline v2.0 (run-id: checkout-traces-001) spanning 8 microservices across HTTP and Kafka event boundaries.
    • Deciders: Lead SRE Telemetry Architect (Marcus Vance) and Core Platform Lead (Elena Rostova).
    • Scale: Peak 3,800 checkouts/sec; aggregate 45,000 spans/sec; OpenTelemetry SDKs exporting to OTel Collector and Grafana Tempo.
    • Tension: Squads proposed 100% head-based sampling with custom headers (X-B3-TraceId) and embedding card tokens in span attributes; Marcus Vance strictly forbids 100% sampling, non-standard headers, and card tokens, citing incident INC-4418 where tracing storage costs exploded by $85,000/month while PCI tokens leaked into telemetry. He mandates W3C Trace Context (traceparent), tail-based sampling (100% of errors and p95+ latency outliers, 2% nominal), strict attribute allowlists, and a 14-day Tempo storage retention budget.

    Write the distributed tracing spec under docs/.

    • Read your context and instructions
    • Compiled the distributed tracing
    • Generated the UI component

    Wrote docs/architecture/tasks/checkout-traces-001/traces-design/distributed-tracing-spec.md. Complete distributed tracing contract establishing W3C context propagation, tail-based sampling, span attribute allowlists, and Grafana Tempo storage retention tiers.

    ---
    skill: traces-design
    ---
    
    # Distributed Tracing & Context Contract: Core Checkout & Payment Flow [TRACE-CHK-001]
    
    ## Summary
    
    This specification establishes the distributed tracing architecture, span schema conventions, and context propagation contract for the `checkout-payment-pipeline v2.0` under run ID `checkout-traces-001`. It governs 8 distributed microservices spanning synchronous HTTP and asynchronous Kafka messaging across 3,800 peak checkouts/second (generating 45,000 spans/second). It decisively resolves the catastrophic storage cost inflation and PCI-DSS compliance violations demonstrated in incident INC-4418 (where 100% un-sampled tracing drove an $85,000/month storage overrun while card tokens leaked into span tags). The contract enforces standard W3C Trace Context headers (`traceparent`), implements OpenTelemetry Collector tail-based sampling (retaining 100% of error traces and p95+ latency outliers while sampling nominal success traces at 2%), enforces strict span attribute allowlists, and defines a 14-day Grafana Tempo object storage tier.
    
    ## Detailed Description
    
    Operating distributed polyglot microservices without unified context propagation breaks causal transaction visibility. Using legacy, divergent headers (`X-B3-TraceId`, `X-Cloud-Trace-Context`) fragments traces at service boundaries. Furthermore, naive 100% sampling at 45,000 spans/sec generates over 18 TB of uncompressed trace data daily, 98% of which represents repetitive nominal executions.
    
    

    Client Checkout Request (3,800 TPS via HTTPS)
    │
    ▼ (Injects W3C traceparent: 00-4bf92f35...-00f067a...-01)
    [ Ingress Gateway: checkout-web ]
    ├── Root Span: POST /api/v1/checkout
    └── Context Propagation: Injects traceparent into Kafka Event Record Header
    │
    ▼
    [ Apache Kafka Topic: orders.pending.v1 ]
    │
    ▼ (Extracts traceparent from Kafka Record Header)
    [ Backend Consumer: payment-service ]
    └── Child Span: payment.process (Links to Parent Trace Context)
    │
    ▼ (Export via OTLP gRPC: 45,000 spans/sec)
    [ OpenTelemetry Collector Tier: Tail-Based Sampler ]
    ├── 1. Error Sampler: HTTP status >= 500 OR Exception ──► 100% Retained
    ├── 2. Latency Outlier Sampler: Duration > 150 ms ───────► 100% Retained
    └── 3. Nominal Success Sampler: Standard 200 OK ────────► 2% Probabilistic
    │
    ▼ (Retained Traces: ~2,400 spans/sec, 95% Reduction)
    [ Distributed Trace Backend: Grafana Tempo (S3 Object Storage, 14-Day TTL) ]

    
    ### Criteria and weights
    
    | Criterion | Why it matters here | Weight | Source of the weight |
    |---|---|---|---|
    | Complete End-to-End Context Continuity | Context must traverse HTTP and Kafka boundaries without creating orphan root spans. | 0.35 | Marcus Vance (Lead Telemetry Architect) |
    | Telemetry Cost Containment (Tail Sampling) | 100% trace capture incurs unsustainable storage costs ($85,000/mo overrun in INC-4418). | 0.30 | Cloud FinOps Policy |
    | Zero PCI/PII Data in Span Attributes | Customer credit card numbers or tokens must never be persisted in trace databases. | 0.20 | Elena Rostova (Core Platform Lead) |
    | Latency Overhead Budget (p99 <= 1.5 ms) | Trace span creation and header serialization must not degrade transaction performance. | 0.15 | Payment Transaction SLA |
    
    
    ### Comparison
    
    | Tracing Strategy Candidate | Context Standard | Sampling Model | Storage Volume | Evaluation |
    |---|---|---|---|---|
    | Option A: 100% Head-Based Sampling (Legacy) | Legacy B3 headers | 100% at ingress | 18 TB / day ($85k/mo) | Rejected: Caused INC-4418 cost explosion; leaked PCI tokens. |
    | Option B: 5% Probabilistic Head Sampling | W3C Trace Context | 5% random at root | 0.9 TB / day | Rejected: Drops 95% of intermittent production bugs and rare timeouts. |
    | Option C: Tail-Based Intelligent Sampling (Chosen) | W3C `traceparent` | Tail-sampled: 100% errors + 2% nominal | 0.85 TB / day | Selected: 100% error capture, 95% cost reduction, unified traces. |
    
    
    ### Result
    
    Option C is selected. W3C Trace Context unifies propagation across protocols; OpenTelemetry Collector tail-sampling preserves critical failures while discarding redundant success traces.
    
    ---
    
    ### Required Mechanisms
    
    #### 1. W3C Context Propagation Standard [MC-CP-01]
    - **Wire Format**: Strict adherence to W3C Trace Context Level 1:
      - Header: `traceparent: {version}-{trace_id}-{parent_id}-{trace_flags}`
      - Example: `traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01`
    - **Protocol Injection**:
      - *HTTP*: Propagated as lowercase HTTP request header `traceparent`.
      - *Kafka*: Injected into Kafka record byte header array `traceparent`.
      - All proprietary B3 and Jaeger headers are sanitized and dropped at ingress.
    
    #### 2. OpenTelemetry Tail-Based Sampling Rules [MC-TS-01]
    Enforced within the OpenTelemetry Collector `tail_sampling` processor:
    ```yaml
    processors:
      tail_sampling:
        decision_wait: 10s
        num_traces: 50000
        expected_new_traces_per_sec: 4000
        policies:
          # Rule 1: Always retain errors and uncaught exceptions
          - name: drop-no-errors
            type: status_code
            status_code: { status_codes: [ERROR] }
          # Rule 2: Always retain high-latency outliers
          - name: latency-outliers
            type: numeric_attribute
            numeric_attribute:
              key: http.status_code
              value_condition: { greater_than_or_equal: 500 }
          - name: duration-outliers
            type: latency
            latency: { threshold_ms: 150 }
          # Rule 3: Sample nominal successful traces
          - name: nominal-sample
            type: probabilistic
            probabilistic: { sampling_percentage: 2.0 }
    
    3. Span Attribute Governance & Cardinality Allowlist [MC-AG-01]
    • Standardized Attributes:
      • service.name, service.version, deployment.environment
      • http.method, http.status_code, http.route (e.g. /v1/checkout/{order_id})
      • messaging.system: "kafka", messaging.destination: "orders.pending.v1"
    • Strict Attribute Blocklist:
      • user_id, customer_email, phone_number
      • credit_card, pan, cvv, auth_token, authorization
      • CI pipeline AST linter span-attribute-check rejects pull requests attempting to record unapproved dynamic attributes.
    4. Trace Storage & Lifecycle Retention [MC-TR-01]
    • Storage Engine: Grafana Tempo backed by AWS S3.
    • Retention: S3 Lifecycle rule automatically expires and purges trace block parquet files after 14 days.

    Invariants and Contracts

    Mandatory W3C Traceparent Invariant [INV-TRC-01]
      All inter-service RPC calls and message queue publishes must propagate the `traceparent` header.
      Emitting asynchronous events without context propagation violates platform observability rules.
    
    Zero Sensitive Data in Attributes [INV-TRC-02]
      Trace spans must never contain credit card numbers, authorization tokens, or customer PII.
      Span serialization filters must sanitize dynamic attributes before OTLP export.
    
    One Hundred Percent Error Capture Guarantee [INV-TRC-03]
      The telemetry collection pipeline must retain 100% of traces that result in HTTP 5xx errors
      or uncaught exceptions. Downsampling error traces is strictly prohibited.
    

    Explicit Unknowns

    • OpenTelemetry Collector memory overhead when buffering 50,000 in-flight traces during sudden 10-second upstream timeouts (G-1).
    • Cross-region data transfer egress charges when exporting spans from us-west-2 to central Tempo in us-east-1 (G-2).

    Traceability

    ClaimClassificationSourceFreshness
    Peak 3,800 checkouts/sec, 45,000 spans/secprovidedTraffic intakeCurrent
    8 microservices across HTTP & KafkaprovidedScope intakeCurrent
    Incident INC-4418 $85k/mo cost overrunprovidedPost-mortem evidenceHistorical
    W3C Trace Context standardizationdecidedMarcus Vance (Lead Telemetry Architect)2026-09-15
    Tail sampling (100% errors / 2% nominal)decidedArchitectural invariant INV-TRC-032026-09-15
    14-day Tempo storage retentiondecidedTelemetry Platform Policy2026-09-15

    Verification

    No validator was supplied, so no command was run.

    Reviewer self-check against distributed tracing standards:

    • Context Continuity: PASS. W3C traceparent covers both synchronous HTTP and Kafka event headers.
    • Cost Protection: PASS. Tail sampling achieves 95% volume reduction while keeping 100% of errors.
    • Security Posture: PASS. Attribute allowlist strictly blocks card tokens and PII.
    • Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to rule_markdown.md.

    Open Decisions

    • DEC-TRC-01: Elena Rostova to determine whether OpenTelemetry Baggage propagation should be enabled for tenant subscription tier tags across internal hops (Owner: Elena Rostova).

    Next steps

    1. Marcus Vance deploys OpenTelemetry Collector DaemonSet with tail-sampling configuration in staging.
    2. Platform team embeds OpenTelemetry W3C context interceptors in shared Kafka client libraries.
    3. Conduct staging resilience test generating 500 synthetic HTTP 500 errors to verify 100% trace retention in Tempo.

    distributed-tracing-and-context-propagat.tsx

    TSX · React component

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    What you get

    Standardize W3C traceparent headers across microservice boundariesDefine span attribute schemas and PII masking rules for OTelDesign tail-based sampling strategies for high-latency requestsMap asynchronous message queue causality into span relationships

    About this skill

    What it does

    This skill maps accepted logical operations and communication boundaries into trace context, span structure, causality, sampling and delivery evidence. It defines portable trace semantics without selecting an SDK, collector or backend.

    Use it when

    Use when a distributed logical operation needs exact trace/context/span contracts across known boundaries for known operator questions.

    For example: “Our flight booking engine loses trace context whenever the checkout service publishes an event to Kafka, so engineers see isolated 1-span traces in Jaeger and cannot debug 10-second payment processing delays.”

    What you get

    • Distributed Tracing Spec
    • OTel Instrumentation Guide
    • Sampling Strategy Doc

    Written as Markdown to <your output folder>/architecture/tasks/<run-id>/traces-design/.

    What it will not do

    Do not use for log/metric/SLO/alert design, tracing backend/collector deployment, implementation or troubleshooting.

    How it works

    1. Check tracing contract is required.
    2. Define logical operations and span hierarchy boundaries.
    3. Establish context carrier injection and extraction rules.
    4. Formulate span attribute schemas and privacy masking.
    5. Configure tail-based and head-based sampling strategies.
    6. Write the distributed tracing spec under <output_root>/architecture/tasks/{run-id}/traces-design/distributed-tracing-spec.md.

    What's in the package

    Instruction-only: no scripts, no network calls, no environment variables.

    • LICENSE.txt
    • SKILL.md
    • agents/openai.yaml
    • assets/output-template-task.md
    • references/domain-rules.md
    • references/operating-rules.md
    • references/output-contract.md

    How to install

    Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.

    ~30 seconds
    1. 1

      Download the ZIP

      Free skills download straight away. Paid skills unlock right after purchase.

    2. 2

      Unzip into your skills folder

      Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.

    3. 3

      Ask your agent to use it

      Restart the agent if it was already running. It picks the skill up automatically - no config needed.

    Skills folder by agent

    Click the path to copy it. Create the folder if it does not exist yet.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean 12 days ago

    • Passed all security checks, Safe to install

    Listed12 days ago

    What's inside

    Frequently Asked Questions