Formula - ContextKey
Section titled “ Formula - ContextKey”The contextKey Formula function returns the key names (not the values) of the Message Context properties of the Log Event whose key matches a regular expression.

Animated walkthrough: on the Message Context of the Order Received event of order ORD-10005 in the Order-to-Cash demo, contextKey(regex('^Customer')) returns the key names CustomerId and CustomerName, not their values. Nested in count, the same call returns 2.
Syntax
Section titled “ Syntax”contextKey(regex('Key pattern'))Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
regex('Key pattern') |
Yes | A regex that is matched against the context key names. |
Returns
Section titled “Returns”Every matching key name, one value per key. Duplicates are collapsed (see Formula language rules). When no key matches, nothing is returned. To get the values of the matching context keys instead, use context with the same regex(...) argument.
Examples
Section titled “ Examples”Example 1: List the order keys in the context
Section titled “Example 1: List the order keys in the context”| Key | Value |
|---|---|
| Order#123 | OK |
| Order#456 | OK |
| Order#789 | Fail |
Formula
Section titled “Formula”contextKey(regex('Order#.*'))Result
Section titled “Result”Order#123Order#456Order#789
Each key that matches Order#.* is returned as its own unique match.
contextKeyreturns the whole key name whenever the pattern matches part of it. The pattern matches anywhere in the key name unless you anchor it: use^Order[#]to match only keys that start withOrder#.- In Formula regular expressions
#starts a comment, so'Order#.*'in the example really runs as'Order'. It works here because every key starts withOrder; write[#]or\#when the#matters. See Formula language rules. - Combine with count to get the number of matching keys, for example
count(contextKey(regex('Order#.*'))).