-
-
Notifications
You must be signed in to change notification settings - Fork 88
Add FedifySpanExporter for distributed trace storage
#502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implement FedifySpanExporter class that persists ActivityPub activity traces to a KvStore, enabling distributed tracing across multiple nodes. This allows building debug dashboards that show complete request flows across web servers and background workers. Features: - Captures inbound (received) and outbound (sent) activities from OpenTelemetry span events - Supports both list() and cas() storage strategies depending on KvStore capabilities - Includes actorId and signatureDetails fields for debug dashboard use - Provides getActivitiesByTraceId() and getRecentTraces() query methods - Configurable TTL and key prefix options Closes fedify-dev#497 Co-Authored-By: Claude <noreply@anthropic.com>
Summary of ChangesHello @dahlia, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances Fedify's observability by integrating distributed tracing capabilities. It introduces Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces FedifySpanExporter, a valuable addition for distributed tracing in Fedify applications. The implementation is well-structured and accompanied by a comprehensive set of unit tests, covering various scenarios including distributed simulations and concurrent writes. The documentation is also clear and thorough.
I have a few suggestions to improve correctness and maintainability:
- Use the event timestamp from OpenTelemetry spans for more accurate trace data.
- Address a potential race condition in the trace summary update logic by using atomic operations.
- Refactor a method to reduce code duplication.
- Minor updates to an error message and documentation for consistency and clarity.
Overall, this is a great contribution that significantly enhances Fedify's observability capabilities.
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces FedifySpanExporter, a new OpenTelemetry SpanExporter implementation that enables distributed tracing across multiple nodes in Fedify deployments. The exporter persists ActivityPub activity traces to a KvStore, allowing debug dashboards to aggregate and display complete request flows across web servers and background workers.
Key changes:
- New
@fedify/fedify/otelmodule withFedifySpanExporterclass and supporting interfaces - Support for two storage strategies: individual record keys (when
list()is available) or CAS-based array append (when onlycas()is available) - Query methods for retrieving trace activities and summaries for dashboard consumption
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/fedify/tsdown.config.ts | Adds new otel module to build configuration |
| packages/fedify/package.json | Exports @fedify/fedify/otel module for npm consumers |
| packages/fedify/deno.json | Exports ./otel path for Deno consumers |
| packages/fedify/src/otel/mod.ts | Module entry point that re-exports FedifySpanExporter and related types |
| packages/fedify/src/otel/exporter.ts | Core implementation of FedifySpanExporter with span processing, storage, and query methods |
| packages/fedify/src/otel/exporter.test.ts | Comprehensive test suite with 22 test cases covering exporter functionality |
| docs/manual/opentelemetry.md | Documentation for setting up and using FedifySpanExporter in distributed deployments |
| CHANGES.md | Changelog entries documenting all new types and interfaces added in version 1.10.0 |
| AGENTS.md | Updates repository structure documentation to include otel module |
Use the OpenTelemetry event's actual timestamp instead of the export time for more accurate trace data. fedify-dev#502 (comment) fedify-dev#502 (comment)
Use compare-and-swap operation when available to ensure atomic updates to trace summaries in concurrent/distributed environments. fedify-dev#502 (comment) fedify-dev#502 (comment)
Collect all summaries before sorting and limiting to ensure we return the actual most recent traces, not just the first N traces returned by KvStore.list(). Also removed unnecessary type annotation on summaryPrefix. fedify-dev#502 (comment) fedify-dev#502 (comment)
Use key structure check instead of string includes to avoid incorrectly filtering records when traceId/spanId contains "_summaries" substring. fedify-dev#502 (comment)
Log errors when span export fails instead of silently swallowing them. Also document the new ["fedify", "otel", "exporter"] log category. fedify-dev#502 (comment)
FedifySpanExporter for distributed trace storage
The comment incorrectly stated the implementation is synchronous. The actual reason for no-op is that we write directly to KvStore without buffering, not that it's synchronous. fedify-dev#502 (comment)
The key ID is only available when HTTP signature verification was performed. fedify-dev#502 (comment)
Both #storeWithCas and #updateTraceSummary share the same pattern of CAS retry with fallback to set. Extract this into a reusable helper. fedify-dev#502 (comment)
|
Thanks for the thorough review! I've addressed most of the comments:
|
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces FedifySpanExporter, a new OpenTelemetry SpanExporter for persisting ActivityPub traces to a KvStore, enabling distributed tracing. The implementation is thorough, with comprehensive unit tests and excellent documentation.
I've identified a couple of potential issues in the implementation of FedifySpanExporter:
- A race condition in the
casretry logic that could lead to data loss. - The
getRecentTracesmethod silently fails onKvStoreimplementations withoutlist()support. - A minor logic issue in
getActivitiesByTraceIdthat could be confusing.
My review includes suggestions to improve the robustness and correctness of these parts. Overall, this is a great addition to Fedify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Avoid mutating the existing array from KvStore by using spread syntax to create a new array instead of push(). fedify-dev#502 (comment)
The filter is not needed because summary entries are stored under a different key prefix ([...keyPrefix, "_summaries", traceId]) which won't match when listing with prefix [...keyPrefix, traceId]. fedify-dev#502 (comment) fedify-dev#502 (comment)
Process all store operations in parallel and ensure all records are attempted even if some fail. This prevents partial data loss when individual operations fail. fedify-dev#502 (comment)
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces FedifySpanExporter, a significant new feature for distributed tracing by persisting OpenTelemetry spans to a KvStore. The implementation is robust, with support for different KvStore capabilities (list() vs. cas()) and a comprehensive suite of unit tests covering various scenarios, including distributed simulations and concurrency. The documentation is also updated thoroughly to reflect these new additions. My feedback includes a couple of suggestions for improving robustness and developer experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
2chanhaeng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR!
How about separating the package as just @fedify/otel?
@2chanhaeng Separating into Thank you all for the reviews! I've addressed the applicable feedback and responded to each comment. |
Summary
This PR implements
FedifySpanExporter, a new OpenTelemetrySpanExporterthat persists ActivityPub activity traces to aKvStore. This enables distributed tracing support across multiple nodes in a Fedify deployment, which is essential for building debug dashboards that can show complete request flows across web servers and background workers.Closes #497
Usage
The exporter captures activity data from OpenTelemetry span events (
activitypub.activity.receivedandactivitypub.activity.sent) and stores them with full trace context preserved:The stored traces can then be queried for display in a debug dashboard:
Storage strategies
The exporter supports two storage strategies depending on the
KvStorecapabilities. When thelist()method is available (preferred), it stores individual records with keys like[prefix, traceId, spanId]. When onlycas()is available, it uses compare-and-swap operations to append records to arrays stored per trace.Changelog
For a detailed list of added types and interfaces, see the diff in CHANGES.md.
Test plan
FedifySpanExporterclass (22 test cases)deno task test)pnpm test)