Skip to content

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Aug 18, 2025

This is not a performance critical exporter, but it is acting as the foundation for all other self-observability work. We want to ensure performance is considered for all this other work.

  • Do not allocate the add and record measurement option slices.
  • Do not allocate the metric.attrOpt to head when on default path (i.e. WithAttributeSet or WithAttributes)

There are three additional allocations in the self-observability. It appears these are added in the error scenario where we need to dynamically build the attributes that are being recorded.

Benchmarks

$ benchstat main-49be00144.txt amortize-opts-stdouttrace.txt
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/stdout/stdouttrace
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                        │ main-49be00144.txt │   amortize-opts-stdouttrace.txt    │
                                        │       sec/op       │   sec/op     vs base               │
ExporterExportSpans/SelfObservability-8          26.89µ ± 3%   27.40µ ± 3%       ~ (p=0.143 n=10)
ExporterExportSpans/NoObservability-8            25.99µ ± 3%   27.22µ ± 2%  +4.76% (p=0.004 n=10)

                                        │ main-49be00144.txt │    amortize-opts-stdouttrace.txt     │
                                        │        B/op        │     B/op      vs base                │
ExporterExportSpans/SelfObservability-8         5.459Ki ± 0%   4.081Ki ± 0%  -25.24% (p=0.000 n=10)
ExporterExportSpans/NoObservability-8           3.873Ki ± 0%   3.873Ki ± 0%        ~ (p=1.000 n=10)

                                        │ main-49be00144.txt │    amortize-opts-stdouttrace.txt     │
                                        │     allocs/op      │ allocs/op   vs base                  │
ExporterExportSpans/SelfObservability-8           80.00 ± 0%   67.00 ± 0%  -16.25% (p=0.000 n=10)
ExporterExportSpans/NoObservability-8             65.00 ± 0%   65.00 ± 0%        ~ (p=1.000 n=10) ¹
¹ all samples are equal

Follow-up

  • Investigate if the semconv helper packages can be updated to accept some of this complexity (e.g. add a AddSet method that accepts an attribute.Set instead of just ...attribute.KeyValue).

Alternatives

A cleaner version is found in #7226. That relies on an external bind package and the clean up mentioned above.

@MrAlias MrAlias added Skip Changelog PRs that do not require a CHANGELOG.md entry pkg:exporter:stdout Related to the stdout exporter package labels Aug 18, 2025
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7215   +/-   ##
=====================================
  Coverage   83.0%   83.0%           
=====================================
  Files        265     265           
  Lines      24748   24788   +40     
=====================================
+ Hits       20541   20582   +41     
+ Misses      3832    3831    -1     
  Partials     375     375           
Files with missing lines Coverage Δ
exporters/stdout/stdouttrace/trace.go 91.5% <100.0%> (+2.7%) ⬆️

... and 1 file with indirect coverage changes

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

@MrAlias MrAlias marked this pull request as ready for review August 18, 2025 21:30
@MrAlias MrAlias added this to the v1.38.0 milestone Aug 26, 2025
@MrAlias MrAlias merged commit 41f0330 into open-telemetry:main Aug 26, 2025
38 checks passed
@MrAlias MrAlias deleted the amortize-opts-stdouttrace branch August 26, 2025 16:10
@MrAlias MrAlias mentioned this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:exporter:stdout Related to the stdout exporter package Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants