-
Notifications
You must be signed in to change notification settings - Fork 401
chore(telemetry): track process creation via it headers #5464
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
11 commits
Select commit
Hold shift + click to select a range
329b0cd
chore(telemetry): track process creation via it headers
mabdinur cc34520
Merge 329b0cd04cee76516c737d50c9f90d329d6d5ce9 into 6f300a1920200bed4…
mabdinur 1ac18f3
[🤖] Lock Dependency: https://github.com/DataDog/dd-trace-rb/actions/r…
dd-apm-ecosystems-autobot[bot] 309042d
add spawnmonkeypatch to only once
mabdinur 5e656d1
use root instead of ancestor id (term used in dd-trace-py)
mabdinur f72882b
lint and clean up implementation
mabdinur 4fbe9f8
add tests and fix circular import with Datadogenv usage
mabdinur 8e2e7da
fix steep
mabdinur e2b2a89
avoid fixing circular import in this PR
mabdinur 319995f
avoid fixing circular import in this PR
mabdinur 2751beb
clean ups from PR review
mabdinur 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Datadog | ||
| module Core | ||
| module Utils | ||
| module SpawnMonkeyPatch | ||
| # @param lineage_envs_provider [#call] returns a Hash of env vars to merge into the child process | ||
| def self.apply!(lineage_envs_provider:) | ||
| @lineage_envs_provider = lineage_envs_provider | ||
| ::Process.singleton_class.prepend(ProcessSpawnPatch) | ||
| true | ||
| end | ||
|
|
||
| module ProcessSpawnPatch | ||
| def spawn(*args, **opts) | ||
| args.replace(SpawnMonkeyPatch.inject_lineage_envs(args)) | ||
|
Strech marked this conversation as resolved.
|
||
| super | ||
| end | ||
| end | ||
|
|
||
| # Process.spawn(env?, cmd, ...): env is optional first arg (Hash). When present, merge | ||
| # runtime_ids into it; when absent, prepend full ENV + runtime_ids so the child inherits both. | ||
| def self.inject_lineage_envs(args) | ||
| runtime_ids = @lineage_envs_provider.call | ||
| env_provided = Hash === args.first | ||
|
|
||
| base_env = env_provided ? args.first : DATADOG_ENV.to_h | ||
| env = base_env.merge(runtime_ids) | ||
| rest = env_provided ? args.drop(1) : args | ||
|
|
||
| [env, *rest] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| module Datadog | ||
| module Core | ||
| module Utils | ||
| module SpawnMonkeyPatch | ||
| # Set in apply! before Process.spawn is intercepted; internal wiring only. | ||
| self.@lineage_envs_provider: ^() -> ::Hash[::String, ::String] | ||
|
|
||
| def self.apply!: (lineage_envs_provider: ^() -> ::Hash[::String, ::String]) -> true | ||
|
|
||
| module ProcessSpawnPatch | ||
| def spawn: (*untyped args, **untyped opts) -> untyped | ||
| end | ||
|
|
||
| def self.inject_lineage_envs: (untyped args) -> ::Array[untyped] | ||
| end | ||
| end | ||
| end | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'datadog/core/utils/spawn_monkey_patch' | ||
| require 'datadog/core/configuration/components' | ||
| require 'datadog/core/configuration/settings' | ||
|
|
||
| RSpec.describe Datadog::Core::Utils::SpawnMonkeyPatch do | ||
| describe '::apply!' do | ||
| subject(:apply!) { described_class.apply!(lineage_envs_provider: -> { {} }) } | ||
|
|
||
| context 'when Process.spawn is supported' do | ||
| before do | ||
| skip 'Fork not supported' unless Process.respond_to?(:fork) | ||
| skip 'Process.spawn not supported' unless Process.respond_to?(:spawn) | ||
| end | ||
|
|
||
| it 'prepends the spawn monkey patch' do | ||
| expect_in_fork do | ||
| apply! | ||
| expect(Process.singleton_class.ancestors).to include(described_class::ProcessSpawnPatch) | ||
| expect(Process.method(:spawn).source_location.first).to match(/spawn_monkey_patch\.rb/) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'Components initialization' do | ||
| reset_at_fork_monkey_patch_for_components! | ||
|
|
||
| before do | ||
| skip 'Fork not supported' unless Process.respond_to?(:fork) | ||
| skip 'Process.spawn not supported' unless Process.respond_to?(:spawn) | ||
| end | ||
|
|
||
| it 'applies both fork and spawn patches when Components is initialized' do | ||
| expect_in_fork do | ||
| Datadog::Core::Configuration::Components.new(Datadog::Core::Configuration::Settings.new) | ||
|
|
||
| expect(Process.singleton_class.ancestors).to include( | ||
| Datadog::Core::Utils::AtForkMonkeyPatch::ProcessMonkeyPatch, | ||
| ) | ||
| expect(Process.singleton_class.ancestors).to include( | ||
| Datadog::Core::Utils::SpawnMonkeyPatch::ProcessSpawnPatch, | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end |
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.