Skip to content

exporter/otlploghttp: guard observ metrics with Enabled checks#7813

Merged
MrAlias merged 11 commits intoopen-telemetry:mainfrom
NesterovYehor:metric-enabled-otlploghttp-observ
Feb 9, 2026
Merged

exporter/otlploghttp: guard observ metrics with Enabled checks#7813
MrAlias merged 11 commits intoopen-telemetry:mainfrom
NesterovYehor:metric-enabled-otlploghttp-observ

Conversation

@NesterovYehor
Copy link
Copy Markdown
Contributor

This PR updates the OTLP HTTP log exporter observability instrumentation to check instrument Enabled(ctx) before building options/attributes and recording measurements.

Behavior is unchanged when metrics are enabled; this reduces overhead when exporter self-metrics are disabled/no-op.

Part of the work tracked in #7800.

@itssaharsh
Copy link
Copy Markdown
Contributor

Hey, I wante to ask you check this but what if something changes in between time start (sorry i was wrong i was using your code as refrence to understand what the changes were )
if i.operationDuration.Enabled(ctx) {
extOp.start = time.Now()
}
duration := time.Since(e.start).Seconds()

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.6%. Comparing base (c3f955a) to head (d5094f4).
⚠️ Report is 251 commits behind head on main.

Files with missing lines Patch % Lines
...log/otlploghttp/internal/observ/instrumentation.go 89.2% 0 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #7813     +/-   ##
=======================================
- Coverage   81.7%   81.6%   -0.1%     
=======================================
  Files        304     304             
  Lines      23265   23277     +12     
=======================================
+ Hits       19013   19016      +3     
- Misses      3861    3862      +1     
- Partials     391     399      +8     
Files with missing lines Coverage Δ
...log/otlploghttp/internal/observ/instrumentation.go 94.8% <89.2%> (-5.2%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dmathieu
Copy link
Copy Markdown
Member

Could you add tests?

@NesterovYehor
Copy link
Copy Markdown
Contributor Author

Hi. I can add tests.

Do you expect separate cases (drop inflight/exported/duration, plus “all dropped”), or is one view-based test enough to show that when an instrument is disabled we skip it and ExportLogs().End() still records the remaining metrics?

@dmathieu
Copy link
Copy Markdown
Member

I think one test with subtests for each metric would be good.

@dmathieu
Copy link
Copy Markdown
Member

Don't trust what the LLM says. Your test needs to fail before your changes, and pass after.
Here, it passes both before and after.

@dashpole
Copy link
Copy Markdown
Contributor

How would this be tested? Enabled is a performance improvement to avoid computing attributes when we know in advance the metric will be dropped. Using enabled or not shouldn't be a behavioral change, right?

@dashpole
Copy link
Copy Markdown
Contributor

Might be able to demonstrate it with a benchmark when a no-op meterprovider is used?

@NesterovYehor
Copy link
Copy Markdown
Contributor Author

I added a unit test because another reviewer asked for tests. it basically just verifies we don’t call Add/Record when an instrument reports Enabled(ctx)==false.

If you’d prefer, I can drop the unit test and add a benchmark instead since this is mainly a perf improvement. What would you rather have?

@dashpole
Copy link
Copy Markdown
Contributor

Nice. I didn't think of that, and that works for me.

@NesterovYehor
Copy link
Copy Markdown
Contributor Author

Awesome, thanks! I’ll fix the remaining lint issues and update the PR.

@MrAlias MrAlias merged commit 1227752 into open-telemetry:main Feb 9, 2026
31 checks passed
@MrAlias MrAlias added this to the v1.41.0 milestone Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants