logging-tracing-capture

Rules and examples for capturing traces from AWS Lambda applications with AWS X-Ray, a service that shows how requests travel through connected services. They cover AWS SDK calls, HTTP requests, and trace details.

In plain words
What is it for?
Use them to trace DynamoDB and other AWS SDK calls, record external API requests, configure X-Ray in AWS CDK deployments, and inspect service maps.
Why use it?
They help developers follow a request across services and distinguish searchable annotations from extra diagnostic metadata.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/goranerhartic/cursor-development-rules/logging-tracing-capture
Clone the repo
git clone --depth 1 https://github.com/GoranErhartic/cursor-development-rules

Made for: Cursor.

Per session 23 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,708 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00023 $0.01708
Opus 5 $0.00012 $0.00854
Sonnet 5 $0.00005 $0.00342
Haiku 4.5 $0.00002 $0.00171

Measured 3d ago against content hash 60cc776b7c6b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

logging-tracing-capture scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

const response = await fetch(options.url, {
.cursor/rules/languages/aws-lambda/logging-tracing-capture.mdc · 249 lines

How it starts

The opening of the file, as written. The whole thing — 249 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Lambda X-Ray Capture & CDK

Tracing AWS SDK Clients

// src/shared/clients/dynamodb.ts

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import { tracer } from "@/shared/tracer";

let docClient: DynamoDBDocumentClient | undefined;

export function getDynamoDBClient(): DynamoDBDocumentClient {
  if (!docClient) {
    const client = new DynamoDBClient({});
    
    // Capture AWS SDK calls in X-Ray
    tracer.captureAWSv3Client(client);
    
    docClient = DynamoDBDocumentClient.from(client);
  }

  return docClient;
}

Tracing HTTP Clients (External APIs)

// src/shared/clients/http-client.ts

import { tracer } from "@/shared/tracer";
import { getRequestContext } from "@/shared/observability/request-context";
import { logger } from "@/shared/logger";

interface HttpRequestOptions {
  method: "GET" | "POST" | "PUT" | "DELETE";
  url: string;
  headers?: Record<string, string>;
  body?: unknown;
  timeout?: number;
}

export async function tracedFetch<T>(options: HttpRequestOptions): Promise<T> {
  const context = getRequestContext();
  const segment = tracer.getSegment();
  const subsegment = segment?.addNewSubsegment(`HTTP ${options.method} ${new URL(options.url).hostname}`);

  const startTime = Date.now();

  try {
    // Add trace context to outgoing request
    const headers: Record<string, string> = {
      ...options.headers,
      "X-Correlation-Id": context?.correlationId ?? "",
    };

    // Propagate X-Ray trace header for downstream tracing
    if (process.env._X_AMZN_TRACE_ID) {
      headers["X-Amzn-Trace-Id"] = process.env._X_AMZN_TRACE_ID;
    }

    subsegment?.addAnnotation("correlationId", context?.correlationId ?? "unknown");
    subsegment?.addAnnotation("url", options.url);
    subsegment?.addAnnotation("method", options.method);
    subsegment?.addMetadata("requestHeaders", headers);

    const response = await fetch(options.url, {
      method: options.method,
      headers,
      body: options.body ? JSON.stringify(options.body) : undefined,
      signal: options.timeout ? AbortSignal.timeout(options.timeout) : undefined,
    });

    const duration = Date.now() - startTime;

    subsegment?.addAnnotation("statusCode", response.status);
    subsegment?.addMetadata("responseHeaders", Object.fromEntries(response.headers));

    logger.info({
      correlationId: context?.correlationId,
      url: options.url,
      method: options.method,
      statusCode: response.status,
      durationMs: duration,
    }, "External HTTP request completed");

    if (!response.ok) {
      const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
      subsegment?.addError(error);
      throw error;
    }

    return response.json() as Promise<T>;
  } catch (error) {
    subsegment?.addError(error as Error);
    logger.error({
      correlationId: context?.correlationId,
      url: options.url,
      err: error,
    }, "External HTTP request failed");
    throw error;
  } finally {
    subsegment?.close();
  }
}

Read the full file on GitHub · 249 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 249 lines · 23 tokens per session scan A 60cc776b7c6b

Subscribe to this mod's changes

logging-tracing-capture is a cursor rule published in the GitHub repository GoranErhartic/cursor-development-rules (19 stars, last pushed 6mo ago), licensed MIT. It adds 23 tokens to every session and 1,708 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other cursor rules, from other repositories