Files
kumomta/docs/reference/message/set_meta.md
T
Wez Furlong b8310da8be docs: add warning about logging headers
TL;DR: you can easily halve your system performance by logging headers
vs. logging meta.

This is one of those things that is easy to overlook or forget,
but: whenever you need to operate on the message data, rather
than its metadata, the aggregate cost is high.

In this case, we were recently troubleshooting a system where
the CPU was bogged down and we traced it to the logging configuration: a
number of message headers were being logged in a configuration that
made heavy use of throttles and limits in its traffic shaping, and
thus had a large number of Delayed and TransientFailure events being
written to the logs.

When logging headers, each one of those events requires loading
the message from the spool and parsing out the headers.  When the
average message size is ~100KB this imposes a notable overhead
on the CPU and IO utilization of the system.

What we recommend instead of logging headers directly is capturing
the information that you want to log into the message metadata
at the time that the message is received.

The message meta is usually already loaded, but is also typically
much smaller and easier to decode than the full message content
in the cases where it is not loaded.

As a result, it is much cheaper to log meta than to log headers.

This commit adds some warnings and cross links to help folks
be aware of this, and to generally navigate related meta and logging
topics more easily via tags.
2025-04-25 05:52:44 -07:00

1.5 KiB

tags
tags
meta

message:set_meta(KEY, VALUE)

Messages are associated with some metadata. You can think of this metadata as being equivalent to a JSON object.

The set_meta method allows you to set a field of that object to a value that you specify.

You can assign any value that is serializable as a JSON:

-- set foo='bar', a string value
msg:set_meta('foo', 'bar')

-- set foo=123, a numeric value
msg:set_meta('foo', 123)

-- set foo=true, a boolean value
msg:set_meta('foo', true)

-- set foo={key="value"}, an object value
msg:set_meta('foo', { key = 'value' })

You can retrieve a metadata value via message:get_meta.

Pre-defined meta values

The following meta values are unique to the message scope:

<style> table tbody tr td:nth-of-type(2) { white-space: nowrap; } </style>
Scope Name Purpose Since
Message queue specify the name of the queue to which the message will be queued. Must be a string value.
Message tenant specify the name/identifier of the tenant, if any. Must be a string value.
Message campaign specify the name/identifier of the campaign. Must be a string value.
Message routing_domain Overrides the domain of the recipient domain for routing purposes. {{since('2023.08.22-4d895015', inline=True)}}

!!! Note Additional metadata is available in the message scope that is copied in from the connection scope, for a full list of all available metadata, see the Predefined Metadata page.