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

converting 'severity' field to an integer results in loss of granularity #22

Open
gorkem2020 opened this issue Dec 31, 2023 · 2 comments

Comments

@gorkem2020
Copy link
Contributor

Under the create_frame function, we are converting 'levelno' field to 'severity' by dividing by 10 and then converting to integer, as in below;

frame['severity'] = int(r['levelno'] / 10)

in doing so we are losing custom log levels created by the user. For example I have additional 2 log levels that have levelno of 25 and 35. These are converted to 2 and 3 respectively. This makes it impossible to query using something like severity>25 when I want to get the events that have levelno greater than 25.

I guess we cannot do something like below, which will break compatibailty who are using severity as is

frame['severity'] = r['levelno']

so maybe we can add a field?

frame['level_no'] = r['levelno']

this will enable to query with finer granularity.

I did not want to create a PR because I thought there must be a reason why this has not been already added.

Or even better idea; why not pass a dict which has the python-to-logtail mappings to the handler and frame can be created using this mapping? something like below;

# frame.py
def create_frame(record, message, context, include_extra_attributes=False, mapping: dict = None):
    ... # omitted code
    
    if mapping:
        for k, v in mapping.items():
            frame[v] = getattr(record, k)

    ... # omitted code
    return frame

@curusarn
Copy link
Contributor

curusarn commented Feb 4, 2024

Hi @gorkem2020,

Thank you for reaching out! I appreciate your patience here.

The severity is divided by 10 for historical reasons. We don't want to break backward compatibility by changing the meaning of severity.

Allowing customizing how the frame is created is a good idea.
I wouldn't go as far as passing entirely new mapping for all fields.

I would instead solve the issue with levels and severity specifically.
What do you think about allowing to pass a dict that maps "levelno" to "levels"?
This way, the "severity" field would stay unchanged, but you could map 25 and 35 to any level you want.
Would that work for you? 🙏

@gorkem2020
Copy link
Contributor Author

Hello @curusarn,

Passing a mapping dict to customize fields was meant to be seperate idea not related to severity. In general, it would be very useful to control precisely what is being sent and how it is constructed.

And, yes "levels" would work. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants