Skip to content

Do the TelemetryAPI records support JSON record fields? #977

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

Open
mheffner opened this issue Apr 9, 2025 · 1 comment
Open

Do the TelemetryAPI records support JSON record fields? #977

mheffner opened this issue Apr 9, 2025 · 1 comment

Comments

@mheffner
Copy link

mheffner commented Apr 9, 2025

According to the TelemetryAPI docs, if you're using a more recent schema version than "2022-12-13", the record field of function and extension logs may be a string OR a JSON record.

From the code it would appear that these only support the string records. Do these need to be updated to something like serde_json::Value to handle both cases?

pub enum LambdaTelemetryRecord {
/// Function log records
Function(String),
/// Extension log records
Extension(String),

Thanks!

@jlizen
Copy link

jlizen commented May 6, 2025

Looks like you're right! Feel free to modify this issue into a feature request, or take a stab at implementing it!

One way to deal with this might be to encode it at the type level via a generic (or more likely a separate struct, since adding a generic to LambdaTelemetryRecord would cause semver breakage). And then the caller could just specify that in their handler if they want to receive processed JSON. The downside of that approach though is that it would be effectively hardcoding a choice around log format, whereas advanced logging controls are designed to be changeable in console, etc. I guess probably the caller could write two different handlers and choose between them based on the same ENV, but it's all pretty klunky.

Maybe it would be better to newtype both of the inner record types and offer a .json() method on them that lazily attempts to deserialize if invoked? That keeps the handler signatures simple but still lets the caller apply context around whether a given record format is set or not?

You could MAYBE hack something together with a new typed inner enum that has an internally tagged variant for serde that uses one of the known json field names, and a #[serde(other)] tag on the plain variant? Except that would force callers to match on them all the time, and also that would be semver breakage.

I think probably .json() would be simplest to implement + less terrible to maintain / not too unergonomic for callers...?

Just sharing my perspective! (Not a maintainer / not offering to implement this)

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