[Issue #7] Add event metadata support #33
Reference in New Issue
Block a user
Delete Branch "issue-7-event-metadata-support"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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!