Skip to content

log: add error field to Record and make SDK to emit exception attributes#7924

Merged
dmathieu merged 15 commits intoopen-telemetry:mainfrom
iblancasa:7923
Mar 5, 2026
Merged

log: add error field to Record and make SDK to emit exception attributes#7924
dmathieu merged 15 commits intoopen-telemetry:mainfrom
iblancasa:7923

Conversation

@iblancasa
Copy link
Contributor

@iblancasa iblancasa commented Feb 18, 2026

Fixes #7923

$ go test -run=^$ -bench=BenchmarkLoggerEmitExceptionAttributes -benchmem -count=5 -benchtime=500ms -cpu=1
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Apple M4 Pro
BenchmarkLoggerSetErrAndEmit                 	  628162	      1023 ns/op	    5371 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  663955	       863.3 ns/op	    5105 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  653888	      1067 ns/op	    5177 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  716438	       824.8 ns/op	    4764 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  746902	       999.2 ns/op	    5630 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  650696	      1042 ns/op	    5200 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  574962	       980.7 ns/op	    4743 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  536736	       989.2 ns/op	    5049 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  558511	      1190 ns/op	    4870 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  669452	       978.8 ns/op	    5067 B/op	       1 allocs/op
PASS
ok  	go.opentelemetry.io/otel/sdk/log	6.994s

TODO after merged:

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.6%. Comparing base (fdd1320) to head (245fa6e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7924   +/-   ##
=====================================
  Coverage   81.6%   81.6%           
=====================================
  Files        304     304           
  Lines      23389   23424   +35     
=====================================
+ Hits       19094   19132   +38     
+ Misses      3907    3904    -3     
  Partials     388     388           
Files with missing lines Coverage Δ
log/record.go 100.0% <100.0%> (ø)
sdk/log/logger.go 100.0% <100.0%> (ø)

... and 2 files with indirect coverage changes

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

pellared

This comment was marked as outdated.

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Please address the comments and add some benchmarks that would showcase and so that we can compare the difference between adding the attributes manually vs via the newly added API.

@pellared pellared dismissed their stale review February 20, 2026 12:12

most comments addressed

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

I made a quick look and overall it looks acceptable.
Please add the benchmark results to the PR description.
Moreover, I would prefer handling the stack trace in a seperate PR and track this on a separate issue.
Thanks a lot for your work.

@pellared pellared changed the title Add logger exception support for logs API/SDK log: add error field to Record and make SDK to emit exception attributes Feb 23, 2026
@iblancasa iblancasa marked this pull request as draft February 24, 2026 11:21
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
@iblancasa iblancasa marked this pull request as ready for review February 25, 2026 08:53
@pellared
Copy link
Member

#7924 (comment) this comment is not addressed and the linter is failing.

Side note: Overall the PR looks nice 😉 💪

Signed-off-by: Israel Blancas <iblancasa@gmail.com>
@iblancasa
Copy link
Contributor Author

#7924 (comment) this comment is not addressed

Sorry I thought with the introduced changes was ok. I did some modifications and I think it should be correct now. Please, let me know if you want some other change or I'm missing something else.

and the linter is failing

I was not sure about fixing this or not because #7924 (comment) Will fix in a better way.

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Thanks! 🏅

@pellared pellared requested a review from dashpole March 5, 2026 07:34
@pellared pellared added this to the v1.42.0 milestone Mar 5, 2026
iblancasa and others added 2 commits March 5, 2026 10:10
Co-authored-by: Damien Mathieu <42@dmathieu.com>
@dmathieu dmathieu merged commit c9d2015 into open-telemetry:main Mar 5, 2026
33 checks passed
pellared added a commit that referenced this pull request Mar 6, 2026
### Added

- Add `go.opentelemetry.io/otel/semconv/v1.40.0` package.
The package contains semantic conventions from the `v1.40.0` version of
the OpenTelemetry Semantic Conventions.
See the [migration documentation](./semconv/v1.40.0/MIGRATION.md) for
information on how to upgrade from
`go.opentelemetry.io/otel/semconv/v1.39.0`. (#7985)
- Add `Err` and `SetErr` on `Record` in `go.opentelemetry.io/otel/log`
to attach an error and set record exception attributes in
`go.opentelemetry.io/otel/log/sdk`. (#7924)

### Changed

- `TracerProvider.ForceFlush` in `go.opentelemetry.io/otel/sdk/trace`
joins errors together and continues iteration through SpanProcessors as
opposed to returning the first encountered error without attempting
exports on subsequent SpanProcessors. (#7856)

### Fixed

- Fix missing `request.GetBody` in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` to
correctly handle HTTP2 GOAWAY frame. (#7931)
- Fix semconv v1.39.0 generated metric helpers skipping required
attributes when extra attributes were empty. (#7964)
- Preserve W3C TraceFlags bitmask (including the random Trace ID flag)
during trace context extraction and injection in
`go.opentelemetry.io/otel/propagation`. (#7834)

### Removed

- Drop support for [Go 1.24]. (#7984)
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 log exception support to Logger API/SDK

4 participants