-
Notifications
You must be signed in to change notification settings - Fork 39
feat: unified stack trace configuration from agent, in-code and env vars #2235
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
base: feat-stack-trace
Are you sure you want to change the base?
Conversation
5965b8c to
b30a2d8
Compare
7213e70 to
efa9059
Compare
packages/collector/test/tracing/protocols/http/proxy/expressProxyControls.js
Outdated
Show resolved
Hide resolved
b30a2d8 to
04b7085
Compare
Co-authored-by: kirrg001 <katharina.irrgang@ibm.com>
| } else { | ||
| logger?.warn( | ||
| `The value of config.tracing.stackTrace has the non-supported type ${typeof config.tracing.stackTrace}. ` + | ||
| `Valid values are: ${validStackTraceModes.join(', ')}. Using default: all` |
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.
This is also validation.
kirrg001
left a comment
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.
Pre-approving
| const envVar = 'INSTANA_STACK_TRACE'; | ||
|
|
||
| if (isAgentConfig) { | ||
| const configPath = 'stack-trace value from agent'; |
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.
What is that?
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.
configPath is used only for logging purposes.
isAgentConfig is used to identify the source of the configuration, as we apply different rules for agent and non-agent sources.
If the configuration comes from the agent, it takes precedence, and we do not evaluate any other sources.
If the configuration comes from in-code settings, it eventually resolves to the default value if config is not provided.
The isAgentConfig flag helps determine whether we should exit early or continue processing.
This is part of an optimisation effort. Previously, similar logic existed separately for agent and non-agent normalisation, which has now been merged.
| } | ||
|
|
||
| const validatedConfigGlobal = validateStackTraceMode( | ||
| tracingObj?.global?.stackTrace, |
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.
Its a bit confusing that for agent we forward the config value without global (see unannounced) but for incode we use the global usage here. That needs to be corrected, hard to follow the code.
| if (isAgentConfig) { | ||
| const configPath = 'stack-trace-length value from agent'; | ||
|
|
||
| const validatedAgentConfig = validateStackTraceLength(tracingObj?.stackTraceLength, configPath); |
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.
I feel like we still mix validation and normalization :D
The parent caller should deal with that - otherwise you are coupling the code too much
| } | ||
|
|
||
| const validatedConfig = validateStackTraceLength(tracingObj?.stackTraceLength, 'config.tracing.stackTraceLength'); | ||
| if (validatedConfig != null) { |
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.
Deprecation warning missing
kirrg001
left a comment
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.
See comments
| resetEnv(); | ||
| }); | ||
|
|
||
| describe('normalize()', () => { |
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.
This function is now split into 2 and has some logic change (removed validation)
686b641 to
bb4cf08
Compare
| stackTraceMode = agentTraceConfig.stackTrace; | ||
| } | ||
|
|
||
| // stackTraceLength is valid when set to any number, including 0 |
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.
// stackTraceLength is valid when set to any number, including 0
Why do we have to do another validation check here? 🤔
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.
At activation time, extraConfig?.tracing will be present, and stackTrace may or may not be set by the agent.
If we blindly assign the value, it may be undefined, which would overwrite the existing stackTraceMode.
Therefore, we need to check for its existence before assigning it.
The same applies to length, but in this case we must also support 0 as a valid value.
For that reason, we check the type to confirm validity.
Only when these checks pass do we overwrite the previously resolved value (from core, environment, or default).
ps: we follow this similar logic already:
| if (isIgnoreEndpointsEmpty && extraConfig?.tracing?.ignoreEndpoints) { |
packages/core/src/config/index.js
Outdated
|
|
||
| module.exports.configNormalizers = configNormalizers; | ||
| module.exports.configValidators = { | ||
| stackTraceValidation: require('./configValidators/stackTraceValidation') |
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.
Lets keep requires on top. There is a way to lazy load modules, but not part of this PR.
| if (config.tracing.global?.stackTrace !== undefined) { | ||
| const modeResult = validateStackTraceMode(config.tracing.global.stackTrace); | ||
| if (!modeResult.isValid) { | ||
| logger.warn(`Invalid config.tracing.global.stackTrace: ${modeResult.error}`); |
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.
Bug: if not valid, you have to return and use the default
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.
Yes, that is already covered in the logic. We validate first and then call the normaliser. The normaliser already returns the default in the relevant cases.
| ); | ||
| config.tracing.stackTraceLength = defaults.tracing.stackTraceLength; | ||
| function normalizeTracingStackTrace(config) { | ||
| if (config.tracing.global?.stackTrace !== undefined) { |
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.
if (config.tracing.global?.stackTrace !== undefined) {
const modeResult = validateStackTraceMode(config.tracing.global.stackTrace);
if (!modeResult.isValid) {
logger.warn(Invalid config.tracing.global.stackTrace: ${modeResult.error});
}
}
config.tracing.stackTrace = configNormalizers.stackTrace.normalizeStackTraceMode(config);
Why do we call normalize if config.tracing.global?.stackTrace is not set?
The logic in this fn does not look right to me
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.
This is the same as the previous case: the normaliser returns default values under the relevant conditions, such as when the value is not set or when an invalid value is provided.
Unlike the agent (unannounced), we always call the normaliser here. For the unannounced case, the normaliser is only called when a valid configuration is present.
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.
I will change this to be in line with unannounced!
kirrg001
left a comment
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.
See comments
|



refs https://jsw.ibm.com/browse/INSTA-63750
Current PR
agent → tracing.global.stackTraceLength → tracing.stackTraceLength → env var → default
Next PR
Extend the stackTraceLength limit to the getStackTrace function and add the required tests.done in this pr