Skip to content
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

🔄 synced file(s) with logfire-ai/logfire-python-source #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions logfire/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .uploader import Uploader
from .frame import create_frame

DEFAULT_HOST = 'https://in.logfire.sh'
DEFAULT_HOST = "https://in.logfire.ai"
DEFAULT_BUFFER_CAPACITY = 1000
DEFAULT_FLUSH_INTERVAL = 1
DEFAULT_RAISE_EXCEPTIONS = False
Expand All @@ -17,16 +17,18 @@


class LogfireHandler(logging.Handler):
def __init__(self,
source_token,
host=DEFAULT_HOST,
buffer_capacity=DEFAULT_BUFFER_CAPACITY,
flush_interval=DEFAULT_FLUSH_INTERVAL,
raise_exceptions=DEFAULT_RAISE_EXCEPTIONS,
drop_extra_events=DEFAULT_DROP_EXTRA_EVENTS,
include_extra_attributes=DEFAULT_INCLUDE_EXTRA_ATTRIBUTES,
context=DEFAULT_CONTEXT,
level=logging.NOTSET):
def __init__(
self,
source_token,
host=DEFAULT_HOST,
buffer_capacity=DEFAULT_BUFFER_CAPACITY,
flush_interval=DEFAULT_FLUSH_INTERVAL,
raise_exceptions=DEFAULT_RAISE_EXCEPTIONS,
drop_extra_events=DEFAULT_DROP_EXTRA_EVENTS,
include_extra_attributes=DEFAULT_INCLUDE_EXTRA_ATTRIBUTES,
context=DEFAULT_CONTEXT,
level=logging.NOTSET,
):
super(LogfireHandler, self).__init__(level=level)
self.source_token = source_token
self.host = host
Expand All @@ -40,10 +42,7 @@ def __init__(self,
self.raise_exceptions = raise_exceptions
self.dropcount = 0
self.flush_thread = FlushWorker(
self.uploader,
self.pipe,
self.buffer_capacity,
self.flush_interval
self.uploader, self.pipe, self.buffer_capacity, self.flush_interval
)
if self._is_main_process():
self.flush_thread.start()
Expand All @@ -56,7 +55,12 @@ def emit(self, record):
if self._is_main_process() and not self.flush_thread.is_alive():
self.flush_thread.start()
message = self.format(record)
frame = create_frame(record, message, self.context, include_extra_attributes=self.include_extra_attributes)
frame = create_frame(
record,
message,
self.context,
include_extra_attributes=self.include_extra_attributes,
)
try:
self.pipe.put(frame, block=(not self.drop_extra_events))
except queue.Full:
Expand All @@ -66,4 +70,4 @@ def emit(self, record):
pass
except Exception as e:
if self.raise_exceptions:
raise e
raise e
19 changes: 11 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"

[project]
name = "logfire-python"
version = "0.0.7"
description = "Logfire.sh client library"
version = "0.0.9"
description = "Logfire.ai client library"
readme = "README.md"
authors = [{ name = "Logfire", email = "support@logfire.sh" }]
authors = [{ name = "Logfire", email = "support@logfire.ai" }]
license = { file = "LICENSE" }
classifiers = [
"Intended Audience :: Developers",
Expand All @@ -27,13 +27,16 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
keywords = ["api", "logfire", "logging", "client"]
dependencies = [
"requests",
"msgpack",
]
dependencies = ["requests", "msgpack"]

[project.optional-dependencies]
dev = ["coverage>=3.7.1", "httpretty>=0.9.4", "nose>=1.3.7", "unittest2>=0.8.0", "mock>=1.0.1"]
dev = [
"coverage>=3.7.1",
"httpretty>=0.9.4",
"nose>=1.3.7",
"unittest2>=0.8.0",
"mock>=1.0.1",
]

[project.urls]
Homepage = "https://github.com/logfire-sh/logfire-python"