-
Notifications
You must be signed in to change notification settings - Fork 39
refactor: simplified bull child process initialization #2008
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ if (isNodeJsTooOld()) { | |
| } | ||
|
|
||
| const { util: coreUtil } = require('@instana/core'); | ||
| const agentOpts = require('./agent/opts'); | ||
|
|
||
| // This file can be used with NODE_OPTIONS or `node --require` to instrument a Node.js app with Instana without | ||
| // modifying the source code. See | ||
|
|
@@ -27,22 +26,14 @@ const agentOpts = require('./agent/opts'); | |
|
|
||
| const isExcludedFromInstrumentation = coreUtil.excludedFromInstrumentation && coreUtil.excludedFromInstrumentation(); | ||
|
|
||
| // In case this is a child process of an instrumented parent process we might receive the agent uuid from the parent | ||
| // process to be able to produce and collect spans immediately without waiting for a connection to the agent in this | ||
| // process. | ||
| // TODO: This does not work because you would report spans with parent agent uuid and the child process pid - | ||
| // this is not compatible. Our codebase does not support this. | ||
| const parentProcessAgentUuid = process.env.INSTANA_AGENT_UUID; | ||
| // CASE: This process is a forked child process of a bull worker. | ||
| const currentProcessIsBullChildProcess = process.env.INSTANA_IS_BULL_CHILD_PROCESS === 'true'; | ||
|
|
||
| if (!isExcludedFromInstrumentation) { | ||
| if (parentProcessAgentUuid) { | ||
| // @ts-ignore - Type 'string' is not assignable to type 'undefined' | ||
| // Probably because exports.agentUuid is set to undefined and export values were not supposed to be changed | ||
| // TODO: This has no effect. Remove! See comment above. | ||
| agentOpts.agentUuid = parentProcessAgentUuid; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally getting rid of this dirty code. It was not working anyway |
||
| if (currentProcessIsBullChildProcess) { | ||
| require('./index')({ | ||
| tracing: { | ||
| activateImmediately: true, | ||
| // If we don't ACTIVATE the process instrumentation for bull forked processes immediately, we miss this event. | ||
| activateBullProcessInstrumentation: true, | ||
| forceTransmissionStartingAt: 1 | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,6 +248,7 @@ exports.init = function init(_config, downstreamConnection, _processIdentityProv | |
| } | ||
| } | ||
|
|
||
| // TODO: This is not used anymore. Investigate any usages. Potentially remove/deprecate in the next major release. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added note to https://jsw.ibm.com/browse/INSTA-786
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its super nice that we might be able to remove activateImmediately functionality
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this configuration option isn’t documented, but we can look into it later. It’s really nice to discover such untouched or unknown parts of our codebase. |
||
| if (config.tracing.activateImmediately) { | ||
| exports.activate(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,10 @@ exports.init = function init(config) { | |
| if (config.tracing.activateBullProcessInstrumentation) { | ||
| shimmer.wrap(process, 'emit', shimProcessEmitForBullChildWorker); | ||
| shimmer.wrap(process, 'send', shimProcessSendForBullChildWorker); | ||
|
|
||
| // Activate immediately, otherwise we miss the first message event and the instana | ||
| // headers would not get removed from the message. | ||
| exports.activate(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of activating everything, we just activate what we need. The config even says it
|
||
| } | ||
| }; | ||
|
|
||
|
|
@@ -32,6 +36,7 @@ function shimProcessEmitForBullChildWorker(originalProcessEmit) { | |
| if (!isActive || event !== 'message') { | ||
| return originalProcessEmit.apply(this, arguments); | ||
| } | ||
|
|
||
| const ipcMessage = arguments[1]; | ||
|
|
||
| if ( | ||
|
|
||
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.
Changed from
INSTANA_AGENT_UUIDto exact envINSTANA_IS_BULL_CHILD_PROCESS.This env is not documented INSTANA_AGENT_UUID.