Many endpoints that return information about errors and events support a filters parameter which can be used to restrict the data returned.
Filter object
The filter object is a hash of Event Field keys containing an array of filter values. Each filter value has a type and a value to filter on. The type determines the type of comparison that will be performed.
Filters are composed of an array of hashes. Each hash contains a type and a value. Valid types are eq, ne, and empty, though not all Event Fields support filtering on all of these.
{
"event.field": [{ "type": "eq", "value": "filter value 1" },
{ "type": "eq", "value": "filter value 2" },
{ "type": "empty", "value": "true"}]
}Any number of Event Fields can be supplied and results must match each event field (logical AND). Different filter values for an event field will combined according to the following rules.
Field value comparison
These compare whether an Event Field is equal (eq) or not equal (ne) to a given value. Filter values for each Event Field are combined logically as shown:
| Type | Description | Multiple value combination logic |
|---|---|---|
eq | Filter for items that 'match' the value. Some fields require an exact match and some support substring matching. | OR |
ne | Filter for items that don't match the value. | AND |
If ne filter types are supplied alongside eq, the ne are discarded to avoid a logically ambiguous combination.
Note that the ne type is not supported for the time based filters event.since and event.before.
Field emptiness
These filter based on the presence or absence of any value for a given field. The filter type is empty, and takes true or false values. If an ambiguous value is supplied it is assumed true.
Field emptiness filters combine with field value comparisons eq and ne as follows:
| Field value type | Empty field true | Empty field false |
|---|---|---|
eq | OR | emptiness ignored |
ne | emptiness ignored | AND |
If both true and false values are supplied for a given Event Field, true will be preferred, except for Event Field error.assigned_to.
Encoding in URL parameters
The filters are generally sent as URL parameters. The object should be encoded as follows:
filters[event.field][][type]=eq
filters[event.field][][value]=filter value 1
filters[event.field][][type]=eq
filters[event.field][][value]=filter value 2
filters[event.field][][type]=empty
filters[event.field][][value]=trueEvent fields
Each project has a set of default Event Fields, which represent metadata captured on Error events. These are available to filter by plus any custom event fields that have been created via the API or any custom filters that have been added via the dashboard.
To find the available Event Fields on a project use List the Event Fields for a Project.
Time filters can either be supplied in ISO 8601 format or as relative times in the format <number><period>. If using ISO 8601, times must use the extended format and be in UTC (e.g. 2018-05-20T00:00:00Z). For relative times, the past seven days could be requested as 7d. Valid values for <period> are:
| Period | Description |
|---|---|
| h | Hours |
| d | Days |
Filtering errors vs. filtering events
While any of a project's Event Fields can be passed as a filter to any endpoint that supports filtering, some fields are more applicable to Errors and others are more applicable to Events.
For example, an Event Field like error.status or error.assigned_to would make more sense when filtering at the Error level, since all Events grouped within a particular error would share the same status and assignee. Conversely, a filter like user.email or app.release_stage is applied at the Event level, since different Events within a particular Error may happen to different users or in different release stages.
If an endpoint that returns Errors is passed an Event-level filter, it will return Errors that include at least one Event that matches the filter. Event-level information within the Error, like the count of relevant Events, will reflect the filters applied.
Trace fields and Performance Filtering
Trace Fields are similar to Event Fields, but instead capture performance monitoring metadata as span attributes. These can be used for filtering spans in BugSnag.
To find available Trace Fields on a project, use List the Trace Fields for a Project.
As above, time filters can either be supplied in ISO 8601 format or as relative times in the format <number><period>. If using ISO 8601, times must use the extended format and be in UTC (e.g. 2018-05-20T00:00:00Z). For relative times, the past seven days could be requested as 7d. Valid values for <period> are:
| Period | Description |
|---|---|
| h | Hours |
| d | Days |
Examples
Open errors with events in the last day
This example will filter for events of errors that have a status of open that occurred in the last day:
{
"event.since": [{ "type": "eq", "value": "1d" }],
"error.status": [{ "type": "eq", "value": "open" }]
}or as URL parameters:
filters[event.since][][type]=eq
filters[event.since][][value]=1d
filters[error.status][][type]=eq
filters[error.status][][value]=openEvents affecting two specific users on a specific day
This example will filter for events that occurred for either user1@example.com or user2@example.com on January 1st, 2017:
{
"event.before": [{ "type": "eq", "value": "2017-01-02T00:00:00Z" }],
"event.since": [{ "type": "eq", "value": "2017-01-01T00:00:00Z" }],
"user.email": [{ "type": "eq", "value": "user1@example.com" },
{ "type": "eq", "value": "user2@example.com" }]
}or as URL parameters:
filters[event.before][][type]=eq
filters[event.before][][value]=2017-01-02T00:00:00Z
filters[event.since][][type]=eq
filters[event.since][][value]=2017-01-01T00:00:00Z
filters[user.email][][type]=eq
filters[user.email][][value]=user1@example.com
filters[user.email][][type]=eq
filters[user.email][][value]=user2@example.comEvents that have user data
This example will filter for any events that have a user ID:
{
"user.id": [{ "type": "empty", "value": "false"}]
}or as URL parameters:
filters[user.id][][type]=empty
filters[user.id][][value]=falseErrors that are new and aren't assigned to anyone
This example will filter for errors that have a status of new but are not assigned to a particular user.
{
"error.status": [{ "type": "eq", "value": "new" }]
"error.assigned_to": [{ "type": "ne", "value": "12345" }]
}or as URL parameters:
filters[error.status][][type]=eq
filters[error.status][][value]=new
filters[user.email][][type]=ne
filters[user.email][][value]=12345Advanced Filters
Advanced filters give you more granular control over error and event filtering, allowing you to create complex logical combinations of filters. Advanced filters are applied using the filter_groups and filter_groups_join parameters either as URL query parameters, or a object in the request body.
Advanced filters can be used alongside standard filters in a request. When used together, the main filters are applied first, and joined with advanced filters using a logical AND.
To use advanced filters your plan must support it. Please contact the BugSnag support team for more information on which plans include this feature.
Filter Groups
The filter_groups parameter is an object with multiple group objects keyed by an index. Each group object contains one or more event field filters, as described above, and a join key which determines how the filters within the group are combined (either and or or), and defaults to and if not specified.
| Group Join type | Description |
|---|---|
and | All filters in the group must be satisfied (default) |
or | At least one filter in the group must be satisfied |
A filter_groups object with the join key and filters is formatted as so:
"filter_groups": {
"0": {
"event.message": [{ "type": "eq", "value": "Something bad happened!" }],
"event.class": [
{ "type": "eq", "value": "InvalidArgument" },
{ "type": "eq", "value": "RuntimeError" }
],
"join": "and"
},
"1": {
Another filter group object...
}
}Filter Groups Examples
This request would return errors from the last thirty days which have Organization in the event.message and where the event.class is not InvalidArgument or which have Payment in the event.message or where the app.context is Post /my/payment/processor:
{
"filters": { "event.since": "30d" },
"filter_groups": {
"0": {
"event.message": [{ "type": "eq", "value": "User" }],
"event.class": [{ "type": "ne", "value": "InvalidArgument" }],
"join": "and"
},
"1": {
"event.message": [{ "type": "eq", "value": "Payment" }],
"app.context": [{ "type": "eq", "value": "POST /my/payment/processor" }],
"join": "or"
}
},
"filter_groups_join": "or"
}Or as URL parameters:
?filters[event.since]=30d
&filters_groups[0][event.message][type]=eq
&filters_groups[0][event.message][value]=User
&filters_groups[0][event.class][type]=ne
&filters_groups[0][event.class][value]=InvalidArgument
&filters_groups[0][join]=and
&filters_groups[1][event.message][type]=eq
&filters_groups[1][event.message][value]=Payment
&filters_groups[1][app.context][type]=eq
&filters_groups[1][app.context][value]=POST /my/payment/processor
&filters_groups[1][join]=or
&filter_groups_join=orFilter Groups Join
The filter_groups_join parameter determines how the groups themselves are combined (either and or or), and defaults to or if not specified.
| Filter Groups Join Type | Description |
|---|---|
and | All filter groups must be satisfied |
or | At least one filter group must be satisfied (default) |
The filter_groups_join parameter is formatted as so:
"filter_groups" : "and"Combining eq and ne filters
Unlike standard filters, advanced_filters can be used to combine eq and ne filters for the same event field. Filters for the same event field can be constrained to a single filter group or spread across multiple filter groups.
Using combined eq and ne filters in the same group (Group join is and):
{
"filter_groups": {
"0": {
"event.message": [
{ "type": "eq", "value": "Errors which contain me" },
{ "type": "ne", "value": "But do not contain me" }
],
"join": "and"
}
}
}Using combined eq and ne filters across groups (Filter Groups Join is and):
{
"filter_groups": {
"0": {
"event.message": [
{ "type": "eq", "value": "Errors which contain me" }
]
},
"1": {
"event.message": [
{ "type": "ne", "value": "But do not contain me" }
]
}
},
"filter_groups_join": "and"
}