This document describes why we recommend that you send your trace data to your
Google Cloud project by using the Telemetry (OTLP) API, which implements
the [OpenTelemetry Protocol](https://opentelemetry.io/docs/specs/otlp). It also provides guidance on instrumenting
your applications and where you can view your trace data. You can use the
Telemetry API when you instrument your applications by using one of the
[OpenTelemetry SDKs](https://opentelemetry.io/docs/languages/) or when you use a OpenTelemetry Collector.

We recommend the Telemetry API for the following reason:

- The API provides compatibility with the open source OpenTelemetry ecosystem and
  [its limits](https://docs.cloud.google.com/stackdriver/quotas.md.txt#telemetry-api-limits) are often more generous than the limits of the
  Cloud Trace API, which is a proprietary Google Cloud API

- Your trace data is stored in a format that is generally consistent with the
  proto files defined by the [OpenTelemetry Protocol](https://opentelemetry.io/docs/specs/otlp). Some fields might
  be converted from an OpenTelemetry-specific data type to a JSON data type before
  storage. To learn more about the storage format, see
  [Schema for trace data](https://docs.cloud.google.com/stackdriver/docs/reference/telemetry/trace-schema.md.txt).

- Your instrumentation doesn't rely on a Google Cloud-specific exporter.

- Some features, like Application Monitoring, rely on information that is available only
  when you send trace data to the Telemetry API.

OpenTelemetry is a Google Cloud-supported open source project with Google Cloud
engineers staffed to ensure support for ingesting and visualizing your
telemetry.

Google Cloud Observability verifies that the Cloud Trace API is enabled
on your Google Cloud project before it stores any trace data. That means that if you
disable the Cloud Trace API, then Google Cloud Observability discards trace data you send to the
Telemetry API.

## Best practices

When instrumenting your applications to send trace data to your
Google Cloud project, we recommend that you use an exporter that
writes OTLP-formatted data to an [Collector](https://opentelemetry.io/docs/collector/),
which then sends your trace data to the Telemetry API.
In your collector, specify only the root URL:

    exporters:
      otlphttp:
        encoding: proto
        endpoint: https://telemetry.googleapis.com

OpenTelemetry detects the data type and automatically appends `/v1/traces`,
`/v1/metrics`, or `/v1/logs` as appropriate. For more information, see
[OTLP/HTTP Request](https://opentelemetry.io/docs/specs/otlp#otlphttp-request).

For examples that export trace or metric data to the Telemetry API,
see the following documents:

- [Overview of collector-based instrumentation samples](https://docs.cloud.google.com/stackdriver/docs/instrumentation/setup/sample-overview.md.txt).
- [OTLP ingestion overview](https://docs.cloud.google.com/stackdriver/docs/otlp/overview.md.txt).

When you can't use a collector, you can use an OpenTelemetry library that contains
an in-process OTLP exporter to send telemetry to the Telemetry API.
To learn how to directly export trace data, see
[Cloud Trace exporter to the OTLP endpoint](https://docs.cloud.google.com/stackdriver/docs/instrumentation/migrate-to-otlp-endpoints.md.txt).

## Authentication

You must configure your exporters with the credentials necessary to send
data to your Google Cloud project. For example, when you use collectors, typically
you use the `googleclientauth` extension to authenticate with Google
credentials.

For an example of authentication when using direct export of trace data, see
[Configure authentication](https://docs.cloud.google.com/stackdriver/docs/instrumentation/migrate-to-otlp-endpoints.md.txt#auth).
This example illustrates how to configure the exporter with your Google Cloud
[Application Default Credentials (ADC)](https://docs.cloud.google.com/docs/authentication/provide-credentials-adc.md.txt)
and add a language-specific Google Auth Library to your application.

To send telemetry data to your Google Cloud project by using the Telemetry API,
you must also do the following:

- Configure a quota project. To learn more, see
  [Set the quota project](https://docs.cloud.google.com/docs/quotas/set-quota-project.md.txt).

- Grant the following Identity and Access Management (IAM) roles to the user or to the
  service account that the application uses:

  - [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) role (`roles/serviceusage.serviceUsageConsumer`) on the quota project.
  - [Cloud Telemetry Writer](https://docs.cloud.google.com/iam/docs/roles-permissions/telemetry.md.txt#telemetry.writer) role (`roles/telemetry.writer`) on the project. This role lets your application write log, metric, and trace data.

## Cloud Trace and data residency

If you are using [Assured Workloads](https://cloud.google.com/security/products/assured-workloads)
because you have data-residency or
[Impact Level 4 (IL4)](https://cloud.google.com/security/compliance/disa) requirements,
then don't use the Telemetry API to send trace spans to your project.

## Where to view ingested data

You can view your trace data by using the **Trace Explorer** and
**Observability Analytics** pages. For information, see the following:

- [Find and explore traces](https://docs.cloud.google.com/trace/docs/finding-traces.md.txt).
- [Query and analyze traces](https://docs.cloud.google.com/trace/docs/analytics.md.txt).

## Quotas

For information about quotas associated with the Telemetry API,
see [Telemetry API limits](https://docs.cloud.google.com/stackdriver/quotas.md.txt#telemetry-api-limits).