Skip to content

Observability: Structured audit logs for escrow/NFT mutations with correlation IDs (no PII) #810

@coderabbitai

Description

@coderabbitai

Description

Implement structured audit logging for critical escrow and NFT mutation operations to improve observability, debugging, and compliance tracking across the platform.

Problem Statement

Currently, tracking escrow transactions and NFT mutations across the system is challenging due to:

  • Lack of centralized, structured logging for critical operations
  • Difficulty correlating related operations across different services/components
  • Limited visibility into the lifecycle of escrow and NFT state changes
  • Potential compliance and audit trail gaps

Requirements

Must Have

  • Structured Log Format: Use a consistent JSON format for all audit logs
  • Correlation IDs: Assign unique correlation IDs to track related operations across the system
  • No PII: Ensure no Personally Identifiable Information is logged (use user IDs, wallet addresses in hashed form if needed)
  • Critical Operations Coverage:
    • Escrow creation, funding, release, and cancellation
    • NFT minting, transfers, and state mutations
    • Any state changes affecting escrow or NFT ownership

Log Fields

Each audit log entry should include:

  • timestamp: ISO 8601 format
  • correlationId: Unique identifier for tracking related operations
  • operation: Action being performed (e.g., "escrow.created", "nft.transferred")
  • resourceType: Type of resource ("escrow" or "nft")
  • resourceId: Identifier of the resource being mutated
  • actorId: Hashed/anonymized identifier of the actor
  • status: Operation status ("success", "failure", "pending")
  • metadata: Additional context (amounts, addresses in anonymized form, etc.)
  • errorCode: If applicable, error code for failed operations

Suggested Implementation

1. Create Audit Logger Service

// services/auditLogger.ts
interface AuditLogEntry {
  timestamp: string;
  correlationId: string;
  operation: string;
  resourceType: 'escrow' | 'nft';
  resourceId: string;
  actorId: string;
  status: 'success' | 'failure' | 'pending';
  metadata?: Record<string, any>;
  errorCode?: string;
}

class AuditLogger {
  log(entry: AuditLogEntry): void {
    // Implement structured logging
  }
}

2. Correlation ID Propagation

  • Generate correlation IDs at API entry points
  • Propagate through async context or request headers
  • Include in all downstream operations

3. Integration Points

  • Wrap escrow mutation functions with audit logging
  • Add audit logging to NFT contract interaction handlers
  • Ensure database transaction boundaries align with audit log entries

4. Storage & Retention

  • Consider log aggregation service (e.g., CloudWatch, Datadog, ELK stack)
  • Define retention policies based on compliance requirements
  • Ensure logs are immutable and tamper-proof

Acceptance Criteria

  • Audit logger service/utility is implemented
  • All escrow mutations are logged with correlation IDs
  • All NFT mutations are logged with correlation IDs
  • No PII is present in any audit logs
  • Logs are in structured JSON format
  • Documentation updated with logging schema and examples
  • Unit tests for audit logger
  • Integration tests verify logs are created for critical operations

Additional Context

This is a foundational observability improvement that will:

  • Enable better debugging of production issues
  • Provide audit trails for compliance
  • Support future monitoring and alerting features
  • Improve incident response capabilities

Related Issues

Help Wanted

Looking for contributors who can help with:

  • Designing the structured log schema
  • Implementing the audit logger service
  • Integrating logging into existing escrow and NFT mutation flows
  • Setting up log aggregation and monitoring infrastructure
  • Writing comprehensive tests

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions