Skip to content

Fix inconsistent exception logging patterns and add guidance#8231

Open
VamshikrishnaMonagari wants to merge 1 commit intoopen-telemetry:mainfrom
VamshikrishnaMonagari:fix-exception-logging-patterns
Open

Fix inconsistent exception logging patterns and add guidance#8231
VamshikrishnaMonagari wants to merge 1 commit 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.28%. Comparing base (3c0f6ff) to head (718b3c7).

Files with missing lines Patch % Lines
...incubator/fileconfig/DeclarativeConfiguration.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8231   +/-   ##
=========================================
  Coverage     90.27%   90.28%           
+ Complexity     7695     7692    -3     
=========================================
  Files           850      850           
  Lines         23207    23201    -6     
  Branches       2356     2356           
=========================================
- Hits          20951    20946    -5     
+ Misses         1531     1528    -3     
- Partials        725      727    +2     

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

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