-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support arbitrary value type in fctx metadata #38
Comments
Hey, thanks for opening an issue! It's good to see some feedback about the design here as I went back and forth about this for a while with user testing and eventually settled on strings. The reason for this is that string values are just easier to serialise and play nicer with the kinds of tooling this library was built to integrate with (structured logging, tracing and context-rich HTTP responses for errors) The issue with complex structures and nested data is it's difficult to represent and index. In production, this library is often wired up to Graylog, Datadog, Kibana etc. as well as Jaeger tracing and other otel tracing tools. They usually prefer flattened structures for indexing and rendering (though this isn't a requirement on every system.) There's definitely a question to be made around where this responsibility should live, as it can often be annoying to turn the data you have into strings at the call site of fctx.WithMeta(ctx, "key", fmt.Sprint(value)) I think it would make sense to change this to However, one benefit of enforcing strings only at the call site is that your error handling code is much simpler, there doesn't need to be any reflection or encoding/serialisation of these values which may interrupt a very important area of the application: error reporting. |
Thanks for the insights. Since I've always worked in teams with DevOps, they usually take care of these things, I was able to filter the logs no matter what structures of the data I logged (one exception was when I wanted to filter a number field using greater than or less than operators), so I didn't think of indexing at all when asking.
Another way is to add a new function like |
WithData could be a nice non-breaking approach, I like it! I would likely stick with a design like https://pkg.go.dev/log/slog#Debug where it's just
|
I always prefer to have type-safe, but since this is for debugging/logging purposes, I think |
I hear you, type safety is usually my top priority, but ergonomics of the API is also important - if it's awkward to use, fewer people will be inclined to use it. I find this with Zap, it's a great logger but typing |
Hi, thanks for the library.
While testing the library, I see that
fctx
only supportsstring
values. If I want to add a struct to the metadata, I'll have to either stringify it (but the log will be hard to read when logged using a structured logger) or add each field manually (which is painful if the struct has a lot of fields).So I want to ask if there is any reason why
fctx
only supportsstring
values, and if it is possible to make it support arbitrary-type (interface{}
) values instead.The text was updated successfully, but these errors were encountered: