-
Notifications
You must be signed in to change notification settings - Fork 926
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
Document how to properly use Logfire in Kedro #3978
Comments
FTR Logfire is leaving beta soon https://pydantic.notion.site/Pydantic-Logfire-Pricing-f719ee768d10457f970f78eedbff976e |
How did you disable rich handler? If I remove
|
https://noklam.github.io/blog/posts/kedro_logfire/2024-12-01-kedro-with-logfire.html I guess the spike is done? 🙃 @noklam do you have any more thoughts you want to add? |
@astrojuanlu I didn't spend too much time on The code is weird because most of the time Otel use a context manager (kedro) Nok_Lam_Chan@ spaceflights_pandas % cat settings.py
"""Project settings. There is no need to edit this file unless you want to change values
from the Kedro defaults. For further information, including these default values, see
https://docs.kedro.org/en/stable/kedro_project_setup/settings.html."""
# Instantiated project hooks.
# For example, after creating a hooks.py and defining a ProjectHooks class there, do
# from spaceflights_pandas.hooks import ProjectHooks
# Hooks are executed in a Last-In-First-Out (LIFO) order.
import time
from kedro.framework.hooks import hook_impl
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.context import attach, detach, get_current
# Acquire a tracer
tracer = trace.get_tracer("kedro_app.tracer")
# Set up tracing with service name 'kedro_app'
resource = Resource.create({"service.name": "kedro_node_trace"})
trace.set_tracer_provider(TracerProvider(resource=resource))
tracer = trace.get_tracer(__name__)
# Configure OTLP exporter to send traces to the collector
otlp_exporter = OTLPSpanExporter(endpoint="localhost:4317", insecure=True)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(otlp_exporter))
class OtelHook:
@hook_impl
def before_node_run(self):
self.node_span = tracer.start_as_current_span("trace")
self.node_span.__enter__()
print("Send something to Otel before node run")
time.sleep(1)
print("sleep for 1 sec")
@hook_impl
def after_node_run(self):
with tracer.start_as_current_span("after node run trace") as span:
print("Send something to Otel after node run")
time.sleep(0.5)
print("sleep for 0.5 sec")
self.node_span.__exit__(None, None, None) # call __exit__ for @contextmanager
HOOKS = (OtelHook(),) |
Description
I was trying to use Logfire in Kedro, and it mostly worked. However, the results aren't optimal.
Context
Steps to Reproduce
spaceflights
projectlogfire.configure()
insettings.py
(for lack of a better place)logfire
handler to the logging. For example:Expected Result
The logs should display flawlessly on the Logfire web UI.
Actual Result
Note
The shortcodes shouldn't leak any longer, see below
With this configuration, the shortcodes for rich coloring "leak" onto the logs:
(notice the
[dark_orange]
shortcodes)If I disable the
rich
handler inlogging.yml
, the CLI output changes but the result on Logfire UI is the same.And finally, I tried
rich.uninstall()
but it turns outlogfire
depends onrich
🙃On top of that, I observe this big fat warning:
Apart from that
LOGFIRE_IGNORE_NO_CONFIG
, is there a better way to achieve this?Your Environment
pip show kedro
orkedro -V
): 0.19.6python -V
): 3.11.9The text was updated successfully, but these errors were encountered: