Skip to content

Fix inconsistent exception logging patterns and add guidance#8231

Merged
jack-berg merged 2 commits intoopen-telemetry:mainfrom
VamshikrishnaMonagari:fix-exception-logging-patterns
Apr 27, 2026
Merged

Fix inconsistent exception logging patterns and add guidance#8231
jack-berg merged 2 commits intoopen-telemetry:mainfrom
VamshikrishnaMonagari:fix-exception-logging-patterns

Conversation

@VamshikrishnaMonagari
Copy link
Copy Markdown
Contributor

Category A : Remove redundant e.getMessage() where exception is already passed as the Throwable parameter:

  • GrpcExporter.java
  • HttpExporter.java
  • JaegerRemoteSampler.java (also fix stale FINEST log to pass exception as Throwable instead of concatenating)

Category B : Pass exception as Throwable instead of stringifying via getMessage(), so logging frameworks can render full stack traces:

  • AutoConfiguredOpenTelemetrySdkBuilder.java
  • DeclarativeConfiguration.java
  • TracerShim.java
  • SdkDoubleHistogram.java
  • SdkLongHistogram.java

Add best practice guidance to CONTRIBUTING.md recommending the use of dedicated logger overloads that accept a Throwable parameter.

Resolves #8228

@VamshikrishnaMonagari VamshikrishnaMonagari requested a review from a team as a code owner March 31, 2026 01:10
@VamshikrishnaMonagari VamshikrishnaMonagari force-pushed the fix-exception-logging-patterns branch 2 times, most recently from 699d1bd to e01ec36 Compare March 31, 2026 01:56
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.27%. Comparing base (f674cdd) to head (4b8589c).

Files with missing lines Patch % Lines
...re/declarativeconfig/DeclarativeConfiguration.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8231   +/-   ##
=========================================
  Coverage     90.27%   90.27%           
+ Complexity     7695     7694    -1     
=========================================
  Files           850      850           
  Lines         23213    23207    -6     
  Branches       2356     2356           
=========================================
- Hits          20955    20951    -4     
+ Misses         1531     1529    -2     
  Partials        727      727           

☔ 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.

@jack-berg
Copy link
Copy Markdown
Member

Sorry for the delayed review. I've reworked the CONTRIBUTING.md and introduced a knowledge base at https://github.com/open-telemetry/opentelemetry-java/tree/main/docs/knowledge

Can you merge main and include a section about this guidance in https://github.com/open-telemetry/opentelemetry-java/blob/main/docs/knowledge/general-patterns.md? Thanks!

@VamshikrishnaMonagari VamshikrishnaMonagari force-pushed the fix-exception-logging-patterns branch from e01ec36 to 86fd832 Compare April 23, 2026 01:57
…uidance

Category A — Remove redundant e.getMessage() where exception is already
passed as the Throwable parameter:
- GrpcExporter.java
- HttpExporter.java
- JaegerRemoteSampler.java (also fix stale FINEST log to pass exception
  as Throwable instead of concatenating)

Category B — Pass exception as Throwable instead of stringifying via
getMessage(), so logging frameworks can render full stack traces:
- AutoConfiguredOpenTelemetrySdkBuilder.java
- DeclarativeConfiguration.java
- TracerShim.java
- SdkDoubleHistogram.java
- SdkLongHistogram.java

Add best practice guidance to CONTRIBUTING.md recommending the use of
dedicated logger overloads that accept a Throwable parameter.

Resolves open-telemetry#8228
@VamshikrishnaMonagari VamshikrishnaMonagari force-pushed the fix-exception-logging-patterns branch from 86fd832 to 718b3c7 Compare April 23, 2026 02:02
@VamshikrishnaMonagari
Copy link
Copy Markdown
Contributor Author

Sorry for the delayed review. I've reworked the CONTRIBUTING.md and introduced a knowledge base at https://github.com/open-telemetry/opentelemetry-java/tree/main/docs/knowledge

Can you merge main and include a section about this guidance in https://github.com/open-telemetry/opentelemetry-java/blob/main/docs/knowledge/general-patterns.md? Thanks!

Thanks for the heads up, @jack-berg ! I've rebased on main and moved the logging guidance over to the Logging section in docs/knowledge/general-patterns.md. The CONTRIBUTING.md is left untouched now. Let me know if the placement looks good.

Copy link
Copy Markdown
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

Thanks!

@VamshikrishnaMonagari
Copy link
Copy Markdown
Contributor Author

@jack-berg Thanks for the approval! Could you go ahead and merge this when you get a chance? I don't have merge access on the repo.

@jack-berg
Copy link
Copy Markdown
Member

Yup - was waiting for a passing build after resolving a merge conflict

@jack-berg jack-berg merged commit 3751720 into open-telemetry:main Apr 27, 2026
28 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Apr 27, 2026

Thank you for your contribution @VamshikrishnaMonagari! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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.

Add contributing guidance for logging when handling exceptions

2 participants