Skip to content

Conversation

@abhilash-sivan
Copy link
Contributor

@abhilash-sivan abhilash-sivan commented Dec 16, 2025

refs https://jsw.ibm.com/browse/INSTA-63750

Current PR

  • Accept stack trace configuration (tracing.global.stack-trace-length and stack-trace) from the agent.
  • Support in-code configuration via tracing.global.stackTraceLength and stackTrace, while keeping tracing.stackTraceLength for backward compatibility.
  • Configuration precedence (highest to lowest):
    agent → tracing.global.stackTraceLength → tracing.stackTraceLength → env var → default
  • Introduce a maximum limit of 500 for stackTraceLength; the default remains 10.
  • Apply agent configuration when present.
  • Enforce the configured stackTraceLength limit in setErrorDetails to demonstrate that the limit is applied.

Next PR

  • Extend the stackTraceLength limit to the getStackTrace function and add the required tests. done in this pr
  • Apply the stackTrace mode and add corresponding tests.

@abhilash-sivan abhilash-sivan marked this pull request as ready for review December 17, 2025 06:34
@abhilash-sivan abhilash-sivan requested a review from a team as a code owner December 17, 2025 06:34
@abhilash-sivan abhilash-sivan marked this pull request as draft December 17, 2025 06:43
@abhilash-sivan abhilash-sivan changed the title feat: accept stack trace config from agent and apply limit of 50 feat: accept stack trace config from agent Dec 17, 2025
@abhilash-sivan abhilash-sivan marked this pull request as ready for review December 17, 2025 10:34
@abhilash-sivan abhilash-sivan changed the title feat: accept stack trace config from agent feat: accept stack trace config from agent and env, and apply Dec 19, 2025
Co-authored-by: kirrg001 <katharina.irrgang@ibm.com>
Co-authored-by: kirrg001 <katharina.irrgang@ibm.com>
logger.warn(
`Normalized the provided value of config.tracing.stackTraceLength (${numericalLength}) to ${normalized}.`
);
if (typeof tracing.stackTraceLength !== 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Why do we have to validate here again that stackTraceLength is a number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a similar case of #2235 (comment)

We can't just check the existence because of the possible 0 case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra check is only needed because we dont set the default value after the failed validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, in a recent change I updated the normaliser to return null when no valid data is parsed.
This should have allowed us to move away from type checks and instead use a simple != null check.

However, there are some edge cases to consider.

For example, when a legacy configuration is set with an invalid value:

const config = coreConfig.normalize({ tracing: { stackTraceLength: {} } });
expect(config.tracing.stackTraceLength).to.equal(10);

In this case, validation fails and the normaliser is not called.
Because of that, the value remains defined (but invalid), and the != null check passes.
As a result, we never fall back to the default value, which is incorrect.

To handle edge cases like {}, [], or [18], we still need to perform a type check.
This is specific to stackTraceLength only because legacy support writes directly to the same field we later normalise.

This issue does not apply to stackTrace mode, since that value is derived from tracing.global.stackTrace, and when the user provides an invalid value, we correctly fall back to the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of that, the value remains defined (but invalid), and the != null check passes.

If validation fails, we have to set defaults!

Co-authored-by: kirrg001 <katharina.irrgang@ibm.com>
const isLegacyLengthDefined = tracing.stackTraceLength !== undefined;

if (isGlobalLengthDefined || isLegacyLengthDefined) {
if (isLegacyLengthDefined && !isGlobalLengthDefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have defined isLegacyLengthDefined -> we show the warning. It doesn't matter if customer already uses the new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, updated 👍


/**
* Normalizes stack trace length configuration based on precedence.
* Precedence: global config > config > env var > default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The features ignore-endpoints and disable used the community config order. This slipped through my review. We should have continued with our Node.js config order. Now we are in a mixed state, which is not right.

As we do not want to change ignore-endpoints and disable features, we decided change the order in our tracer asap (Q1) and release v6. We have that on our board anyway for a while now (https://jsw.ibm.com/browse/INSTA-817).

That means (I am sorry) this PR also has to follow the new community order.

cc @aryamohanan cc @abhilash-sivan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Np., Will do

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% make sense.

Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-approving. Just the new order is missing.

Copy link
Contributor

@aryamohanan aryamohanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work 👏

@abhilash-sivan abhilash-sivan merged commit a33fc10 into feat-stack-trace Dec 31, 2025
1 check was pending
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants