This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-log-bridge-dynamic-checkpointing-guardrail

OpenTelemetry Log Bridge Native Dynamic Checkpointing and Atomic Offset Commit Guardrail

Enforces synchronous, durable offset checkpointing and atomic write-ahead log (WAL) synchronization for OpenTelemetry Log Bridge pipelines. Guarantees zero-data-loss harvesting and deterministic at-least-once with deduplication idempotency under SIGTERM, rapid Kubernetes pod evictions, and ephemeral volume detach events.

Prohibited Anti-Pattern: Asynchronous fire-and-forget log batching and local volatile offset storage causing log drops and duplicate re-ingestion during pod preemption

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Log Bridge Native Dynamic Checkpointing and Atomic Offset Commit Guardrail - Enforces synchronous, durable offset checkpointing and atomic write-ahead log (WAL) synchronization for OpenTelemetry Log Bridge pipelines. Guarantees zero-data-loss harvesting and deterministic at-least-once with deduplication idempotency under SIGTERM, rapid Kubernetes pod evictions, and ephemeral volume detach events.
globs: src/telemetry/**/*.ts, src/logging/**/*.ts, src/infrastructure/k8s/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-log-bridge-dynamic-checkpointing-guardrail"
---

# OpenTelemetry Log Bridge Native Dynamic Checkpointing and Atomic Offset Commit Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Asynchronous fire-and-forget log batching and local volatile offset storage causing log drops and duplicate re-ingestion during pod preemption

## System Constraints
You are a Principal Software Architect enforcing enterprise log harvesting resilience. You must guarantee that any log ingestion pipeline using OpenTelemetry Log Bridge bridges or file-tailing agents binds pipeline dispatch directly to atomic offset checkpointing with synchronous durable flushes. You MUST reject asynchronous non-durable offset updates, unhandled termination lifecycle hooks, and checkpoint-agnostic batch processing.

## Strict Guidelines
- Engineers MUST ALWAYS bind OpenTelemetry Log Record export confirmation directly to atomic checkpoint commits before advancing the reader offset.
- Engineers MUST ALWAYS implement durable checkpoint persistence using fsync or an external state lease coordinator rather than volatile memory or uncommitted disk caches.
- Code SHOULD track file identity using both device and inode metadata (`dev:inode`) alongside byte offset to guard against inode recycling during volume detach/remount cycles.
- Services MUST intercept `SIGTERM` and `SIGINT` signals, synchronously drain in-flight OpenTelemetry log batches, commit the final offset barrier, and close file handles before exiting.
- Components NEVER advance local log cursor pointers when downstream OpenTelemetry LogExporter invocations fail or time out.

## Bad vs Good Implementations
### Asynchronous Unchecked Offset Mutation vs. Two-Phase Atomic Checkpointed OTel Log Bridge Harvester

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The harvester updates its internal offset immediately in volatile memory without waiting for the OpenTelemetry Log Bridge exporter to succeed. If Kubernetes terminates the pod or detaches the volume mid-stream, pending records are dropped, and upon reschedule, the offset resets to 0 (or stale state), resulting in massive duplicate log storms and unrecoverable silent data loss.
```typescript
import { logs } from '@opentelemetry/api-logs';
import * as fs from 'fs';

export class VulnerableLogHarvester {
  private offset = 0;
  private readonly logger = logs.getLogger('harvester');

  public async harvest(filePath: string): Promise<void> {
    const stream = fs.createReadStream(filePath, { start: this.offset });
    stream.on('data', (chunk: Buffer) => {
      // ANTI-PATTERN: Advance offset immediately in memory
      this.offset += chunk.length;
      
      // Asynchronous non-blocking emit; pod killed here loses un-exported data
      // or re-reads on restart causing unbounded duplicates
      this.logger.emit({
        body: chunk.toString('utf-8'),
        severityNumber: 9,
      });
    });
  }
}
```

#### Production Standard (Correct)
> **Standard**: Log emission is synchronized with an atomic, fsync-flushed file checkpoint containing device and inode metadata. Inode tracking defends against volume remount mismatches, and atomic file renaming guarantees consistent offset recovery with zero log loss and deterministic restart boundaries across pod rescheduling events.
```typescript
import { logs, SeverityNumber } from '@opentelemetry/api-logs';
import * as fs from 'fs/promises';
import * as path from 'path';

interface CheckpointState {
  dev: number;
  inode: number;
  offset: number;
  generationEpochMs: number;
}

export class ResilientLogBridgeHarvester {
  private readonly logger = logs.getLogger('resilient-harvester');
  private isDraining = false;

  constructor(private readonly checkpointPath: string) {}

  public async processBatch(
    fileHandle: fs.FileHandle,
    stat: { dev: number; ino: number },
    currentOffset: number,
    buffer: Buffer
  ): Promise<number> {
    if (this.isDraining) {
      throw new Error('Pipeline is draining: rejecting new batch');
    }

    const logBody = buffer.toString('utf-8');
    const nextOffset = currentOffset + buffer.length;

    // 1. Synchronously emit to OpenTelemetry Log Bridge
    this.logger.emit({
      body: logBody,
      severityNumber: SeverityNumber.INFO,
      timestamp: Date.now(),
      observedTimestamp: Date.now(),
    });

    // 2. Atomically persist checkpoint before advancing file pointer
    const state: CheckpointState = {
      dev: stat.dev,
      inode: stat.ino,
      offset: nextOffset,
      generationEpochMs: Date.now(),
    };

    const tempCheckpoint = `${this.checkpointPath}.tmp.${Date.now()}`;
    await fs.writeFile(tempCheckpoint, JSON.stringify(state), { flush: true });
    await fs.rename(tempCheckpoint, this.checkpointPath);

    return nextOffset;
  }

  public prepareShutdown(): void {
    this.isDraining = true;
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

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

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry Log Bridge Native Dynamic Checkpointing and Atomic Offset Commit Guardrail

OpenTelemetry Log Bridge Native Dynamic Checkpointing and Atomic Offset Commit Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces synchronous, durable offset checkpointing and atomic write-ahead log (WAL) synchronization for OpenTelemetry Log Bridge pipelines. Guarantees zero-data-loss harvesting and deterministic at-least-once with deduplication idempotency under SIGTERM, rapid Kubernetes pod evictions, and ephemeral volume detach events. 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: Asynchronous fire-and-forget log batching and local volatile offset storage causing log drops and duplicate re-ingestion during pod preemption 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 DriftAsynchronous fire-and-forget log batching and local volatile offset storage causing log drops and duplicate re-ingestion during pod preemptionCritical
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 bind OpenTelemetry Log Record export confirmation directly to atomic checkpoint commits before advancing the reader offset.

Engineers MUST ALWAYS bind OpenTelemetry Log Record export confirmation directly to atomic checkpoint commits before advancing the reader offset.

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 ALWAYS implement durable checkpoint persistence using fsync or an external state lease coordinator rather than volatile memory or uncommitted disk caches.

Engineers MUST ALWAYS implement durable checkpoint persistence using fsync or an external state lease coordinator rather than volatile memory or uncommitted disk caches.

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

Code SHOULD track file identity using both device and inode metadata (`dev

Code SHOULD track file identity using both device and inode metadata (`dev:inode`) alongside byte offset to guard against inode recycling during volume detach/remount cycles.

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

Services MUST intercept `SIGTERM` and `SIGINT` signals, synchronously drain in-flight OpenTelemetry log batches, commit the final offset barrier, and close file handles before exiting.

Services MUST intercept `SIGTERM` and `SIGINT` signals, synchronously drain in-flight OpenTelemetry log batches, commit the final offset barrier, and close file handles before exiting.

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

Components NEVER advance local log cursor pointers when downstream OpenTelemetry LogExporter invocations fail or time out.

Components NEVER advance local log cursor pointers when downstream OpenTelemetry LogExporter invocations fail or time out.

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 Log Bridge Native Dynamic Checkpointing and Atomic Offset Commit Guardrail critical for AI coding assistants?

Enforces synchronous, durable offset checkpointing and atomic write-ahead log (WAL) synchronization for OpenTelemetry Log Bridge pipelines. Guarantees zero-data-loss harvesting and deterministic at-least-once with deduplication idempotency under SIGTERM, rapid Kubernetes pod evictions, and ephemeral volume detach events. 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 (Asynchronous fire-and-forget log batching and local volatile offset storage causing log drops and duplicate re-ingestion during pod preemption) 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