-
Notifications
You must be signed in to change notification settings - Fork 399
Telemetry: send events in forked children #5074
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1074777
Send telemetry in forked children
p fdf0fe9
consolidate attr_readers
p 1e15731
types
p 8ed7634
skip fork tests on jruby
p 8dc1c4a
mark as integration tests
p e8b48ca
fix syntax
p f2e7239
tabs
p d784c1d
Merge branch 'master' into telemetry-in-children
p 1fb050b
go back to reset_ran_once_state_for_tests
p 9541c23
reset initial event once
p bb2da80
Update lib/datadog/core/telemetry/event/app_started.rb
p-datadog 856b1a0
Update lib/datadog/core/telemetry/event/app_started.rb
p-datadog c1aafe3
extract initialize_state
p 5087109
remove Buffer#clear
p f44a8f5
type
p fa9154f
make private
p 114b87e
add docs
p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Telemetry Development | ||
|
|
||
| ## Telemetry Presence | ||
|
|
||
| `dd-trace-rb` is written to assume that the telemetry component is always | ||
| present. If telemetry is disabled, the component is still created but does | ||
| nothing. | ||
|
|
||
| Most components call methods on `telemetry` unconditionally. There are two | ||
| exceptons: DI and Data Streams are written to assume that `telemetry` may be nil. | ||
| However, this assumption is not necessary and these components may be | ||
| changed in the future to assume that `telemetry` is always present. | ||
|
|
||
| ## Event Submission Prior To Start | ||
|
|
||
| Telemetry is unique among other components in that it permits events to be | ||
| submitted to it prior to its worker starting. This is done so that errors | ||
| during `Datadog.configure` processing can be reported via telemetry, because | ||
| the errors can be produced prior to telemetry worker starting. The telemetry | ||
| component keeps the events and sends them after the worker starts. | ||
|
|
||
| ## Initial Event | ||
|
|
||
| `dd-trace-rb` can be initialized multiple times during application boot. | ||
| For example, if customers follow our documentation and require | ||
| `datadog/auto_instrument`, and call `Datadog.configure`, they would get | ||
| `Datadog.configure` invoked two times total (the first time by `auto_instrument`) | ||
| and thus telemetry instance would be created twice. This happens in the | ||
| applications used with system tests. | ||
|
|
||
| System tests, on the other hand, require that there is only one `app-started` | ||
| event emitted, because they think the application is launched once. | ||
| To deal with this we have a hack in the telemetry code to send an | ||
| `app-client-configuration-change` event instead of the second `app-started` | ||
| event. This is implemented via the `SynthAppClientConfigurationChange` class. | ||
|
|
||
| ## Fork Handling | ||
|
|
||
| We must send telemetry data from forked children. | ||
|
|
||
| Telemetry started out as a diagnostic tool used during application boot, | ||
| but is now used for reporting application liveness (and settings/state) | ||
| throughout the application lifetime. Live Debugger / Dynamic Instrumentation, | ||
| for example, require ongoing `app-heartbeat` events emitted via telemetry | ||
| to provide a working UI to customers. | ||
|
|
||
| It is somewhat common for customers to preload the application in the parent | ||
| web server process and process requests from children. This means telemetry | ||
| is initialized from the parent process, and it must emit events in the | ||
| forked children. | ||
|
|
||
| We use the standard worker `after_fork` handler to recreated the worker | ||
| thread in forked children. However, there are two caveats to keep in mind | ||
| which are specific to telemetry: | ||
|
|
||
| 1. Due to telemetry permitting event submission prior to its start, it is | ||
| not sufficient to simply reset the state from the worker's `perform` method, | ||
| as is done in other components. We must only reset the state when we are | ||
| in the forked child, otherwise we'll trash any events submitted to telemetry | ||
| prior to its worker starting. | ||
|
|
||
| 2. The child process is a brand new application as far as the backend/UI is | ||
| concerned, having a new runtime ID, and therefore the initial event in the | ||
| forked child must always be `app-started`. Since we track the initial event | ||
| in the telemetry component, this event must be changed to `app-started` in | ||
| forked children regardless of what it was in the parent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.