Tinkex.Telemetry.Reporter.Serializer (Tinkex v0.3.4)

View Source

Event serialization and sanitization for telemetry.

Handles:

  • Converting typed event structs to wire format maps
  • Sanitizing data for JSON serialization (atoms to strings, etc)
  • Platform detection

Summary

Functions

Build a telemetry request payload from events and state.

Convert a typed event struct to a wire format map.

Get the platform string (os_type/os_flavor).

Sanitize a value for JSON serialization.

Functions

build_request(events, state)

@spec build_request(list(), map()) :: map()

Build a telemetry request payload from events and state.

Returns a map with session_id, platform, sdk_version, and serialized events.

event_to_map(event)

@spec event_to_map(struct() | map()) :: map()

Convert a typed event struct to a wire format map.

Delegates to the appropriate to_map/1 function based on event type.

platform()

@spec platform() :: String.t()

Get the platform string (os_type/os_flavor).

Example: "unix/linux"

sanitize(struct)

@spec sanitize(term()) :: term()

Sanitize a value for JSON serialization.

Converts:

  • Structs to maps (via Map.from_struct)
  • Atoms to strings
  • Lists recursively
  • Maps recursively (keys and values)
  • Numbers, binaries, booleans, nil - pass through
  • Everything else - inspect