-
Notifications
You must be signed in to change notification settings - Fork 45
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-api
#268
Add logfire-api
#268
Conversation
Deploying logfire-docs with
|
Latest commit: |
8f42fe8
|
Status: | ✅ Deploy successful! |
Preview URL: | https://c57b71f1.logfire-docs.pages.dev |
Branch Preview URL: | https://logfire-api.logfire-docs.pages.dev |
class Logfire: | ||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
if logfire_installed: | ||
return logfire.Logfire(*args, **kwargs) |
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.
You need to add methods like span()
which return something functionally consistent with logfire.span()
.
And also.
def __getattr__(self, attr):
return MagicMock()
We perhaps we shoud also implement all the know methods with a signature of (*args, **kwargs) -> None
, then leave this as a fallback.
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.
Returning a MagicMock outside of tests seems bad IMO. Can we follow the opentelemetry-api way of doing this?
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
30c6e95
to
d42ad35
Compare
@alexmojaki do you know why those tests are failing? 🤔 There are different tests failing depending on the Python version... |
- name: Publish logfire to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
||
- name: Build logfire-api | ||
run: rye build | ||
working-directory: logfire-api/ | ||
|
||
- name: Publish logfire-api to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
packages-dir: logfire-api/ |
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 know why. How new/consistent are they? |
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 looks awesome.
Thank you!
It seems like the idea is to generate stubs / API files from all of logfire. IMO this is unnecessary. The use case for a try:
import logfire
except ImportError:
logfire = None
def info(...) -> None:
if logfire:
logfire.info(...)
def span(...) -> ?:
if logfire:
return logfire.span(...)
return ? I leave |
Since it's automated, I don't see the issue.
This was already discussed. Also, it was the first question before I started implementing it.
If it were few objects, yes... But for every object on |
My point is that libraries instrumenting with logfire don't need e.g. |
See https://github.com/search?q=repo%3AMirascope%2Fmirascope%20instrument_openai&type=code |
Let's go ahead with this, I don't really see the point of putting effort into limiting the type hint coverage. Let's go ahead with this. @adriangb we have to make some decisions on calls without the whole team present, if you don't join calls you have to accept some decisions are made without you. |
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
@alexmojaki Anything else, or can I merge? I've applied all your comments. |
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.
Thanks!
This PR creates the
logfire-api
package.We'll have to remove rye - or it needs to work with editable mode, otherwise developers need to remember to remove the
.venv
and runrye sync --no-lock
every time they perform changes.The approach here is simple - the
logfire-api/logfire_api/__init__.py
contains all the runtime logic, and the type hints are generated from themake generate-stubs
command - we have a lot ofpyi
files.There are two tests:
logfire
andlogfire_api
have the same objects in the__init__.py
.__init__.pyi
type compliant.