Langfuse JS/TS SDKs
    Preparing search index...

    Function serializeMetadataValue

    • Internal

      Serializes an observation metadata value into the JSON string written to its langfuse.observation.metadata.<key> span attribute.

      Every value is JSON-encoded, strings included ("3" becomes "\"3\""), so the server can tell the string "3" from the number 3 and the string '{"a":1}' from the object { a: 1 }. Bigints, also nested ones, become JSON numbers if they are in the JS-safe integer range (10n becomes "10") and JSON strings of their decimal digits otherwise (2n ** 60n becomes "\"1152921504606846976\""), matching the Python SDK. NaN and ±Infinity, also nested, become the JSON strings "NaN", "Infinity" and "-Infinity" instead of null, also matching the Python SDK. A value that fails to serialize becomes the JSON string "\"<failed to serialize>\"". null, undefined, functions and symbols return undefined and are not written.

      Parameters

      • value: unknown

        Metadata value to serialize

      Returns undefined | string

      JSON string, or undefined if the value is not written