Skip to content

Conversation

@NesterovYehor
Copy link

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

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 82.14286% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.7%. Comparing base (f740ea8) to head (9458d23).
⚠️ Report is 14 commits behind head on main.

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

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #7813     +/-   ##
=======================================
- Coverage   86.1%   81.7%   -4.5%     
=======================================
  Files        302     304      +2     
  Lines      22046   23247   +1201     
=======================================
+ Hits       18991   18998      +7     
- Misses      2675    3859   +1184     
- Partials     380     390     +10     
Files with missing lines Coverage Δ
...log/otlploghttp/internal/observ/instrumentation.go 93.6% <82.1%> (-6.4%) ⬇️

... and 10 files with indirect coverage changes

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

@dmathieu
Copy link
Member

Could you add tests?

@NesterovYehor
Copy link
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
Member

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

@dmathieu
Copy link
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
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
Contributor

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

@NesterovYehor
Copy link
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
Contributor

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

@NesterovYehor
Copy link
Author

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

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.

4 participants