Mortem supports optional AES-256-GCM encryption for event payloads. When you set a master key, the SDK encrypts every event payload before it is buffered and sent to the ingest service. The encrypted ciphertext is what Mortem stores — the plaintext never leaves your process unencrypted. Encryption is opt-in. If you do not set a master key, payloads are stored as plain JSON and the feature has no effect on the rest of the SDK.Documentation Index
Fetch the complete documentation index at: https://docs.mortemlabs.com/llms.txt
Use this file to discover all available pages before exploring further.
Generate a master key
Use OpenSSL to generate a cryptographically random 256-bit key encoded as base64:Set the environment variable
.env.local
MORTEM_MASTER_KEY automatically when it is set in process.env. You do not need to pass the key anywhere in code for the SDK’s built-in instrumentation to encrypt payloads.
How encryption works
WhenMORTEM_MASTER_KEY is present and valid, the SDK uses AES-256-GCM with a randomly generated 12-byte IV for every payload. The encrypted result is a structured object:
Encrypt and decrypt manually
The SDK exportsencryptPayload and decryptPayload for cases where you want to encrypt payloads yourself before passing them to beginEvent or eventBuilder.complete.
encryptPayload
undefined if the key is missing, invalid (not exactly 32 bytes after base64 decoding), or if encryption fails for any reason.
decryptPayload
undefined if the key is wrong, the ciphertext has been tampered with (GCM tag mismatch), or if decryption fails for any other reason.
Function signatures
Encrypts a JSON-serializable value. Pass the base64 master key explicitly, or omit it to use
process.env.MORTEM_MASTER_KEY. Returns undefined on any failure.Decrypts an
EncryptedPayload object. Pass the base64 master key explicitly, or omit it to use process.env.MORTEM_MASTER_KEY. Returns undefined on any failure.Example: encrypt a custom event payload
When
MORTEM_MASTER_KEY is set and valid, the SDK automatically encrypts event payloads in the built-in instrumentation wrappers. You only need to call encryptPayload manually when constructing payloads yourself before passing them to beginEvent or complete.Security checklist
- Generate the key with
openssl rand -base64 32— do not use passwords or weak entropy sources. - Store the key in your secrets manager or deployment platform, not in committed files.
- Never rotate the key without first backing up and decrypting all existing payloads you care about.
- The key is exactly 32 bytes (256 bits) after base64 decoding. An incorrectly sized key causes
encryptPayloadto returnundefinedsilently.