Developers configure metadata in your application. See Tracing setup for setup instructions.
Setting metadata
There are two ways to attach metadata to traces: viaexperimental_telemetry.metadata on the model call, and via the span() function’s metadata option when grouping traces.
Via telemetry metadata
Pass metadata inexperimental_telemetry on the model call. AgentMark attaches these key-value pairs to the resulting generation span:
Via the span function
Pass metadata when creating a trace group. The metadata lives on the trace’s root span and powers trace-level filtering:SpanOptions.metadata has the type Record<string, string>, so values must be strings. Convert numbers, booleans, and other types before passing.
Filtering by metadata
In the AgentMark Dashboard, metadata keys are auto-discovered from your trace data. You can filter traces by any metadata key that appears in your data. To filter by metadata:- Navigate to the Traces tab in the Dashboard.
- Open the filter dropdown.
- Look for entries prefixed with Metadata: followed by the key name (for example, “Metadata: environment”).
- Select the key you want to filter by.
- Choose an operator and enter a value.
- equals / notEquals: exact match or no match on the value
- contains / notContains: value includes or excludes the specified substring
- starts with: value begins with the specified string
- ends with: value ends with the specified string
- exists: the key is present, regardless of value
does not exist: the key isn’t present on the trace
Metadata in the trace detail
When viewing an individual trace in the Dashboard, metadata appears in the attributes section. The Dashboard displays all key-value pairs you attached, making it easy to see the full context of a trace without switching to your application logs.How AgentMark stores metadata
AgentMark stores metadata as string key-value pairs. It indexes keys for fast filtering and search, and it stores all values as strings. If you need to attach non-string values, convert them first:Best practices
Recommended metadata keys
user_id: Per-user debugging and cost attribution. Example:"user-123". Use snake_case to populate the trace’s user field (AgentMark stores camelCaseuserIdas ordinary metadata).session_id: Group related traces into a session. Must be snake_case in metadata, or use the top-levelspan()sessionIdoption. Example:"sess-abc"environment: Distinguish staging from production when using a single app. Example:"production"version: Track which application version generated the trace. Example:"2.1.0"requestId: Correlate AgentMark traces with your application logs. Example:"req-xyz"feature: Identify which feature or flow triggered the trace. Example:"chat-v2"
Tips
- Use consistent key names across your application. If one service sends
userIdand another sendsuser_id, they appear as separate keys in the Dashboard. - Keep values short. Metadata suits identifiers and labels, not large payloads.
- Use metadata for anything you want to filter by later. If you find yourself searching your application logs for a value, it’s a good candidate for metadata.
- Metadata keys are case-sensitive. AgentMark treats
userIdanduseridas different keys. - AgentMark stores all values as strings. Convert numbers, booleans, and other types before passing.
SpanOptions.metadatahas the typeRecord<string, string>; AgentMark converts values inexperimental_telemetry.metadatato strings on ingest.
Reserved keys
AgentMark promotes some keys to dedicated trace fields on ingest instead of storing them as custom metadata:session_id, session_name, user_id, trace_name, prompt_name, props, and the dataset_* keys (dataset_run_id, dataset_run_name, dataset_path, dataset_item_name, dataset_expected_output, dataset_input). A custom key with one of these names doesn’t appear under the Metadata: filter fields, so pick a different name for unrelated values (for example app_props instead of props).
Next steps
Traces and logs
Understand trace details and span attributes
Sessions
Group related traces together
Filtering and search
Filter traces by metadata keys
Tracing setup
Set up tracing in your application
Have questions?
Reach out any time:
- Email the team at hello@agentmark.co for support
- Schedule an Enterprise Demo to learn about AgentMark’s business solutions