-
Notifications
You must be signed in to change notification settings - Fork 392
feat(telemetry): add stable session identifier headers #7821
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
18 commits
Select commit
Hold shift + click to select a range
748e99f
feat(telemetry): add stable session identifier headers
khanayan123 1c7b1a2
fix: address CI lint, test, and label failures
khanayan123 bd88368
refactor: fold child_session into existing child_process instrumentation
khanayan123 3a68e9b
refactor: rename child_session to session-propagation, gate on teleme…
khanayan123 a21798d
refactor: move session-propagation to top-level require
khanayan123 28cfefc
test: add fork and callArgs mutation tests to child_process instrumen…
khanayan123 651b556
fix: address CI lint and Windows test failures, clean up redundant code
khanayan123 6073719
chore: remove redundant comments and fix stray division operator
khanayan123 303e977
chore: remove duplicate tests covering same code paths
khanayan123 599733f
fix: resolve lint errors in test files
khanayan123 6a4b898
fix: restore original comments removed by simplifier
khanayan123 d3dd247
refactor: use switch statement in onChildProcessStart
khanayan123 5634511
fix: improve codecov coverage for session-propagation
khanayan123 09bad69
fix: preserve callbacks when injecting session env vars
khanayan123 281ecf0
refactor: simplify session-propagation with findOptionsIndex
khanayan123 626781b
chore: remove unnecessary comments from session-propagation
khanayan123 ca5349a
feat: add stop() lifecycle to session-propagation
khanayan123 9a8f4dd
fix: handle spawn(cmd, undefined, opts) in findOptionsIndex
khanayan123 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,78 @@ | ||
| 'use strict' | ||
|
|
||
| const dc = require('dc-polyfill') | ||
|
|
||
| const childProcessChannel = dc.tracingChannel('datadog:child_process:execution') | ||
|
|
||
| let subscribed = false | ||
| let rootSessionId | ||
| let runtimeId | ||
|
|
||
| function injectSessionEnv (existingEnv) { | ||
| // eslint-disable-next-line eslint-rules/eslint-process-env -- not in supported-configurations.json | ||
| const base = existingEnv == null ? process.env : existingEnv | ||
| return { | ||
| ...base, | ||
| DD_ROOT_JS_SESSION_ID: rootSessionId, | ||
| DD_PARENT_JS_SESSION_ID: runtimeId, | ||
| } | ||
| } | ||
|
|
||
| function findOptionsIndex (args, shell) { | ||
| if (Array.isArray(args[1])) { | ||
| return { index: 2, exists: args[2] != null && typeof args[2] === 'object' } | ||
| } | ||
| if (args[1] != null && typeof args[1] === 'object') { | ||
| return { index: 1, exists: true } | ||
| } | ||
| if (!shell && args[2] != null && typeof args[2] === 'object') { | ||
| return { index: 2, exists: true } | ||
| } | ||
| return { index: shell ? 1 : 2, exists: false } | ||
| } | ||
|
|
||
| function onChildProcessStart (context) { | ||
| if (!context.callArgs) return | ||
|
|
||
| const args = context.callArgs | ||
| const { index, exists } = findOptionsIndex(args, context.shell) | ||
|
|
||
| if (exists) { | ||
| args[index] = { ...args[index], env: injectSessionEnv(args[index].env) } | ||
| return | ||
| } | ||
|
|
||
| const opts = { env: injectSessionEnv(null) } | ||
|
|
||
| if (!context.shell && !Array.isArray(args[1])) { | ||
| args.splice(1, 0, []) | ||
| } | ||
|
|
||
| if (typeof args[index] === 'function') { | ||
| args.splice(index, 0, opts) | ||
| } else { | ||
| args[index] = opts | ||
| } | ||
| } | ||
|
|
||
| const handler = { start: onChildProcessStart } | ||
|
|
||
| function start (config) { | ||
| if (!config.telemetry?.enabled || subscribed) return | ||
| subscribed = true | ||
|
|
||
| rootSessionId = config.rootSessionId | ||
| runtimeId = config.tags['runtime-id'] | ||
|
|
||
| childProcessChannel.subscribe(handler) | ||
| } | ||
|
|
||
| function stop () { | ||
| if (!subscribed) return | ||
| childProcessChannel.unsubscribe(handler) | ||
| subscribed = false | ||
| rootSessionId = undefined | ||
| runtimeId = undefined | ||
| } | ||
|
|
||
| module.exports = { start, stop, _onChildProcessStart: onChildProcessStart } | ||
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.
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.