Closed lironesamoun closed 3 months ago
It sounds like you wrote code like this:
try:
...
except Exception as e:
logfire.exception(e)
logfire.msg_template
refers to that first argument of logfire.exception
, it has to be a string. You can write logfire.exception("Failed to do jobs")
and the exception itself will be picked up automatically.
Actually, I don't use logfire.exception(e) unless I'm mistaken.
class JobsNumberMinimumException(DataQualityException):
def __init__(self, message=""):
super().__init__(message)
class DataQualityException(Exception):
"""
Base exception for data quality issues.
"""
def __init__(self, message: str):
self.message = message
super().__init__(self.message)
if len(jobs) <= self.number_minimum_jobs
raise JobsNumberMinimumException(f"not enough jobs: {len(jobs)} over "
f"the requirements needed: {self.number_minimum_jobs}")
Inside JobsNumberMinimumException, it's a string.
But where's the code where you used logfire?
So far, I've juste integrated Logfire with the standard library logging module (logging). It works fine for most of my process but on this case it works until I get to the exception level, the code above.
OK, this makes sense. There must be some code doing this:
import logging
logger = logging.getLogger(...)
try:
...
except Exception as e:
logger.<log method>(e)
This is a bug that we should fix ASAP by converting log_record.msg
to a string in the logging integration. In the meantime, if you can identify those logging calls, you can ensure that they receive a string instead to resolve the error.
In fact it should be noted that even after the fix it would be best to ensure that you pass a string where possible describing the general problem. Otherwise it will be hard when viewing/querying logs to group together all logs coming from this location if they have different error messages, and it will also be hard to distinguish between similar exceptions being logged from different places.
I'll take a look but I don't think that I have any logger.
Thank for your recommendation.
Do you think that this string as an example is a bad practice: _f"not enough jobs: {len(jobs)} over the requirements needed: {self.number_minimumjobs}" ?
I'll take a look but I don't think that I have any logger.(e) inside my except. That's why I'm confused especially for my case where I don't see one.
It's probably inside a library somewhere.
Do you think that this string as an example is a bad practice: _f"not enough jobs: {len(jobs)} over the requirements needed: {self.number_minimumjobs}" ?
No it's not bad practice, but also it makes no difference to logfire.
New version of the SDK should fix this.
Description
On my code, I raise a custom exception if a condition is not met.
When I run my code, the exception is raised and I got an error from logfire.
not enough jobs: 20 over the requirements needed: 50 Invalid type JobsNumberMinimumException for attribute 'logfire.msg_template' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
Following by this
And on the "Live" Section, I don't see any exception or things related to this.
Any insights ?
Python, Logfire & OS Versions, related packages (not required)