Skip to content

Conversation

VictorRibeiroLima
Copy link
Contributor

This PR adds special handling for error values in the slog adapter to ensure their error messages are used.

Previously, when sending an error as an Any value, it would be converted into an empty map[string]interface{}. This caused the value to be ignored by Axiom.

To address this, I added a special case to handle values that are instances of error, similar to how the std JSONHandler handles them.

i get that this somewhat breaks the flow of the code and the user can easily resolve this by explicitly writing:

slog.String("error",err.Error())

instead of

slog.Any("Error",err)

But in my option this gets annoying to do pretty quick

There is an argument to be made that the entire addAttrToEvent function should be rewritten IF the intention is to replicate the behavior of the std JSONHandler.

Witch in my understanding kinda is because a JSON in what axiom is getting,but i can be wrong and that's ok

That said, this PR focuses on addressing the specific issue of handling error values, and a broader rewrite could be considered as a separate improvement.

Copy link
Collaborator

@lukasmalkmus lukasmalkmus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

Sorry for being late to the party.

I believe this is an absolutely legitimate fix.

Personally, I usually have an slogx package with my projects and one of the exported functions is as simple as:

func Err(err error) slog.Attr {
        return slog.Any("error", err.Error())
}

But given this is a common pitfall and the stdlib implementation handles it explicitly, as well, I can totally accept this fix.

Cheers and thanks for your contribution!

@lukasmalkmus lukasmalkmus enabled auto-merge (rebase) August 19, 2025 14:45
@lukasmalkmus lukasmalkmus force-pushed the use-error-message-as-value-on-slog-adapter branch from 92785e5 to 060fd18 Compare August 19, 2025 14:45
@lukasmalkmus lukasmalkmus merged commit 602c469 into axiomhq:main Aug 19, 2025
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants