This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-v130-outbox-correlation-standard

OpenTelemetry v1.30 Structured Outbox Trace & Baggage Correlation Standard

Establishes mandatory OpenTelemetry Semantic Conventions v1.30 messaging standards for transactional outbox persistence and asynchronous message relay streams. Enforces explicit W3C TraceContext and Baggage serialization into outbox table schemas and ensures trace extraction with span links during relay publishing to eliminate telemetry dead zones.

Prohibited Anti-Pattern: Discarded Trace Carriers and Telemetry Dead Zones in Transactional Outbox Workers

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry v1.30 Structured Outbox Trace & Baggage Correlation Standard - Establishes mandatory OpenTelemetry Semantic Conventions v1.30 messaging standards for transactional outbox persistence and asynchronous message relay streams. Enforces explicit W3C TraceContext and Baggage serialization into outbox table schemas and ensures trace extraction with span links during relay publishing to eliminate telemetry dead zones.
globs: src/infrastructure/outbox/**/*.{ts,js,go,java}, src/domain/events/**/*.{ts,js,go,java}, src/database/entities/**/*.{ts,js,go,java}, src/workers/**/*.{ts,js,go,java}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-v130-outbox-correlation-standard"
---

# OpenTelemetry v1.30 Structured Outbox Trace & Baggage Correlation Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Discarded Trace Carriers and Telemetry Dead Zones in Transactional Outbox Workers

## System Constraints
You are a Principal Software Architect enforcing OpenTelemetry Semantic Conventions v1.30 for Transactional Outbox implementations. You must mandate that every event persisted to an outbox table carries a serialized W3C trace context (traceparent, tracestate) and Baggage. You must enforce that outbox pollers/relay engines extract this context and create standard messaging publish spans adhering to v1.30 semantics (using messaging.operation.type: 'publish' and appropriate span links or parents) instead of generating unlinked root spans.

## Strict Guidelines
- Engineers MUST ALWAYS serialize the active OpenTelemetry context (W3C traceparent, tracestate, and baggage) into an explicit `trace_carrier` JSONB or binary column when inserting records into an outbox table.
- Engineers MUST NOT allow background relay dispatchers or change-data-capture (CDC) tailers to emit message broker events as new trace roots without linking or continuing the originating transactional span context.
- Relay dispatchers MUST extract the serialized carrier using `propagation.extract()` and create a producer span adhering to OTel Semantic Conventions v1.30: `messaging.system`, `messaging.operation.type = 'publish'`, `messaging.destination.name`, and `messaging.message.id`.
- If the relay operation runs in a batch loop, engineers MUST attach the extracted outbox context as a Span Link on the batch publish span if the batch contains events from distinct traces.
- Services MUST preserve OTel Baggage across the transactional outbox persistence boundary to prevent loss of tenant ID, customer ID, or compliance routing headers downstream.
- Components NEVER drop trace carrier propagation during payload serialization, domain event envelope creation, or schema migration steps.

## Bad vs Good Implementations
### Ad-Hoc Unlinked Outbox Publishing vs OTel SemConv v1.30 Structured Context Relay

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The originating HTTP/RPC span context and baggage are not recorded into the database outbox row. When the relay dispatcher processes rows, Kafka messages are produced without headers or linked spans, completely severing trace causality between user transactions and asynchronous event consumers.
```typescript
import { db } from './db';
import { kafkaProducer } from './kafka';

// ANTI-PATTERN: Transaction writes outbox record without trace context;
// Relay creates an unlinked root span, severing distributed causality.
export async function saveOrderEvent(orderId: string, event: object) {
  await db.query(
    'INSERT INTO outbox (aggregate_id, event_type, payload) VALUES ($1, $2, $3)',
    [orderId, 'OrderCreated', JSON.stringify(event)]
  );
}

export async function relayOutboxMessages() {
  const pending = await db.query('SELECT * FROM outbox WHERE status = $1 LIMIT 50', ['PENDING']);
  for (const record of pending.rows) {
    // Telemetry dead zone: No context extraction, produces a new disjoint root trace
    await kafkaProducer.send({
      topic: 'orders.v1',
      messages: [{ key: record.aggregate_id, value: record.payload }],
    });
    await db.query('UPDATE outbox SET status = $1 WHERE id = $2', ['SENT', record.id]);
  }
}
```

#### Production Standard (Correct)
> **Standard**: Context and baggage are injected into a dedicated `trace_carrier` JSON column during the transactional write. The outbox relay extracts this context and creates a compliant v1.30 `publish` span as a direct child or link, injecting refreshed headers into Kafka for seamless end-to-end trace continuity.
```typescript
import { context, propagation, trace, SpanKind } from '@opentelemetry/api';
import { SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_MESSAGING_OPERATION_TYPE, SEMATTRS_MESSAGING_DESTINATION_NAME, SEMATTRS_MESSAGING_MESSAGE_ID } from '@opentelemetry/semantic-conventions';
import { db } from './db';
import { kafkaProducer } from './kafka';

const tracer = trace.getTracer('orders-outbox-relay', '1.30.0');

export async function saveOrderEvent(orderId: string, event: object) {
  // 1. Inject active context (traceparent, tracestate, baggage) into carrier map
  const carrier: Record<string, string> = {};
  propagation.inject(context.active(), carrier);

  await db.query(
    'INSERT INTO outbox (aggregate_id, event_type, payload, trace_carrier) VALUES ($1, $2, $3, $4)',
    [orderId, 'OrderCreated', JSON.stringify(event), JSON.stringify(carrier)]
  );
}

export async function relayOutboxMessages() {
  const pending = await db.query('SELECT * FROM outbox WHERE status = $1 LIMIT 50', ['PENDING']);

  for (const record of pending.rows) {
    const extractedContext = propagation.extract(context.active(), JSON.parse(record.trace_carrier));
    
    // 2. Open span adhering to SemConv v1.30 messaging conventions linked to originating transaction
    await tracer.startActiveSpan(
      `orders.v1 publish`,
      {
        kind: SpanKind.PRODUCER,
        attributes: {
          [SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
          [SEMATTRS_MESSAGING_OPERATION_TYPE]: 'publish',
          [SEMATTRS_MESSAGING_DESTINATION_NAME]: 'orders.v1',
          [SEMATTRS_MESSAGING_MESSAGE_ID]: record.id,
        },
      },
      extractedContext,
      async (span) => {
        try {
          const kafkaHeaders: Record<string, string> = {};
          propagation.inject(context.active(), kafkaHeaders);

          await kafkaProducer.send({
            topic: 'orders.v1',
            messages: [{
              key: record.aggregate_id,
              value: record.payload,
              headers: kafkaHeaders
            }],
          });
          await db.query('UPDATE outbox SET status = $1 WHERE id = $2', ['SENT', record.id]);
        } catch (error) {
          span.recordException(error as Error);
          throw error;
        } finally {
          span.end();
        }
      }
    );
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry v1.30 Structured Outbox Trace & Baggage Correlation Standard

OpenTelemetry v1.30 Structured Outbox Trace & Baggage Correlation Standard defines an industrial-grade behavioral standard for devops engineering. Establishes mandatory OpenTelemetry Semantic Conventions v1.30 messaging standards for transactional outbox persistence and asynchronous message relay streams. Enforces explicit W3C TraceContext and Baggage serialization into outbox table schemas and ensures trace extraction with span links during relay publishing to eliminate telemetry dead zones. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Discarded Trace Carriers and Telemetry Dead Zones in Transactional Outbox Workers Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftDiscarded Trace Carriers and Telemetry Dead Zones in Transactional Outbox WorkersCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS serialize the active OpenTelemetry context (W3C traceparent, tracestate, and baggage) into an explicit `trace_carrier` JSONB or binary column when inserting records into an outbox table.

Engineers MUST ALWAYS serialize the active OpenTelemetry context (W3C traceparent, tracestate, and baggage) into an explicit `trace_carrier` JSONB or binary column when inserting records into an outbox table.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT allow background relay dispatchers or change-data-capture (CDC) tailers to emit message broker events as new trace roots without linking or continuing the originating transactional span context.

Engineers MUST NOT allow background relay dispatchers or change-data-capture (CDC) tailers to emit message broker events as new trace roots without linking or continuing the originating transactional span context.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Relay dispatchers MUST extract the serialized carrier using `propagation.extract()` and create a producer span adhering to OTel Semantic Conventions v1.30

Relay dispatchers MUST extract the serialized carrier using `propagation.extract()` and create a producer span adhering to OTel Semantic Conventions v1.30: `messaging.system`, `messaging.operation.type = 'publish'`, `messaging.destination.name`, and `messaging.message.id`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

If the relay operation runs in a batch loop, engineers MUST attach the extracted outbox context as a Span Link on the batch publish span if the batch contains events from distinct traces.

If the relay operation runs in a batch loop, engineers MUST attach the extracted outbox context as a Span Link on the batch publish span if the batch contains events from distinct traces.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Services MUST preserve OTel Baggage across the transactional outbox persistence boundary to prevent loss of tenant ID, customer ID, or compliance routing headers downstream.

Services MUST preserve OTel Baggage across the transactional outbox persistence boundary to prevent loss of tenant ID, customer ID, or compliance routing headers downstream.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER drop trace carrier propagation during payload serialization, domain event envelope creation, or schema migration steps.

Components NEVER drop trace carrier propagation during payload serialization, domain event envelope creation, or schema migration steps.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is OpenTelemetry v1.30 Structured Outbox Trace & Baggage Correlation Standard critical for AI coding assistants?

Establishes mandatory OpenTelemetry Semantic Conventions v1.30 messaging standards for transactional outbox persistence and asynchronous message relay streams. Enforces explicit W3C TraceContext and Baggage serialization into outbox table schemas and ensures trace extraction with span links during relay publishing to eliminate telemetry dead zones. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Discarded Trace Carriers and Telemetry Dead Zones in Transactional Outbox Workers) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

OpenTelemetry