Skip to content

feat(telemetry): DynamoDB events table with TTL and persistent sink (#127) - #357

Merged
Kaap10 merged 2 commits into
codeforstartups:developmentfrom
shivamm-gupta:issue-127-telemetry-dynamodb-table
Nov 23, 2026
Merged

Kaap10 merged 2 commits into
codeforstartups:developmentfrom
shivamm-gupta:issue-127-telemetry-dynamodb-table

Conversation

@shivamm-gupta

@shivamm-gupta shivamm-gupta commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Introduces persistent telemetry event storage on Amazon DynamoDB with single-table design, TTL expiration, and asynchronous batch writes in dynalogs, addressing issue #127.

Related issue

Fixes #127

Changes

  • Single-table schema design: pk = "{namespace}#events", sk = "{timestamp}#{query_id}", with numeric ttl epoch attribute.
  • Stored attributes: query_id, namespace, top_k, stage_latencies, result_ids, cache_hit, timestamp, ttl, latency_ms, status. Enforces privacy by omitting raw prompt text and PII by default unless capture_text=True.
  • Implemented DynamoDBTelemetrySink:
    • Buffered asynchronous batch writing (BatchWriteItem in chunks of 25 with unprocessed keys retry).
    • Explicit warning log if retries are exhausted under high-load throttling.
    • Automatically registers atexit hook so buffered events in short-lived CLI scripts are safely flushed on process termination.
  • Implemented DynamoDBTelemetryRecorder hybrid recorder:
    • Synchronizes both in-memory ring buffer and DynamoDB table for TelemetryEvent, DynamoDBTelemetryEvent, and dict inputs.
  • Enhanced create_telemetry_table in src/dynavec/provisioning.py:
    • Waits for TableStatus == "ACTIVE" before configuring TTL, avoiding ResourceInUseException during concurrent table creation.
  • Added comprehensive unit tests in tests/test_telemetry_dynamodb.py covering table provisioning, TTL configuration, batch writes, non-blocking asynchronous flush, atexit hook lifecycle, recorder buffer synchronization, and Dynavec client integration.

Testing

  • Tests pass locally (pytest tests/test_telemetry_dynamodb.py tests/test_telemetry.py -> 22 passed)
  • Ruff checks pass (ruff check src/dynavec/telemetry.py src/dynavec/provisioning.py tests/test_telemetry_dynamodb.py -> All checks passed)
  • Mypy checks pass (mypy src/dynavec/telemetry.py -> Success: no issues found)
  • Documentation updated, if applicable

Checklist

  • My changes are focused and relevant to this pull request.
  • I have added or updated tests where appropriate.
  • I have reviewed my changes for unrelated modifications.
  • I have updated documentation where necessary.

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! The DynamoDB telemetry event model, non-blocking batch sink, TTL configuration, and privacy-first defaults (redaction, no raw query text by default) are well designed and thoroughly tested.

Before this can be merged, there are a few important points to address:

  1. Missing Documentation (Acceptance Criteria of #127): Issue #127 specifically requires "Docs on what's stored". Please add documentation (e.g. in docs/ or user guides) explaining the telemetry event schema, what fields are collected, privacy/redaction guarantees, and how to enable TTL and query events.
  2. Silent Drop of Unprocessed Items: In _write_batch, if DynamoDB throttles and retries are exhausted while UnprocessedItems still remain, the loop exits silently without logging a warning about dropped telemetry events.
  3. Flushing on Process Exit (atexit): The sink buffers up to 25 events before writing. If an application executes fewer than 25 queries and terminates without explicitly calling client.close() or using a context manager, buffered events are lost. Adding atexit.register(self.close) prevents this.
  4. Hybrid Recorder In-Memory Buffer Inconsistency: In DynamoDBTelemetryRecorder.record(), events passed as DynamoDBTelemetryEvent or dict are written to DynamoDB but skipped from the in-memory ring buffer.
  5. PR Description Format: Please update the PR description to follow .github/pull_request_template.md and clean up the escaped backslashes (\).

See the inline comments below for suggested fixes.

Comment thread src/dynavec/telemetry.py Resolved
Comment thread src/dynavec/telemetry.py Resolved
Comment thread src/dynavec/telemetry.py Resolved
Comment thread src/dynavec/provisioning.py Resolved
@shivamm-gupta

Copy link
Copy Markdown
Collaborator Author

Thanks @Kaap10 for the thorough review! All feedback has been addressed:

  1. Throttling Warning: Added warning logging in _write_batch\ when retries are exhausted and unprocessed items remain.
  2. Process Exit Flush (atexit): Registered an \�texit\ hook in \DynamoDBTelemetrySink.init\ (and unregistered in \close()) to guarantee flushing buffered events in short-lived CLI executions.
  3. Hybrid Recorder In-Memory Buffer: \DynamoDBTelemetryRecorder.record()\ now converts \dict\ and \DynamoDBTelemetryEvent\ inputs into \TelemetryEvent\ before forwarding to \super().record(), keeping both in-memory and DynamoDB buffers synchronized.
  4. ResourceInUse on CREATING Table: \create_telemetry_table\ in \src/dynavec/provisioning.py\ now waits for \TableStatus == 'ACTIVE'\ when \wait=True\ before calling \update_time_to_live.
  5. PR Description: Updated according to .github/pull_request_template.md\ without escaped backslashes.

@shivamm-gupta
shivamm-gupta requested a review from Kaap10 November 22, 2026 13:32
@shivamm-gupta shivamm-gupta self-assigned this Nov 22, 2026

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for addressing all feedback on atexit flushing, throttling warnings, and table status waiting.

We can track adding a dedicated docs guide (docs/telemetry.md) in a small follow-up PR. Approved and ready to merge.

@Kaap10
Kaap10 merged commit c216cb4 into codeforstartups:development Nov 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry data model: DynamoDB events table

2 participants