-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logfire.metric_gauge()
#153
Conversation
Deploying logfire-docs with Cloudflare Pages
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
logfire/_internal/metrics.py
Outdated
except ImportError: # pragma: no cover | ||
Gauge = None | ||
GAUGE_IMPORTED = False # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why this is better than Gauge = None
, and it requires 2 extra type-ignores.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually avoids the type ignore on the type hint of the metric_gauge
method - but I just had an idea on how to avoid one more.
I'll eat and come back to this.
logfire/_internal/metrics.py
Outdated
def create_gauge( | ||
self, | ||
name: str, | ||
unit: str = '', | ||
description: str = '', | ||
): # pragma: no cover | ||
) -> _Gauge: # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the problem.
logfire/_internal/metrics.py
Outdated
@@ -353,7 +361,7 @@ def _create_real_instrument(self, meter: Meter) -> UpDownCounter: | |||
return meter.create_up_down_counter(self._name, self._unit, self._description) | |||
|
|||
|
|||
if Gauge is not None: # pragma: no branch | |||
if Gauge is not None: # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely this is covered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I was just trying to readd what was previously there.
from opentelemetry.metrics import _Gauge | ||
|
||
Gauge = _Gauge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, pyright treats this differently to import _Gauge as Gauge
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because we need a return type for create_gauge
in this file, and without this line, Gauge can either be _Gauge
or None
. Since it can be either, then the type of create_gauge
is wrong.
That's why the use of another variable - the type checker will know that Gauge
is _Gauge
.
Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
Thanks I needed this the other day 😆 |
Checklist