## Summary
Add optional metadata field to Event for correlation IDs, causation IDs, and user context to support distributed tracing and auditing.
## Changes
- Add `Metadata` field (`map[string]string`) to Event struct with `omitempty` JSON tag
- Add metadata key constants: `MetadataKeyCorrelationID`, `MetadataKeyCausationID`, `MetadataKeyUserID`, `MetadataKeyTraceID`, `MetadataKeySpanID`
- Add helper methods for setting/getting common metadata:
- `SetMetadata(key, value)` / `GetMetadata(key)`
- `SetCorrelationID` / `GetCorrelationID`
- `SetCausationID` / `GetCausationID`
- `SetUserID` / `GetUserID`
- `SetTraceID` / `GetTraceID`
- `SetSpanID` / `GetSpanID`
- Add `WithMetadataFrom(source)` helper for copying metadata between events (useful for event chaining)
- Add comprehensive unit tests for metadata serialization and helper methods
- Add store tests verifying metadata is persisted and retrieved correctly
## Acceptance Criteria
- [x] Add Metadata field to Event struct (map[string]string or similar)
- [x] Metadata is persisted and retrieved correctly
- [x] Metadata is optional (nil/empty allowed)
- [x] Update serialization to include metadata
- [x] Add helper methods for common metadata (correlation ID, causation ID)
Closes #7
- Add Metadata field (map[string]string) to Event struct with omitempty
- Add helper methods for common metadata: SetCorrelationID/GetCorrelationID,
SetCausationID/GetCausationID, SetUserID/GetUserID, SetTraceID/GetTraceID,
SetSpanID/GetSpanID
- Add WithMetadataFrom helper for copying metadata between events
- Add metadata key constants for standard fields
- Add comprehensive unit tests for metadata serialization and helpers
- Add store tests verifying metadata persistence
Closes#7
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This is an automated review generated by the code-reviewer agent.
Summary
This PR adds comprehensive event metadata support for distributed tracing and auditing. The implementation is clean, well-tested, and follows Go best practices. The feature enables correlation of events across services using standard metadata fields like correlation ID, causation ID, user ID, and OpenTelemetry trace/span IDs.
Note: This PR branch includes commits from other pending PRs (hashring tests, eventstore tests, snapshot tests). Only the most recent commit (97ff1c3) addresses issue #7.
Findings
Code Quality
Excellent:
Clean API design with helper methods for common metadata fields
Proper initialization handling in SetMetadata (nil-safe)
Good use of constants for standard metadata keys
Clear, concise method implementations
Comprehensive documentation in comments
Minor observation:
The CommandID field in Event struct (line 36 in event.go) serves a similar purpose to CorrelationID in metadata. Consider documenting the relationship or deprecating CommandID in favor of metadata.correlationId for consistency.
Potential Bugs
No issues found. The implementation correctly handles:
Nil metadata maps (defensive programming in GetMetadata/WithMetadataFrom)
Empty metadata maps
Map initialization in SetMetadata
Deep copy in WithMetadataFrom (copies values, not reference)
Security Concerns
No security concerns identified.
Metadata is map[string]string, preventing injection of complex types
No user input is directly processed by these methods
Metadata is properly serialized/deserialized through JSON
Style Notes
Consistent with codebase conventions:
Follows Go naming conventions (exported constants, camelCase JSON tags)
Uses omitempty JSON tag appropriately for optional field
Method naming follows Go getter/setter patterns
Comments follow godoc standards
Test Coverage
Outstanding test coverage:
JSON serialization/deserialization with metadata
omitempty behavior verification
All helper methods tested (Get/Set for each metadata type)
Nil and empty metadata handling
WithMetadataFrom functionality including edge cases
Store persistence verification for InMemoryEventStore
468 lines of test code in event_test.go
219 lines of store integration tests in store/memory_test.go
Test quality highlights:
Tests verify both behavior and implementation details (e.g., checking correct metadata key constants)
This implementation is production-ready. The code is clean, well-documented, comprehensive test coverage validates all functionality, and the feature enables important distributed tracing capabilities. The minor observation about CommandID vs CorrelationID is worth considering for future cleanup but is not blocking.
Great work on the comprehensive test coverage and thoughtful API design!
## AI Code Review
> This is an automated review generated by the code-reviewer agent.
### Summary
This PR adds comprehensive event metadata support for distributed tracing and auditing. The implementation is clean, well-tested, and follows Go best practices. The feature enables correlation of events across services using standard metadata fields like correlation ID, causation ID, user ID, and OpenTelemetry trace/span IDs.
**Note:** This PR branch includes commits from other pending PRs (hashring tests, eventstore tests, snapshot tests). Only the most recent commit (97ff1c3) addresses issue #7.
### Findings
#### Code Quality
**Excellent:**
- Clean API design with helper methods for common metadata fields
- Proper initialization handling in SetMetadata (nil-safe)
- Good use of constants for standard metadata keys
- Clear, concise method implementations
- Comprehensive documentation in comments
**Minor observation:**
- The `CommandID` field in Event struct (line 36 in event.go) serves a similar purpose to `CorrelationID` in metadata. Consider documenting the relationship or deprecating CommandID in favor of metadata.correlationId for consistency.
#### Potential Bugs
**No issues found.** The implementation correctly handles:
- Nil metadata maps (defensive programming in GetMetadata/WithMetadataFrom)
- Empty metadata maps
- Map initialization in SetMetadata
- Deep copy in WithMetadataFrom (copies values, not reference)
#### Security Concerns
**No security concerns identified.**
- Metadata is map[string]string, preventing injection of complex types
- No user input is directly processed by these methods
- Metadata is properly serialized/deserialized through JSON
#### Style Notes
**Consistent with codebase conventions:**
- Follows Go naming conventions (exported constants, camelCase JSON tags)
- Uses `omitempty` JSON tag appropriately for optional field
- Method naming follows Go getter/setter patterns
- Comments follow godoc standards
#### Test Coverage
**Outstanding test coverage:**
- JSON serialization/deserialization with metadata
- omitempty behavior verification
- All helper methods tested (Get/Set for each metadata type)
- Nil and empty metadata handling
- WithMetadataFrom functionality including edge cases
- Store persistence verification for InMemoryEventStore
- 468 lines of test code in event_test.go
- 219 lines of store integration tests in store/memory_test.go
**Test quality highlights:**
- Tests verify both behavior and implementation details (e.g., checking correct metadata key constants)
- Edge cases covered (nil source, empty metadata, nil metadata)
- Integration tests verify metadata survives persistence layer
### Verdict
**LGTM**
This implementation is production-ready. The code is clean, well-documented, comprehensive test coverage validates all functionality, and the feature enables important distributed tracing capabilities. The minor observation about CommandID vs CorrelationID is worth considering for future cleanup but is not blocking.
Great work on the comprehensive test coverage and thoughtful API design!
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Add optional metadata field to Event for correlation IDs, causation IDs, and user context to support distributed tracing and auditing.
Changes
Metadatafield (map[string]string) to Event struct withomitemptyJSON tagMetadataKeyCorrelationID,MetadataKeyCausationID,MetadataKeyUserID,MetadataKeyTraceID,MetadataKeySpanIDSetMetadata(key, value)/GetMetadata(key)SetCorrelationID/GetCorrelationIDSetCausationID/GetCausationIDSetUserID/GetUserIDSetTraceID/GetTraceIDSetSpanID/GetSpanIDWithMetadataFrom(source)helper for copying metadata between events (useful for event chaining)Acceptance Criteria
Closes #7
AI Code Review
Summary
This PR adds comprehensive event metadata support for distributed tracing and auditing. The implementation is clean, well-tested, and follows Go best practices. The feature enables correlation of events across services using standard metadata fields like correlation ID, causation ID, user ID, and OpenTelemetry trace/span IDs.
Note: This PR branch includes commits from other pending PRs (hashring tests, eventstore tests, snapshot tests). Only the most recent commit (
97ff1c3) addresses issue #7.Findings
Code Quality
Excellent:
Minor observation:
CommandIDfield in Event struct (line 36 in event.go) serves a similar purpose toCorrelationIDin metadata. Consider documenting the relationship or deprecating CommandID in favor of metadata.correlationId for consistency.Potential Bugs
No issues found. The implementation correctly handles:
Security Concerns
No security concerns identified.
Style Notes
Consistent with codebase conventions:
omitemptyJSON tag appropriately for optional fieldTest Coverage
Outstanding test coverage:
Test quality highlights:
Verdict
LGTM
This implementation is production-ready. The code is clean, well-documented, comprehensive test coverage validates all functionality, and the feature enables important distributed tracing capabilities. The minor observation about CommandID vs CorrelationID is worth considering for future cleanup but is not blocking.
Great work on the comprehensive test coverage and thoughtful API design!