-
Notifications
You must be signed in to change notification settings - Fork 96
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
patch(js): utf-8 encode multipart parts #1487
base: main
Are you sure you want to change the base?
Conversation
js/src/client.ts
Outdated
@@ -1144,10 +1145,11 @@ export class Client implements LangSmithTracingClientInterface { | |||
const fields = { inputs, outputs, events }; | |||
// encode the main run payload | |||
const stringifiedPayload = stringifyForTracing(payload); | |||
const valueBytes = encoder.encode(stringifiedPayload).length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Shouldn't/can't stringifyForTracing
already return a properly encoded string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is necessary. The stringify function itself doesn't actually encode anything. It converts the js object into a JSON string.
JSON.stringify() produces a JavaScript string, which is always UTF-16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but could/should our stringifyForTracing
wrapper serialize it as a utf-8 string?
Then we could pass it directly into the Blob constructor?
I think that may save us some bugs in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don’t need to parse a length=... parameter (just application/json), then JSON.stringify(...) should be sufficient. The browser will treat it as a UTF-8 text blob, and the server sees it as JSON with no mismatch in length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I can add an explicit encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
No description provided.