Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Enterprise Open source RSS

Tempo data source

Grafana ships with built-in support for Tempo, a high-volume, minimal-dependency trace storage, open-source tracing solution from Grafana Labs.

For instructions on how to add a data source to Grafana, refer to the administration documentation. Only users with the organization administrator role can add data sources. Administrators can also configure the data source via YAML with Grafana’s provisioning system.

Once you’ve added the data source, you can configure it so that your Grafana instance’s users can create queries in its query editor when they build dashboards and use Explore.

You can also use the service graph to view service relationships, track RED metrics, upload a JSON trace file, and link a trace ID from logs in Loki or Elasticsearch.

Configure the data source

To access the data source configuration page:

  1. Hover the cursor over the Configuration (gear) icon.
  2. Select Data Sources.
  3. Select the Tempo data source.

Set the data source’s basic configuration options carefully:

NameDescription
NameSets the name you use to refer to the data source in panels and queries.
DefaultSets the data source that’s pre-selected for new panels.
URLSets the URL of the Tempo instance, such as http://tempo.
Basic AuthEnables basic authentication to the Tempo data source.
UserSets the user name for basic authentication.
PasswordSets the password for basic authentication.

You can also configure settings specific to the Tempo data source:

Configure trace to logs

Trace to logs settings

Note: Available in Grafana v7.4 and higher. If you use Grafana Cloud, open a support ticket in the Cloud Portal to access this feature.

The Trace to logs setting configures the trace to logs feature that is available when you integrate Grafana with Tempo.

There are two ways to configure the trace to logs feature. You can use simplified configuration with default query, or you can configure custom query where you can use a template language to interpolate variables from the trace or span.

To use simple configuration:

  1. Select the target data source.
  2. Set start and end time shift. As the logs timestamps may not exactly match the timestamps of the spans in trace it may be necessary to search in larger or shifted time range to find the desired logs.
  3. Select which tags to use in the logs query. The tags you configure must be present in the spans attributes or resources for a trace to logs span link to appear. You can optionally configure a new name for the tag. This is useful for example if the tag has dots in the name and the target data source does not allow using dots in labels. In that case you can for example remap http.status to http_status.
  4. Optionally switch on Filter by Trace ID and/or Filter by Span ID to further filter the logs if your logs consistently contain trace or span IDs.

To use custom query configuration:

  1. Select the target data source.
  2. Set start and end time shift. As the logs timestamps may not exactly match the timestamps of the spans in the trace it may be necessary to widen or shift the time range to find the desired logs.
  3. Optionally select tags to map. These tags can be used in the custom query with ${__tags} variable. This variable will interpolate the mapped tags as list in an appropriate syntax for the data source and will only include the tags that were present in the span omitting those that weren’t present. You can optionally configure a new name for the tag. This is useful in cases where the tag has dots in the name and the target data source does not allow using dots in labels. For example, you can remap http.status to http_status in such a case. If you don’t map any tags here, you can still use any tag in the query like this method="${__span.tags.method}".
  4. Skip Filter by Trace ID or Filter by Span ID as these cannot be used with custom query.
  5. Switch on Use custom query.
  6. Specify custom query to be used to query the logs. You can use various variables to make that query relevant for current span. The link will only be shown only if all the variables are interpolated with non-empty values to prevent creating invalid query.

Variables that can be used in custom query To use a variable you need to wrap it in ${}. For example ${__span.name}.

Variable nameDescription
__tagsThis variable is special because it uses the tag mapping in from the UI to create a label matcher string in the specific data source syntax. It uses only tags that are present in the span so the link will still be created even if only one of those tags is present in the span. You can use this if not all the tags are required for the query to be useful.
__span.spanIdThe ID of the span.
__span.traceIdThe ID of the trace.
__span.durationThe duration of the span.
__span.nameName of the span.
__span.tagsNamespace for the tags in the span. To access a specific tag named “version” you would use ${__span.tags.version}. In case the tag contains dot you have to access it as ${__span.tags["http.status"]}.
__trace.traceIdThe ID of the trace.
__trace.durationThe duration of the trace.
__trace.nameThe name of the trace.

The following table describes the ways in which you can configure your trace to logs settings:

Setting nameDescription
Data sourceDefines the target data source. You can select only Loki or Splunk [logs] data sources.
Span start time shiftShifts the start time for the logs query, based on the span’s start time. You can use time units, such as 5s, 1m, 3h. To extend the time to the past, use a negative value. Default is 0.
Span end time shiftShifts the end time for the logs query, based on the span’s end time. You can use time units. Default is 0.
TagsDefines the the tags to use in the logs query. Default is 'cluster', 'hostname', 'namespace', 'pod'. You can change the tag name for example to remove dots from the name if they are not allowed in the target data source. For example map http.status to http_status
Filter by Trace IDToggles whether to append the trace ID to the logs query.
Filter by Span IDToggles whether to append the span ID to the logs query.
Use custom queryToggles use of custom query with interpolation.
QueryInput to write custom query. Use variable interpolation to customize it with variables from span.

Configure trace to metrics

Note: This feature is behind the traceToMetrics feature toggle. If you use Grafana Cloud, open a support ticket in the Cloud Portal to access this feature.

The Trace to metrics setting configures the trace to metrics feature available when integrating Grafana with Tempo.

To configure trace to metrics:

  1. Select the target data source.
  2. Create any desired linked queries.
Setting nameDescription
Data sourceDefines the target data source.
TagsDefines the tags used in linked queries. The key sets the span attribute name, and the optional value sets the corresponding metric label name. For example, you can map k8s.pod to pod. To interpolate these tags into queries, use the $__tags keyword.

Each linked query consists of:

  • Link Label: (Optional) Descriptive label for the linked query.
  • Query: The query ran when navigating from a trace to the metrics data source. Interpolate tags using the $__tags keyword. For example, when you configure the query requests_total{$__tags}with the tags k8s.pod=pod and cluster, the result looks like requests_total{pod="nginx-554b9", cluster="us-east-1"}.

Configure service graph

The Service Graph section configures the Service Graph feature.

Configure the Data source setting to define in which Prometheus instance the Service Graph data is stored.

To use the service graph, refer to the Service graph section.

Configure Tempo search integration

The Search section configures Tempo search.

Optionally configure the Hide search setting to hide the search query option in Explore if search is not configured in the Tempo instance.

Enable Node Graph

The Node Graph setting enables the Node Graph visualization, which is disabled by default.

Once enabled, Grafana displays the Node Graph after loading the trace view.

The Loki search section configures the Loki search query type.

Configure the Data source setting to define which Loki instance you want to use to search traces. You must configure derived fields in the Loki instance.

Span bar label

The Span bar label section helps you display additional information in the span bar row.

You can choose one of three options:

NameDescription
NoneAdds nothing to the span bar row.
Duration(Default) Displays the span duration on the span bar row.
TagDisplays the span tag on the span bar row. You must also specify which tag key to use to get the tag value, such as span.kind.

Provision the data source

You can define and configure the Tempo data source in YAML files as part of Grafana’s provisioning system. For more information about provisioning, and for available configuration options, refer to Provisioning Grafana.

Provisioning examples

yaml
apiVersion: 1

datasources:
  - name: Tempo
    type: tempo
    # Access mode - proxy (server in the UI) or direct (browser in the UI).
    access: proxy
    url: http://localhost:3200
    jsonData:
      httpMethod: GET
      tracesToLogs:
        datasourceUid: 'loki'
        tags: ['job', 'instance', 'pod', 'namespace']
        mappedTags: [{ key: 'service.name', value: 'service' }]
        mapTagNamesEnabled: false
        spanStartTimeShift: '1h'
        spanEndTimeShift: '1h'
        filterByTraceID: false
        filterBySpanID: false
      tracesToMetrics:
        datasourceUid: 'prom'
        tags: [{ key: 'service.name', value: 'service' }, { key: 'job' }]
        queries:
          - name: 'Sample query'
            query: 'sum(rate(traces_spanmetrics_latency_bucket{$__tags}[5m]))'
      serviceMap:
        datasourceUid: 'prometheus'
      search:
        hide: false
      nodeGraph:
        enabled: true
      lokiSearch:
        datasourceUid: 'loki'

Query the data source

The Tempo data source’s query editor helps you query and display traces from Tempo in Explore.

For details, refer to the query editor documentation.

Upload a JSON trace file

You can upload a JSON file that contains a single trace and visualize it. If the file has multiple traces, Grafana visualizes its first trace.

To download a trace or service graph through the inspector:

  1. Open the inspector.
  2. Navigate to the Data tab.
  3. Click Download traces or Download service graph.

Trace JSON example

json
{
  "batches": [
    {
      "resource": {
        "attributes": [
          { "key": "service.name", "value": { "stringValue": "db" } },
          { "key": "job", "value": { "stringValue": "tns/db" } },
          { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } },
          { "key": "host.name", "value": { "stringValue": "63d16772b4a2" } },
          { "key": "ip", "value": { "stringValue": "0.0.0.0" } },
          { "key": "client-uuid", "value": { "stringValue": "39fb01637a579639" } }
        ]
      },
      "instrumentationLibrarySpans": [
        {
          "instrumentationLibrary": {},
          "spans": [
            {
              "traceId": "AAAAAAAAAABguiq7RPE+rg==",
              "spanId": "cmteMBAvwNA=",
              "parentSpanId": "OY8PIaPbma4=",
              "name": "HTTP GET - root",
              "kind": "SPAN_KIND_SERVER",
              "startTimeUnixNano": "1627471657255809000",
              "endTimeUnixNano": "1627471657256268000",
              "attributes": [
                { "key": "http.status_code", "value": { "intValue": "200" } },
                { "key": "http.method", "value": { "stringValue": "GET" } },
                { "key": "http.url", "value": { "stringValue": "/" } },
                { "key": "component", "value": { "stringValue": "net/http" } }
              ],
              "status": {}
            }
          ]
        }
      ]
    }
  ]
}

Use the service graph

A service graph is a visual representation of the relationships between services. Each node on the graph represents a service such as an API or database.

You use a service graph to detect performance issues; track increases in error, fault, or throttle rates in services; and investigate root causes by viewing corresponding traces.

Screenshot of a Node Graph
Screenshot of a Node Graph

To display the service graph:

  1. Configure Grafana Agent or Tempo or GET to generate service graph data.
  2. Link a Prometheus data source in the Tempo data source’s Service Graph settings.
  3. Navigate to Explore.
  4. Select the Tempo data source.
  5. Select the Service Graph query type.
  6. Run the query.
  7. (Optional) Filter by service name.

For details, refer to Node Graph panel.

Each circle in the graph represents a service. To open a context menu with additional links for quick navigation to other relevant information, click a service.

Numbers inside the circles indicate the average time per request and requests per second.

Each circle’s color represents the percentage of requests in each state:

ColorState
GreenSuccess
RedFault
YellowErrors
PurpleThrottled responses

Open the Service Graph view

Service graph view displays a table of request rate, error rate, and duration metrics (RED) calculated from your incoming spans. It also includes a node graph view built from your spans.

Screenshot of the Service Graph view table
Screenshot of the Service Graph view table

For details, refer to the Service Graph view documentation.

To open the Service Graph view:

  1. Link a Prometheus data source in the Tempo data source settings.
  2. Navigate to Explore.
  3. Select the Tempo data source.
  4. Select the Service Graph query type and run the query.
  5. (Optional) Filter your results.

Note: Grafana uses the traces_spanmetrics_calls_total metric to display the name, rate, and error rate columns, and traces_spanmetrics_latency_bucket to display the duration column. These metrics must exist in your Prometheus data source.

To open a query in Prometheus with the span name of that row automatically set in the query, click a row in the rate, error rate, or duration columns.

To open a query in Tempo with the span name of that row automatically set in the query, click a row in the links column.

You can link to Tempo trace from logs in Loki or Elasticsearch by configuring an internal link.

To configure this feature, see the Derived fields section of the Loki data source docs, or the Data links section of the Elasticsearch data source docs.