Skip to content

Optimize Observability return types in in Prometheus exporter#7410

Merged
MrAlias merged 5 commits intoopen-telemetry:mainfrom
MrAlias:prom-optimize-observ
Sep 25, 2025
Merged

Optimize Observability return types in in Prometheus exporter#7410
MrAlias merged 5 commits intoopen-telemetry:mainfrom
MrAlias:prom-optimize-observ

Conversation

@MrAlias
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias commented Sep 24, 2025

Do not allocate a return function from ExportMetrics, RecordCollectionDuration, or RecordOperationDuration to the heap. Use the added ExportOp or Timer type instead.

Benchmarks

prometheus

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/prometheus
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                     │ main.bmark.result │  prom-optimize-observ.bmark.result  │
                                     │      sec/op       │    sec/op     vs base               │
Collect1/ObservabilityDisabled-8            27.59µ ±  7%   27.55µ ±  2%       ~ (p=0.631 n=10)
Collect1/ObservabilityEnabled-8             29.23µ ±  1%   27.25µ ±  7%  -6.78% (p=0.004 n=10)
Collect10/ObservabilityDisabled-8           70.75µ ±  3%   66.81µ ±  4%  -5.57% (p=0.003 n=10)
Collect10/ObservabilityEnabled-8            75.41µ ±  5%   71.13µ ±  5%  -5.68% (p=0.002 n=10)
Collect100/ObservabilityDisabled-8          420.7µ ±  4%   425.4µ ±  6%       ~ (p=0.912 n=10)
Collect100/ObservabilityEnabled-8           432.3µ ±  3%   422.2µ ±  5%       ~ (p=0.105 n=10)
Collect1000/ObservabilityDisabled-8         3.929m ± 31%   3.808m ±  2%  -3.09% (p=0.001 n=10)
Collect1000/ObservabilityEnabled-8          4.150m ±  1%   3.964m ±  4%  -4.48% (p=0.003 n=10)
Collect10000/ObservabilityDisabled-8        37.64m ±  6%   37.52m ±  2%       ~ (p=0.739 n=10)
Collect10000/ObservabilityEnabled-8         39.46m ±  2%   39.81m ± 19%       ~ (p=0.436 n=10)
geomean                                     672.6µ         654.6µ        -2.68%

                                     │ main.bmark.result │  prom-optimize-observ.bmark.result  │
                                     │       B/op        │     B/op      vs base               │
Collect1/ObservabilityDisabled-8            34.40Ki ± 0%   34.40Ki ± 0%       ~ (p=0.075 n=10)
Collect1/ObservabilityEnabled-8             34.64Ki ± 0%   34.43Ki ± 0%  -0.60% (p=0.000 n=10)
Collect10/ObservabilityDisabled-8           47.26Ki ± 0%   47.25Ki ± 0%       ~ (p=0.093 n=10)
Collect10/ObservabilityEnabled-8            47.93Ki ± 0%   47.30Ki ± 0%  -1.33% (p=0.000 n=10)
Collect100/ObservabilityDisabled-8          191.3Ki ± 0%   191.0Ki ± 0%       ~ (p=0.218 n=10)
Collect100/ObservabilityEnabled-8           197.0Ki ± 0%   191.6Ki ± 0%  -2.74% (p=0.000 n=10)
Collect1000/ObservabilityDisabled-8         1.902Mi ± 1%   1.891Mi ± 1%       ~ (p=0.353 n=10)
Collect1000/ObservabilityEnabled-8          1.935Mi ± 2%   1.889Mi ± 1%  -2.38% (p=0.000 n=10)
Collect10000/ObservabilityDisabled-8        17.67Mi ± 4%   18.17Mi ± 5%       ~ (p=0.190 n=10)
Collect10000/ObservabilityEnabled-8         18.62Mi ± 4%   17.98Mi ± 6%  -3.42% (p=0.035 n=10)
geomean                                     410.4Ki        406.9Ki       -0.85%

                                     │ main.bmark.result │  prom-optimize-observ.bmark.result   │
                                     │     allocs/op     │  allocs/op   vs base                 │
Collect1/ObservabilityDisabled-8              61.00 ± 0%    61.00 ± 0%       ~ (p=1.000 n=10) ¹
Collect1/ObservabilityEnabled-8               64.00 ± 0%    61.00 ± 0%  -4.69% (p=0.000 n=10)
Collect10/ObservabilityDisabled-8             410.0 ± 0%    410.0 ± 0%       ~ (p=1.000 n=10) ¹
Collect10/ObservabilityEnabled-8              423.0 ± 0%    411.0 ± 0%  -2.84% (p=0.000 n=10)
Collect100/ObservabilityDisabled-8           3.874k ± 0%   3.874k ± 0%       ~ (p=0.272 n=10)
Collect100/ObservabilityEnabled-8            3.979k ± 0%   3.876k ± 0%  -2.59% (p=0.000 n=10)
Collect1000/ObservabilityDisabled-8          38.90k ± 0%   38.88k ± 0%       ~ (p=0.306 n=10)
Collect1000/ObservabilityEnabled-8           39.88k ± 0%   38.88k ± 0%  -2.51% (p=0.000 n=10)
Collect10000/ObservabilityDisabled-8         387.9k ± 0%   388.9k ± 0%       ~ (p=0.138 n=10)
Collect10000/ObservabilityEnabled-8          399.0k ± 0%   388.6k ± 1%  -2.60% (p=0.000 n=10)
geomean                                      4.364k        4.298k       -1.52%
¹ all samples are equal

prometheus/internal/observ

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/prometheus/internal/observ
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                                  │ main.bmark.result │  prom-optimize-observ.bmark.result  │
                                                  │      sec/op       │   sec/op     vs base                │
InstrumentationExportMetrics/NoError-8                   92.64n ±  7%   56.07n ± 5%  -39.48% (p=0.000 n=10)
InstrumentationExportMetrics/AllError-8                  664.6n ±  4%   579.9n ± 4%  -12.74% (p=0.000 n=10)
InstrumentationExportMetrics/PartialError-8              637.5n ± 10%   579.1n ± 6%   -9.15% (p=0.000 n=10)
InstrumentationRecordOperationDuration/NoError-8         148.3n ±  5%   109.9n ± 3%  -25.89% (p=0.000 n=10)
InstrumentationRecordOperationDuration/Error-8           709.9n ±  8%   613.5n ± 3%  -13.58% (p=0.000 n=10)
InstrumentationRecordCollectionDuration/NoError-8        150.9n ± 11%   114.1n ± 5%  -24.35% (p=0.000 n=10)
InstrumentationRecordCollectionDuration/Error-8          723.5n ± 12%   629.2n ± 2%  -13.04% (p=0.000 n=10)
geomean                                                  332.7n         264.8n       -20.42%

                                                  │ main.bmark.result │    prom-optimize-observ.bmark.result    │
                                                  │       B/op        │    B/op     vs base                     │
InstrumentationExportMetrics/NoError-8                     48.00 ± 0%    0.00 ± 0%  -100.00% (p=0.000 n=10)
InstrumentationExportMetrics/AllError-8                    264.0 ± 0%   216.0 ± 0%   -18.18% (p=0.000 n=10)
InstrumentationExportMetrics/PartialError-8                264.0 ± 0%   216.0 ± 0%   -18.18% (p=0.000 n=10)
InstrumentationRecordOperationDuration/NoError-8           80.00 ± 0%    0.00 ± 0%  -100.00% (p=0.000 n=10)
InstrumentationRecordOperationDuration/Error-8             296.0 ± 0%   216.0 ± 0%   -27.03% (p=0.000 n=10)
InstrumentationRecordCollectionDuration/NoError-8          80.00 ± 0%    0.00 ± 0%  -100.00% (p=0.000 n=10)
InstrumentationRecordCollectionDuration/Error-8            296.0 ± 0%   216.0 ± 0%   -27.03% (p=0.000 n=10)
geomean                                                    152.0                    ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean

                                                  │ main.bmark.result │    prom-optimize-observ.bmark.result    │
                                                  │     allocs/op     │ allocs/op   vs base                     │
InstrumentationExportMetrics/NoError-8                     1.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)
InstrumentationExportMetrics/AllError-8                    3.000 ± 0%   2.000 ± 0%   -33.33% (p=0.000 n=10)
InstrumentationExportMetrics/PartialError-8                3.000 ± 0%   2.000 ± 0%   -33.33% (p=0.000 n=10)
InstrumentationRecordOperationDuration/NoError-8           1.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)
InstrumentationRecordOperationDuration/Error-8             3.000 ± 0%   2.000 ± 0%   -33.33% (p=0.000 n=10)
InstrumentationRecordCollectionDuration/NoError-8          1.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)
InstrumentationRecordCollectionDuration/Error-8            3.000 ± 0%   2.000 ± 0%   -33.33% (p=0.000 n=10)
geomean                                                    1.873                    ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean

@MrAlias MrAlias added this to the v1.39.0 milestone Sep 24, 2025
@MrAlias MrAlias added Skip Changelog PRs that do not require a CHANGELOG.md entry pkg:exporter:prometheus Related to the Prometheus exporter package labels Sep 24, 2025
@MrAlias MrAlias force-pushed the prom-optimize-observ branch from bf01606 to c5a1c8e Compare September 24, 2025 17:24
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 96.36364% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.5%. Comparing base (88d3fed) to head (0db3398).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
exporters/prometheus/exporter.go 81.8% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7410   +/-   ##
=====================================
  Coverage   85.5%   85.5%           
=====================================
  Files        277     277           
  Lines      24648   24654    +6     
=====================================
+ Hits       21080   21086    +6     
  Misses      3189    3189           
  Partials     379     379           
Files with missing lines Coverage Δ
...ters/prometheus/internal/observ/instrumentation.go 100.0% <100.0%> (ø)
exporters/prometheus/exporter.go 83.5% <81.8%> (ø)

... and 3 files 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 September 24, 2025 18:47
@MrAlias MrAlias merged commit ac8d8e9 into open-telemetry:main Sep 25, 2025
31 checks passed
@MrAlias MrAlias deleted the prom-optimize-observ branch September 25, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:exporter:prometheus Related to the Prometheus 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.

4 participants