Skip to content
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

Extract Writer from Tracer #1390

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

delner
Copy link
Contributor

@delner delner commented Mar 1, 2021

Currently our Datadog::Writer lives inside Datadog::Tracer. This has a few drawbacks:

  1. Creates tight coupling between "generating traces" and "writing traces"
    • To create a tracer, you must also create and configure a writer.
  2. Creating tracers implicitly creates writers with threads & background processes
    • These threads have the potential of hanging around in applications and test suites

The goal of this PR is to decouple "tracing" from "writing", by creating a simple pub-sub event.

Tracer#trace_completed
        |
     (trace)
        |
        V
   Writer#write
        |
        V
Writer#flush_completed
        |
   (responses)
        |
        V
PrioritySampler#update
  • Datadog::Tracer now triggers a :trace_completed event with the trace that finished.
  • Datadog::Writer now subscribes to that event and ingests the trace for writing.
  • Datadog::Writer now triggers a :flush_completed event with responses from agent.
  • Datadog.tracer.sampler now subscribes to that event and ingests the responses to update the priority sampler.

This pattern has some nice benefits for the tracer overall:

  1. Each component is simpler to test with less coupling
  2. Multiple writers can subscribe to a tracer (you could conceivably have both an agent and file writer)
  3. Tracing in CI can be much more lightweight (reroute traces to a test buffer instead of creating writer with threads)
  4. Easier to swap alternative writers in (e.g. synchronous vs asynchronous, etc)
  5. Much more similar to a ractorized message pattern, which may ease a migration to that implementation in the future.

@delner delner added core Involves Datadog core libraries dev/refactor Involves refactoring existing components labels Mar 1, 2021
@delner delner self-assigned this Mar 1, 2021
@delner
Copy link
Contributor Author

delner commented Mar 1, 2021

Thus far I have the core & its test suite updated. Tests for each integration still have to be updated, which is WIP.

@ivoanjo
Copy link
Member

ivoanjo commented Mar 9, 2021

I'll be honest: This is a pretty big change and I don't feel at all confident that I can review it properly. Is there a way we can break this down into smaller steps perhaps?

@marcotc
Copy link
Member

marcotc commented Mar 9, 2021

Despite the large number of files touched, the core changes to the core tracer components are surprisingly non-complex.
I really like this change, and I think it's worth pursuing its completion.

@delner
Copy link
Contributor Author

delner commented Mar 9, 2021

@ivoanjo Totally understand how this PR can be overwhelming... it is a lot of lines changed. I think the more complicated part of all this is more in the test suite, which hopefully makes the operational code (in the lib) more manageable to review.

I'm still trying to get all the tests to pass (having trouble with some expectations around tracer defaults implicitly written into some of the tests) but I will look for opportunities to simplify/split parts, if possible, to make it smaller. I might be able to do this with adding the subscription events, or some of the Minitest coverage that migrated into RSpec. Much of it will have to remain in one PR I suspect.

@ivoanjo ivoanjo removed their request for review April 15, 2021 08:02
@ivoanjo
Copy link
Member

ivoanjo commented Apr 15, 2021

(Removed myself for now otherwise this always shows up on my "reviews assigned to you list" -- do please re-add me when you start tackling this again :D )

@delner delner added the do-not-merge/WIP Not ready for merge label Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries dev/refactor Involves refactoring existing components do-not-merge/WIP Not ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants