Make Telemetry API log record type generic#1098
Make Telemetry API log record type generic#1098raphael-theriault-swi wants to merge 2 commits intoaws:mainfrom
Conversation
Managed instances will not require semver breaking. We are a long ways off from release 2.x. With that in mind, do you have any thoughts about a semver-safe way to do it? I guess we just add a new API, deprecate the old, but allow continuing to use old until next release version? |
|
(Also, thanks for picking this up! This is definitely in an awkward spot right now) |
|
I'm thinking maybe an opt-in feature to enable the generic might be more elegant ? Then the feature can just be removed when a future |
|
The opt-in feature will work, but it seems a bit confusing to have a feature that shifts runtime behavior like this, especially for such a limited feature scope. Let me get a temperature check from the other maintainers on this and follow up. |
|
Coming back to this - Unfortunately a feature flag doesn't escape semver constraints, even if it is opt in (given feature unification). Per cargo:
And then, any introduction of generics that don't have an default inference available, is breaking. Which, unfortunately, the function signatures EDIT: Hold on a sec, are those just methods on extension? We might be able to work around it by hoisting it to be struct-wide, with a default. |
|
Yeah, it seems to be working ok with an extra generic on (Maybe there is a way to do it without the PhantomData as well?) And then we can hoist the telemetry where clause back to the struct definition: |
|
And then, it's unpleasant for the user to have to specify all the generic parameters as But, seem to have consistent inference if we update And then you can specify it in your handler that this function receives: (Or not, and then it defaults to String, and stays backwards compatible) |
|
What do you think about the proposed API @raphael-theriault-swi ? I think we should flip the generic default next major version, but that might be a ways off. (At which point, your untagged Are these ergonomics adequate in the meantime? No feature flags at least? Probably a small |
|
The thing is that adding the default generic type to the enum itself is technically a breaking change the moment you try to use an enum literal of a variant that doesn't include the generic. enum Generic<T = &'static str> {
Generic(T),
Fixed(&'static str),
}
fn main() {
let generic = Generic::Generic("inference succeeds");
let fixed = Generic::Fixed("inference fails");
} |
📬 Issue #, if available: #977
✍️ Description of changes:
This adds a generic type parameter to
LambdaTelemetryRecordfor logs to support structured JSON logs. I initially tried to implement theRawValuenewtype based solution suggested in #977, but it turns out you can't useRawValuewithin#[serde(flatten)].This is a breaking change given it introduces a new generic parameter, but IMO it's better than introducing a whole new set of duplicate types, especially given supporting managed instances may already require breakage soon.
Unlike suggested in #977, this doesn't lock users into either supporting text or JSON logs at compile time, since they can just use an untagged enum:
I also opted against adding a new struct for JSON logs since they don't have a fixed schema, some extension authors might want to use
serde_json::Value, some might want a more specialized type.🔏 By submitting this pull request
cargo +nightly fmt.cargo clippy --fix.