bag_has_key
This page explains how to use the bag_has_key function in APL.
Use the bag_has_key
function in APL to check whether a dynamic property bag contains a specific key. This is helpful when your data includes semi-structured or nested fields encoded as dynamic objects, such as JSON-formatted logs or telemetry metadata.
You often encounter property bags in observability data where log entries, spans, or alerts carry key–value metadata. Use bag_has_key
to filter, conditionally process, or join such records based on the existence of specific keys, without needing to extract the values themselves.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
Usage
Syntax
Parameters
Name | Type | Description |
---|---|---|
bag | dynamic | A dynamic value representing a property bag (e.g., JSON object). |
key | string | The key to check for within the property bag. |
Returns
Returns a bool
value:
true
if the specified key exists in the property bagfalse
otherwise
Use case examples
Use bag_has_key
to filter log entries that include a specific metadata key embedded in a dynamic object.
Query
Output
_time | id | method | uri | status | metadata |
---|---|---|---|---|---|
2025-05-27T12:30Z | u123 | GET | /login | 200 | {‘source’:‘cdn’,‘env’:‘prod’} |
2025-05-27T12:31Z | u124 | POST | /cart/checkout | 500 | {‘source’:‘cdn’,‘env’:‘prod’} |
The query filters logs where the synthetic metadata
bag includes the key 'env'
.
Use bag_has_key
to filter log entries that include a specific metadata key embedded in a dynamic object.
Query
Output
_time | id | method | uri | status | metadata |
---|---|---|---|---|---|
2025-05-27T12:30Z | u123 | GET | /login | 200 | {‘source’:‘cdn’,‘env’:‘prod’} |
2025-05-27T12:31Z | u124 | POST | /cart/checkout | 500 | {‘source’:‘cdn’,‘env’:‘prod’} |
The query filters logs where the synthetic metadata
bag includes the key 'env'
.
Use bag_has_key
to filter spans that include specific dynamic span attributes.
Query
Output
_time | trace_id | span_id | [‘service.name’] | kind | attributes |
---|---|---|---|---|---|
2025-05-27T10:02Z | abc123 | span567 | frontend | client | {‘user’:‘alice’,‘feature_flag’:‘beta’} |
The query selects spans with dynamic attributes
bags containing the 'feature_flag'
key.
Use bag_has_key
to identify HTTP logs where the request metadata contains sensitive audit-related keys.
Query
Output
_time | id | uri | status | audit_info |
---|---|---|---|---|
2025-05-27T13:45Z | u999 | /admin/delete | 403 | {‘action’:‘delete’,‘reason’:‘admin_override’} |
The query returns only logs where the audit_info
bag includes the 'reason'
key, indicating administrative override events.