Querying your Cloud Trace data in BigQuery Studio lets you join spans
with other business data and use the full feature set of BigQuery. You
can open a SQL query directly in BigQuery Studio from the **Observability Analytics**
page, which automatically formats the `FROM` clause for your
[linked BigQuery dataset](https://docs.cloud.google.com/trace/docs/analytics-query-linked-dataset.md.txt).

If you haven't written queries in Observability Analytics, then first see
[Query and analyze traces](https://docs.cloud.google.com/trace/docs/analytics.md.txt).

## Before you begin

1.

   To get the permissions that
   you need to query a linked dataset from BigQuery,

   ask your administrator to grant you the
   following IAM roles:

   - [Observability Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/observability.md.txt#observability.viewer) (`roles/observability.viewer`) on the project
   - [Observability View Accessor](https://docs.cloud.google.com/iam/docs/roles-permissions/observability.md.txt#observability.viewAccessor) (`roles/observability.viewAccessor`) on the observability views that you want to query. This role supports IAM conditions, which let you restrict the grant to a specific view. If you don't attach a condition to the role grant, then the principal can access all observability views.
   - [BigQuery Data Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) (`roles/bigquery.dataViewer`) on the project or the linked BigQuery dataset
   - [BigQuery Job User](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.jobUser) (`roles/bigquery.jobUser`) on the project


   For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


   You might also be able to get
   the required permissions through [custom
   roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
   roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).
2. Verify that you have a [linked BigQuery dataset](https://docs.cloud.google.com/trace/docs/analytics-query-linked-dataset.md.txt) on the observability dataset that stores your trace data. If the linked BigQuery dataset doesn't exist, then create it.

## Run queries from BigQuery Studio

To open BigQuery from the Observability Analytics page
and then query your trace data, do the following:

1. In the Google Cloud console, go to the
   **Observability Analytics** page:

   [Go to **Observability Analytics**](https://console.cloud.google.com/logs/analytics)

   <br />

   If you use the search bar to find this page, then select the result whose subheading is
   **Logging**.
2. Enter or load a query. For more information, see
   [Query and analyze traces](https://docs.cloud.google.com/trace/docs/analytics.md.txt).

3. In the toolbar, expand the menu labeled **Run query** or
   **Run on BigQuery** , and select **Open in BigQuery**.

   BigQuery Studio opens. On this page, the `FROM` statement
   specifies the linked dataset by using the BigQuery
   [Table path syntax](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language.md.txt#table_path). You can perform any supported actions
   on the query, such as editing it.

   If the **Open in BigQuery** option is disabled, then either a linked dataset
   doesn't exist or you don't have the necessary permissions to open and
   view the query in BigQuery.
4. In BigQuery Studio, click **Run query**.

## Pricing

To learn about the costs associated with using BigQuery, see
[BigQuery pricing](https://cloud.google.com/bigquery/pricing).

## What's next

- [Monitor your SQL query results with an alerting policy](https://docs.cloud.google.com/trace/docs/sql-in-alerting.md.txt)
- [Save and share a SQL query](https://docs.cloud.google.com/trace/docs/analytics-save-share-query.md.txt)
- [Chart SQL query results](https://docs.cloud.google.com/trace/docs/analytics-chart.md.txt)
- [Sample SQL queries](https://docs.cloud.google.com/trace/docs/analytics-samples.md.txt)