> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Search specification

**Developer**

**Federal docs**

**EU docs**

This topic explains how to use the LaunchDarkly observability query builder and search syntax to find specific sessions, errors, logs, traces, and metrics. You build queries by adding filters that compare the properties and attributes of your observability data to the values you choose.

## Build queries with the query builder

The query builder is available in the search field on observability pages. It appears in these areas:

* On the **Sessions**, **Errors**, **Logs**, **Traces**, and **Observability metrics** pages.
* In the filters for [alerts](https://launchdarkly.com/docs/home/observability/alerts.md) and [custom dashboard](https://launchdarkly.com/docs/home/observability/custom-dashboards.md) graphs.
* In the settings for [filter rules](https://launchdarkly.com/docs/home/observability/settings.md#filters).

The query builder represents each condition in your query as a filter. A filter has three parts: a field, an operator, and one or more values. For example, a filter with the field `service_name`, the operator **is**, and the value `checkout` matches data from the `checkout` service.

![The query builder on the Traces page, with filters and the field menu open.](https://mintcdn.com/launchdarkly/yk3Kp3OHEVZstPVO/images/__LD_UI_no_test/o11y-search-overview.png?fit=max\&auto=format\&n=yk3Kp3OHEVZstPVO\&q=85\&s=eeeaaa7db5f8037e748a28fcdb13bec0)

The query builder on the Traces page, with filters and the field menu open.

### Add and edit filters

Here are the controls for adding, updating, and deleting filters:

<table>
  <thead>
    <tr>
      <th>Activity</th>
      <th>Controls</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Add a filter</td>
      <td>Click an empty spot in the query builder, including the space between two filters, to display the fields, operators, and logical operators you can add at that spot. Type characters to filter the available selections. The query builder highlights the best match.\
      \
      Press Tab or Enter to add the highlighted option, or click a name in the menu.</td>
    </tr>

    <tr>
      <td>Add a field and operator together</td>
      <td>Type a suggested field name followed by an operator, such as `service_name=` or `service_name is not`. The query builder adds both the field and operator and moves to the value entry. You can type the operator as a symbol or as its label.</td>
    </tr>

    <tr>
      <td>Add a filter for a field that isn't suggested</td>
      <td>Type the field name, then select the "Search for field" option.</td>
    </tr>

    <tr>
      <td>Add multiple values</td>
      <td>Use checkboxes in the menu to select multiple values, or use commas to separate multiple, typed values.</td>
    </tr>

    <tr>
      <td>Update a filter</td>
      <td>Click an existing field, operator, or value to change it.</td>
    </tr>

    <tr>
      <td>Delete a filter</td>
      <td>Click the **x** icon next to the filter. You can also press Backspace to delete one character at a time. Deleting the last character of a field removes the filter.</td>
    </tr>

    <tr>
      <td>Run the query</td>
      <td>Press Enter when the menu is closed.</td>
    </tr>
  </tbody>
</table>

When you highlight an option in the menu, a details panel describes it. For fields, the details panel includes the field's type, its "Most used values," and when you last searched for it.

### Operators

Each field offers the operators that apply to its type. If you select more than one value for a filter, the **is** and **is not** operators change to display **is one of** and **is not one of**.

Here are the available operators and the [search syntax](#search-query-syntax) each one produces:

<table>
  <thead>
    <tr>
      <th>Operator</th>
      <th>Field types</th>
      <th>Search syntax</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>**exists**</td>
      <td>All</td>
      <td>`key EXISTS`</td>
    </tr>

    <tr>
      <td>**does not exist**</td>
      <td>All</td>
      <td>`key NOT EXISTS`</td>
    </tr>

    <tr>
      <td>**is**</td>
      <td>All</td>
      <td>`key=value`</td>
    </tr>

    <tr>
      <td>**is not**</td>
      <td>All</td>
      <td>`key!=value`</td>
    </tr>

    <tr>
      <td>**contains**</td>
      <td>String</td>
      <td>`key="*value*"`</td>
    </tr>

    <tr>
      <td>**does not contain**</td>
      <td>String</td>
      <td>`key!="*value*"`</td>
    </tr>

    <tr>
      <td>**starts with**</td>
      <td>String</td>
      <td>`key="value*"`</td>
    </tr>

    <tr>
      <td>**ends with**</td>
      <td>String</td>
      <td>`key="*value"`</td>
    </tr>

    <tr>
      <td>**matches**</td>
      <td>String</td>
      <td>`key="/regex/"`</td>
    </tr>

    <tr>
      <td>**does not match**</td>
      <td>String</td>
      <td>`key!="/regex/"`</td>
    </tr>

    <tr>
      <td>**is greater than**</td>
      <td>Numeric, duration, timestamp</td>
      <td>`key>value`</td>
    </tr>

    <tr>
      <td>**is greater than or equal to**</td>
      <td>Numeric, duration, timestamp</td>
      <td>`key>=value`</td>
    </tr>

    <tr>
      <td>**is less than**</td>
      <td>Numeric, duration, timestamp</td>
      <td>`key<value`</td>
    </tr>

    <tr>
      <td>**is less than or equal to**</td>
      <td>Numeric, duration, timestamp</td>
      <td>`key<=value`</td>
    </tr>
  </tbody>
</table>

For fields that measure duration, such as `duration` or fields with names that end in `_duration`, you can include a unit in the value: `h`, `m`, `s`, `ms`, `us`, or `ns`. For example, `duration>=500ms`.

### Combine filters

The query builder joins filters with an implicit `AND` unless you add a logical operator between them. The "Operators" category in the menu includes these logical operators:

* **AND**: Match when both filter expressions are true.
* **OR**: Match when either filter expression is true.
* **NOT**: Exclude matches for the next filter expression.
* **Logical Group**: Group filter expressions in parentheses to evaluate them first.

You can also type `AND`, `OR`, or `NOT` followed by a space to add a logical operator. To change an existing **AND** to **OR**, or an **OR** to **AND**, click it.

To group filters with the keyboard:

* Type `(` before a filter to group it with every filter after it, up to the end of the query or of the group that contains it.
* Type `)` inside a group to end the group there. The filters after it move out of the group.
* Select filters and type `(` or `)` to group only the selection.
* Type `(` after the last filter to add an empty group.

On the **Traces** page, the menu also includes a "Relational Fields" category with span functions, such as **Any span** and **No span**. A span function groups filters that other spans in the same trace must match. To learn more, read [Span functions for trace search](#span-functions-for-trace-search).

On the **Sessions** page, the "Relational Fields" category includes **Span**, **No span**, **Log**, and **No log**. These group filters that a span or log in the same session must match. To require that events occur in order, add **THEN** between two of these groups.

### Copy and paste queries

When you copy filters from the query builder, LaunchDarkly copies them as search syntax, such as `service_name=checkout AND environment!=production`. When you paste search syntax into the query builder, LaunchDarkly converts it to filters.

The page URL also stores your query in search syntax. You can share the URL to link others to your search results.

### Keyboard shortcuts

Here are the keyboard shortcuts the query builder supports:

<table>
  <thead>
    <tr>
      <th>Shortcut</th>
      <th>Action</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Shift+Left arrow or Shift+Right arrow</td>
      <td>Select filters and logical operators.</td>
    </tr>

    <tr>
      <td>Cmd+A or Ctrl+A</td>
      <td>Select all.</td>
    </tr>

    <tr>
      <td>Cmd+C or Ctrl+C</td>
      <td>Copy the selection as search syntax.</td>
    </tr>

    <tr>
      <td>Cmd+X or Ctrl+X</td>
      <td>Cut the selection.</td>
    </tr>

    <tr>
      <td>Delete or Backspace</td>
      <td>Delete the selection.</td>
    </tr>

    <tr>
      <td>`(` or `)`</td>
      <td>Group the selection in parentheses.</td>
    </tr>

    <tr>
      <td>Cmd+Z or Ctrl+Z</td>
      <td>Undo.</td>
    </tr>

    <tr>
      <td>Cmd+Shift+Z, Ctrl+Shift+Z, or Ctrl+Y</td>
      <td>Redo.</td>
    </tr>

    <tr>
      <td>Left arrow or Right arrow</td>
      <td>Move the cursor one character, or into the space between filters.</td>
    </tr>

    <tr>
      <td>Alt+Left arrow or Alt+Right arrow</td>
      <td>Move the cursor one word.</td>
    </tr>

    <tr>
      <td>Cmd+Left arrow or Ctrl+Left arrow</td>
      <td>Move to the start of the query.</td>
    </tr>

    <tr>
      <td>Cmd+Right arrow or Ctrl+Right arrow</td>
      <td>Move to the end of the query.</td>
    </tr>

    <tr>
      <td>Tab or Enter</td>
      <td>Add the highlighted option in the menu.</td>
    </tr>

    <tr>
      <td>Enter</td>
      <td>Run the query when the menu is closed.</td>
    </tr>
  </tbody>
</table>

## Search query syntax

The query builder stores each query in the search syntax that this section describes. Search syntax appears in the page URL and when you copy a query, and you can paste it into the query builder to create filters.

Compose your search query with one or more expressions. Each expression can be a comparison between a key and a value, or a logical combination of other expressions.

Keywords such as `AND`, `OR`, `NOT`, and `EXISTS` are not case-sensitive. For example, `not exists` and `NOT EXISTS` are equivalent.

Here are some examples of search queries:

```txt title="Example query" lines wrap theme={null}
  span_name=gorm.Query
```

Find sessions associated with a specific feature flag.

```txt title="Example query" lines wrap theme={null}
  events.attributes.feature_flag.key=EXAMPLE_FLAG_KEY
```

Enter a search value without a key to search on a default key. For logs, the default key is the message, and for traces it is the `span_name`.

```txt title="Example query" lines wrap theme={null}
  gorm.Query
```

You can also filter for custom attributes you send in sessions, logs, and traces.

```txt title="Example filter" lines wrap theme={null}
  user_id=42
```

### Keys and values

Keys are identifiers, which can include any combination of alphanumeric characters, underscores (`_`), periods (`.`), dashes (`-`), and wildcards, which are indicated by asterisks (`*`).

Values are strings with any character. To use spaces or special characters, you must enclose the string in quotes (`"`, `'`).

You can use wildcards (`*`) in values to match on part of a pattern. For example:

* `span_name=gorm.*` matches all `span_name` values that start with `gorm`.
* `span_name=*.Query` matches all `span_name` values that end with `.Query`
* `span_name=*orm*` matches all values that contain `orm`

If you want to use a value with a space or special character, you must wrap the value in quotations.

```txt title="Example query" lines wrap theme={null}
  tag="*query error*"
  visited-url="https://app.launchdarkly.com/*"
```

### Log message search

On the **Logs** page, a search term without a key matches the log message. LaunchDarkly matches bare words and quoted phrases against an index of the words in each message. This returns results faster than scanning the full text of every message.

Because the index stores whole words, a quoted phrase matches its first and last words as whole words. For example, consider a search for the phrase `"recovered panic"`:

* The phrase matches the message `recovered panic in handler`.
* The phrase does not match the message `unrecovered panicky`, because `recovered` and `panic` are not whole words in that message.

To match part of a word, use a wildcard value such as `message="*recovered*"`, or a regex value such as `message="/recovered/"`. Word boundaries do not affect wildcard values, regex values, or filters on keys other than the message.

If a log search takes too long to complete, LaunchDarkly returns an error that describes how to narrow the search. To reduce the chance of a timeout, shorten the time range, add filters on keys such as `service_name` or `level`, and search for whole words or a quoted phrase instead of a wildcard.

> [!NOTE]
>
> **Quoted phrases match whole words at the phrase boundaries**
>
> A saved or shared log query that relies on a quoted phrase matching part of a word returns fewer results than it did before. To match part of a word again, replace the quoted phrase with a wildcard value.

### Trace and span ID values

LaunchDarkly stores the `trace_id`, `span_id`, and `parent_span_id` fields in the hexadecimal format that OpenTelemetry uses. Datadog displays the same identifiers as decimal numbers.

When you filter one of these three fields with a decimal value copied from Datadog, LaunchDarkly also matches the hexadecimal form it stored at ingest. You do not need to convert the identifier yourself. This behavior applies on the **Logs**, **Traces**, and **Errors** pages.

Here is an example query that uses a Datadog decimal trace ID:

```txt title="Example query" lines wrap theme={null}
  trace_id=5038895135356951034
```

### Regex expressions

You can search with regex expressions by using the matches query operator: `=/[your regex here]/`. For example:

* `clickTextContent=/\w.+\w/` matches all `clickTextContent` that start and end with any word
* `browser_version=/\d\.\d\.\d/` matches all `browser_version` values in the form \[0-9].\[0-9].\[0-9]

If you want to use a regex expression with a space or special character, you must wrap the value in quotations. For example:

* `tag="/\w \w/"`
* `visited-url="/https://app.launchdarkly.com/\d/.+/"`

### Comparisons

Use operators to compare two different elements in your search query. The following operators are supported:

* `=`: Equals
* `!=`: Does not equal
* `<`: Less than
* `<=`: Less than or equal to
* `>`: Greater than
* `>=`: Greater than or equal to

### Exist and does not exist

You can search if a key exists or does not exist with the `EXISTS` operator. For example, to return all the traces with a connected session, use the following query:

```txt title="Example query" lines wrap theme={null}
  secure_session_id EXISTS
```

`EXISTS` also works with the `NOT` keyword. For example, when you only want the root level spans when searching traces, use this query:

```txt title="Example query" lines wrap theme={null}
  parent_span_id NOT EXISTS
```

You can combine expressions with the logical operators `AND`, `OR`, and `NOT`:

* `AND`: Both expressions must be true.
* `OR`: At least one of the expressions must be true.
* `NOT`: The following expression must be false.

Filters are combined with an implicit `AND` unless you specify `OR`. For example:

```txt title="Example query" lines wrap theme={null}
  service_name=private-graph span_name=gorm.Query
```

This is equivalent to:

```txt title="Example query" lines wrap theme={null}
  service_name=private-graph AND span_name=gorm.Query
```

You can also use parentheses `( AND )` to group values in an expression. For example:

```txt title="Example query" lines wrap theme={null}
  (key1=value1 AND key2=value2) OR key3=value3
```

You can also use parentheses to group values in an expression:

```txt title="Example query" lines wrap theme={null}
  service_name=(private-graph OR public-graph)
```

### Span functions for trace search

The search functionality on the **Traces** page returns individual spans that make up traces.

Span functions help you filter results to show only those spans for traces that contain or don't contain spans that match one or more conditions.

The following span functions are available when you search on the **Traces** page:

* `any_span( expression )` limits results to spans where the trace contains at least one span that matches the expression.
* `any_span2()` and `any_span3()` operate in the same way as `any_span()`. The unique function names let you require different spans in the trace to satisfy different conditions in the same query. To learn more, read [Using multiple span aliases](#using-multiple-span-aliases).
* `no_span( expression )` limits results to spans where the trace contains no spans that match the inner expression.
* `child_span( expression )` limits results to spans that have at least one direct child span matching the expression.
* `parent_span( expression )` limits results to spans where the direct parent span matches the expression.
* `root_span( expression )` limits results to spans where the trace's root span matches the expression.

Span functions wrap a normal search expression in parentheses. Inside the parentheses, you can use any of the existing operators, including comparisons, `EXISTS`, `AND`, `OR`, and `NOT`.

Here is an example that returns spans whose trace contains at least one span from the `auth-service`:

```txt title="Example query" lines wrap theme={null}
  any_span(service_name=auth-service)
```

Here is an example that returns spans whose trace contains at least one error in an `auth-service` span:

```txt title="Example query" lines wrap theme={null}
  any_span(service_name=auth-service AND has_errors=true)
```

Here is an example that returns spans whose trace contains no spans with errors:

```txt title="Example query" lines wrap theme={null}
  no_span(has_errors=true)
```

Here is an example that returns spans that have a direct child span that lasts longer than one second:

```txt title="Example query" lines wrap theme={null}
  child_span(duration>1000)
```

Here is an example that returns spans where the direct parent span belongs to the `auth-service`:

```txt title="Example query" lines wrap theme={null}
  parent_span(service_name=auth-service)
```

Here is an example that returns spans where the trace's root span is named `checkout`:

```txt title="Example query" lines wrap theme={null}
  root_span(span_name=checkout)
```

#### Using multiple span aliases

If you call `any_span()` more than once in a query, the conditions accumulate against the same span. For example, this query requires a single span in the trace to match both conditions:

```txt title="Example query" lines wrap theme={null}
  any_span(service_name=checkout) any_span(has_errors=true)
```

To require that different spans in the trace satisfy each condition, use `any_span2()` or `any_span3()` for the second condition. Here is an example that returns spans whose trace contains at least one `checkout` span and another, different span that contains errors:

```txt title="Example query" lines wrap theme={null}
  any_span(service_name=checkout) any_span2(has_errors=true)
```

#### Combining span functions with regular search expressions

You can combine span functions with regular search expressions in the same query. Regular expressions filter the displayed spans by their own properties, while span functions filter the displayed spans by conditions that apply to the same trace. Here is an example:

```txt title="Example query" lines wrap theme={null}
  environment=production any_span(service_name=auth-service AND duration>1s)
```

This query returns spans in the `production` environment whose trace also contains at least one `auth-service` span that lasts longer than one second.

#### Limitations

You can only use span functions as top-level filters in a query.

Span functions have the following restrictions:

* You cannot wrap span functions in parentheses.
* All span functions at the top level of a query are joined with an implicit `AND` operator. You cannot combine span functions using `AND`, `OR`, or `NOT` outside of the function call.

These restrictions apply to the span function itself. Inside the parentheses, the inner expression supports the full set of search operators, including `AND`, `OR`, `NOT`, `EXISTS`, and grouping.

### Span and log blocks for session search

The search functionality on the **Sessions** page can match sessions by the events they recorded, and by the order in which those events occurred. To describe an event, wrap a search expression in a block. To describe a sequence of events, join blocks with the `THEN` keyword, which requires each block to match later in the session than the block before it.

The following blocks are available when you search on the **Sessions** page:

* `span( expression )` matches sessions that recorded at least one span matching the expression.
* `no_span( expression )` matches sessions that recorded no span matching the expression.
* `log( expression )` matches sessions that recorded at least one log matching the expression.
* `no_log( expression )` matches sessions that recorded no log matching the expression.

Log blocks and span blocks are interchangeable. Use either kind as any step in a `THEN` chain, and combine blocks with `AND` and `OR`.

Here is an example that returns sessions where an end user clicked and the session recorded an error log afterward:

```txt title="Example query" lines wrap theme={null}
  span(span_name="click") THEN log(level=error)
```

#### Expressions inside a log block

Inside a `log( )` block, the log search grammar applies. You can filter on `level`, `message`, `source`, and `service_name`, as well as on any attribute attached to the log. To learn which attributes LaunchDarkly records for logs, read [Search attributes](https://launchdarkly.com/docs/home/observability/logs.md#search-attributes).

Here is an example that returns sessions that recorded an error log from the `checkout` service:

```txt title="Example query" lines wrap theme={null}
  log(level=error AND service_name=checkout)
```

A value with no key searches the body of the log message. Here is an example that returns sessions that recorded a log whose message contains `timeout`:

```txt title="Example query" lines wrap theme={null}
  log(timeout)
```

#### Block limitations

Blocks have the following restrictions:

* A sequence cannot begin with `no_span( )` or `no_log( )`. Begin with a block that describes an event the session did record.
* `no_span( )` and `no_log( )` are valid only as the last step of a `THEN` chain.
* Use `no_log( )` rather than `NOT log( )`, and `no_span( )` rather than `NOT span( )`. LaunchDarkly rejects the `NOT` form.
* You cannot nest one block inside another.

Log blocks apply only to search on the **Sessions** page. On the **Traces** page, LaunchDarkly treats `log( )` as ordinary search text rather than as a block. To learn about the functions available for trace search, read [Span functions for trace search](#span-functions-for-trace-search).

## Saved searches

Saved searches are a set of search filters that apply to sessions or errors. Saved searches are useful if you want to quickly view sessions or errors that relate to a certain population of your end users.

To save a search, click the **Save** button below the query builder.

The searches you build are reflected in the URL parameters when you're accessing sessions through the LaunchDarkly UI. You can share these URLs with others to deep link to search results, or create them programmatically.

## Session-specific searching

To learn more about search terms and defaults specific to session replays, read [Search](https://launchdarkly.com/docs/home/observability/session-replay.md#search) in the [Session replay](https://launchdarkly.com/docs/home/observability/session-replay.md) topic.

LaunchDarkly flattens the nested properties of the track events your application records. This lets you query each individual property. To learn more, read [Search by track event properties](https://launchdarkly.com/docs/home/observability/session-replay.md#search-by-track-event-properties).

## Configure error views

You can configure the **Errors** page to display different subsets of errors. Use the date menu to select a time range, and use the query builder to filter the errors.
