GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add custom stacktrace renderer which is length limit aware by jack-berg · Pull Request #7281 · open-telemetry/opentelemetry-java

Conversation

@jack-berg

@jack-berg jack-berg commented Apr 16, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Replace Throwable#printStackTrace(PrintStream) exception stacktrace rendering with a custom implementation which is aware of attribute length limits, and exits early to avoid unnecessary work. The result is significantly improved memory and cpu, with gains proportional to the difference between the total stack trace length and the attribute length limit. I.e. if you have a really long stack trace (i.e. 100k+ chars) and relatively small length limit (i.e. 1k chars), you'll have more to gain with this improvement.

Benchmark results:

Benchmark                                            (exceptionParam)  (lengthLimit)  (renderer)  Mode  Cnt      Score      Error   Units
StacktraceRenderBenchmark.render                               SIMPLE             10         JDK  avgt    5   2241.467 ±   60.057   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                 SIMPLE             10         JDK  avgt    5   8101.709 ±  219.657  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm            SIMPLE             10         JDK  avgt    5  19064.012 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                      SIMPLE             10         JDK  avgt    5      4.000             counts
StacktraceRenderBenchmark.render:gc.time                       SIMPLE             10         JDK  avgt    5      6.000                 ms
StacktraceRenderBenchmark.render                               SIMPLE             10      CUSTOM  avgt    5     52.201 ±    2.985   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                 SIMPLE             10      CUSTOM  avgt    5   4379.620 ±  255.944  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm            SIMPLE             10      CUSTOM  avgt    5    240.000 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                      SIMPLE             10      CUSTOM  avgt    5      2.000             counts
StacktraceRenderBenchmark.render:gc.time                       SIMPLE             10      CUSTOM  avgt    5      3.000                 ms
StacktraceRenderBenchmark.render                               SIMPLE           1000         JDK  avgt    5   2201.715 ±   12.929   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                 SIMPLE           1000         JDK  avgt    5   8679.632 ±   52.630  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm            SIMPLE           1000         JDK  avgt    5  20064.011 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                      SIMPLE           1000         JDK  avgt    5      5.000             counts
StacktraceRenderBenchmark.render:gc.time                       SIMPLE           1000         JDK  avgt    5      8.000                 ms
StacktraceRenderBenchmark.render                               SIMPLE           1000      CUSTOM  avgt    5    682.286 ±   21.344   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                 SIMPLE           1000      CUSTOM  avgt    5  11936.384 ±  370.103  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm            SIMPLE           1000      CUSTOM  avgt    5   8552.004 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                      SIMPLE           1000      CUSTOM  avgt    5      6.000             counts
StacktraceRenderBenchmark.render:gc.time                       SIMPLE           1000      CUSTOM  avgt    5      8.000                 ms
StacktraceRenderBenchmark.render                               SIMPLE         100000         JDK  avgt    5   2345.609 ±  228.133   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                 SIMPLE         100000         JDK  avgt    5   7727.529 ±  734.088  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm            SIMPLE         100000         JDK  avgt    5  19024.012 ±    0.002    B/op
StacktraceRenderBenchmark.render:gc.count                      SIMPLE         100000         JDK  avgt    5      4.000             counts
StacktraceRenderBenchmark.render:gc.time                       SIMPLE         100000         JDK  avgt    5      7.000                 ms
StacktraceRenderBenchmark.render                               SIMPLE         100000      CUSTOM  avgt    5   1208.501 ±  382.039   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                 SIMPLE         100000      CUSTOM  avgt    5  11661.313 ± 3568.475  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm            SIMPLE         100000      CUSTOM  avgt    5  14720.006 ±    0.002    B/op
StacktraceRenderBenchmark.render:gc.count                      SIMPLE         100000      CUSTOM  avgt    5      6.000             counts
StacktraceRenderBenchmark.render:gc.time                       SIMPLE         100000      CUSTOM  avgt    5     10.000                 ms
StacktraceRenderBenchmark.render                              COMPLEX             10         JDK  avgt    5   3885.420 ± 1011.756   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                COMPLEX             10         JDK  avgt    5   5556.220 ± 1337.094  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm           COMPLEX             10         JDK  avgt    5  22592.020 ±    0.006    B/op
StacktraceRenderBenchmark.render:gc.count                     COMPLEX             10         JDK  avgt    5      3.000             counts
StacktraceRenderBenchmark.render:gc.time                      COMPLEX             10         JDK  avgt    5      4.000                 ms
StacktraceRenderBenchmark.render                              COMPLEX             10      CUSTOM  avgt    5     51.126 ±    2.174   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                COMPLEX             10      CUSTOM  avgt    5   4471.278 ±  187.728  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm           COMPLEX             10      CUSTOM  avgt    5    240.000 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                     COMPLEX             10      CUSTOM  avgt    5      2.000             counts
StacktraceRenderBenchmark.render:gc.time                      COMPLEX             10      CUSTOM  avgt    5      3.000                 ms
StacktraceRenderBenchmark.render                              COMPLEX           1000         JDK  avgt    5   4198.255 ± 2681.956   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                COMPLEX           1000         JDK  avgt    5   5427.646 ± 2823.204  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm           COMPLEX           1000         JDK  avgt    5  23592.022 ±    0.016    B/op
StacktraceRenderBenchmark.render:gc.count                     COMPLEX           1000         JDK  avgt    5      3.000             counts
StacktraceRenderBenchmark.render:gc.time                      COMPLEX           1000         JDK  avgt    5      4.000                 ms
StacktraceRenderBenchmark.render                              COMPLEX           1000      CUSTOM  avgt    5    695.620 ±  176.546   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                COMPLEX           1000      CUSTOM  avgt    5  11713.686 ± 2748.314  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm           COMPLEX           1000      CUSTOM  avgt    5   8528.004 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                     COMPLEX           1000      CUSTOM  avgt    5      6.000             counts
StacktraceRenderBenchmark.render:gc.time                      COMPLEX           1000      CUSTOM  avgt    5      9.000                 ms
StacktraceRenderBenchmark.render                              COMPLEX         100000         JDK  avgt    5   4515.629 ± 3389.181   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                COMPLEX         100000         JDK  avgt    5   4890.416 ± 3325.991  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm           COMPLEX         100000         JDK  avgt    5  22552.023 ±    0.016    B/op
StacktraceRenderBenchmark.render:gc.count                     COMPLEX         100000         JDK  avgt    5      3.000             counts
StacktraceRenderBenchmark.render:gc.time                      COMPLEX         100000         JDK  avgt    5      5.000                 ms
StacktraceRenderBenchmark.render                              COMPLEX         100000      CUSTOM  avgt    5   1937.578 ±   26.976   ns/op
StacktraceRenderBenchmark.render:gc.alloc.rate                COMPLEX         100000      CUSTOM  avgt    5   8356.442 ±  115.892  MB/sec
StacktraceRenderBenchmark.render:gc.alloc.rate.norm           COMPLEX         100000      CUSTOM  avgt    5  17000.010 ±    0.001    B/op
StacktraceRenderBenchmark.render:gc.count                     COMPLEX         100000      CUSTOM  avgt    5      5.000             counts
StacktraceRenderBenchmark.render:gc.time                      COMPLEX         100000      CUSTOM  avgt    5      7.000                 ms

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jack-berg
Add custom stacktrace renderer which is length limit aware
3da5929
@jack-berg
jack-berg requested a review from a team as a code owner April 16, 2025 15:02
jack-berg
jack-berg commented Apr 16, 2025
View reviewed changes
Comment thread sdk/common/src/test/java/io/opentelemetry/sdk/internal/StackTraceRendererTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

jack-berg
jack-berg commented Apr 16, 2025
View reviewed changes
Comment thread sdk/common/src/test/java/io/opentelemetry/sdk/internal/StackTraceRendererTest.java
assertThat(new StackTraceRenderer(throwable, 1000).render())
.isEqualTo(jdkStackTrace(throwable, 1000));
assertThat(new StackTraceRenderer(throwable, Integer.MAX_VALUE).render())
.isEqualTo(jdkStackTrace(throwable, Integer.MAX_VALUE));

@jack-berg jack-berg Apr 16, 2025

Copy link
Copy Markdown
Member Author

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 love this test: for a list of exceptions render each at a variety of length limits, and compare the result to the built-in JDK stack trace renderer.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jack-berg
jack-berg commented Apr 16, 2025
View reviewed changes
Comment thread sdk/common/src/main/java/io/opentelemetry/sdk/internal/AttributeUtil.java Outdated
@@ -107,7 +105,9 @@ public static Object applyAttributeLengthLimit(Object value, int lengthLimit) {
}

public static void addExceptionAttributes(

@jack-berg jack-berg Apr 16, 2025

Copy link
Copy Markdown
Member Author

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.

One thing I've considered is retaining some sort of system property / env var to fallback to the built-in JDK exception rendering. Would offer a nice escape hatch to revert to the built-in jdk rendering in case there's any bugs in the code, but downside is it would be hard to know when it would be safe to finally remove.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jack-berg
suppress warnings
b2d3b58
@codecov

codecov Bot commented Apr 16, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 88.50575% with 10 lines in your changes missing coverage. Please review.

Project coverage is 89.75%. Comparing base (5e50aa7) to head (a0ded5e).
Report is 60 commits behind head on main.

Files with missing lines Patch % Lines
...opentelemetry/sdk/internal/StackTraceRenderer.java 86.30% 4 Missing and 6 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7281      +/-   ##
============================================
- Coverage     89.77%   89.75%   -0.03%     
- Complexity     6979     7002      +23     
============================================
  Files           797      798       +1     
  Lines         21165    21240      +75     
  Branches       2056     2071      +15     
============================================
+ Hits          19001    19063      +62     
- Misses         1503     1509       +6     
- Partials        661      668       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jack-berg added 2 commits April 16, 2025 11:09
@jack-berg
Fix typo
a098e83
@jack-berg
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
47aae74
…y-java into better-stacktrace-render
fandreuz
fandreuz reviewed Apr 17, 2025
View reviewed changes
Comment thread sdk/common/src/jmh/java/io/opentelemetry/sdk/internal/StacktraceRenderBenchmark.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

fandreuz
fandreuz reviewed Apr 17, 2025
View reviewed changes
Comment thread sdk/common/src/main/java/io/opentelemetry/sdk/internal/StackTraceRenderer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jack-berg
more perf
2159b0e
@jack-berg jack-berg mentioned this pull request May 30, 2025
Configurable exception.* attribute resolution #7266
Merged
jack-berg added 2 commits June 5, 2025 17:35
@jack-berg
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
30d25a2
…y-java into better-stacktrace-render
@jack-berg
Add property to render stacktrace using jvm default
7408c08
jack-berg
jack-berg commented Jun 5, 2025
View reviewed changes
Comment thread sdk/common/src/main/java/io/opentelemetry/sdk/internal/DefaultExceptionAttributeResolver.java Outdated
private static final DefaultExceptionAttributeResolver INSTANCE =
new DefaultExceptionAttributeResolver();
new DefaultExceptionAttributeResolver(
Boolean.parseBoolean(ConfigUtil.getString(ENABLE_JVM_STACKTRACE_PROPERTY, "false")));

@jack-berg jack-berg Jun 5, 2025

Copy link
Copy Markdown
Member Author

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.

Added new config to allow toggling between the naive JVM rendering logic and the new limits aware stacktrace rendering logic.

Given the solid testing in StackTraceRendererTest, I think we should default to the new limits aware rendering logic.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jkwatson reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jack-berg
Improve API ergonomics
a0ded5e
@jack-berg

jack-berg commented Jul 8, 2025

Copy link
Copy Markdown
Member Author

@open-telemetry/java-approvers please take a look - I'd like to get this in for the 7/11/25 release.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jkwatson
jkwatson approved these changes Jul 10, 2025
View reviewed changes

@jkwatson jkwatson left a comment

Copy link
Copy Markdown
Contributor

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.

Possible to add a little coverage on the uncovered bits? Otherwise, :shipit:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jack-berg

jack-berg commented Jul 10, 2025

Copy link
Copy Markdown
Member Author

I think the lack of coverage is a bit of a false positive. The key to hitting those uncovered bits to truncate exception stacktraces in all sorts of odd places. This test does that by introducing a random length limit as a parameter of the test. I think the coverage just didn't happen to randomly choose a limit which exercises those bits, but with enough iterations it should.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jack-berg
jack-berg merged commit 4821c37 into open-telemetry:main Jul 10, 2025
@jack-berg jack-berg mentioned this pull request Dec 12, 2025
Lazily evaluate ExceptionEventData exception.* attributes #7172
Closed
@jack-berg jack-berg mentioned this pull request Dec 19, 2025
Moving the rendering of the exception back into SdkSpan makes exception attribute rendering unavoidable and is expensive #7129
Closed
@trask trask mentioned this pull request Jan 7, 2026
Add optional Exception parameter to Emit LogRecord open-telemetry/opentelemetry-specification#4824
Merged
github-merge-queue Bot pushed a commit to open-telemetry/opentelemetry-specification that referenced this pull request Jan 23, 2026
@trask @pellared
Add optional Exception parameter to Emit LogRecord (#4824)
e0a5864
Part of [OTEP
4430](https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/4430-span-event-api-deprecation-plan.md).

This could be considered "just a convenience", but (in addition to a
very nice convenience) it also unlocks two additional features:
- Performance optimization since the SDK can take
`OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` into consideration when generating
large `exception.stacktrace` attributes (a very real issue in the Java
world: open-telemetry/opentelemetry-java#7281)
- (Future) customization of exception stacktraces (we have experimental
support for this in Java, e.g. to support "smarter" truncation of long
`exception.stacktrace` attributes:
open-telemetry/opentelemetry-java#7266)

Prototype:
open-telemetry/opentelemetry-java#7182

---------

Co-authored-by: Robert Pająk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jkwatson jkwatson jkwatson approved these changes
+1 more reviewer
@fandreuz fandreuz fandreuz left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jack-berg @jkwatson @fandreuz
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.