Grafana Guide: Explore Logs and Traces

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-11 against Grafana 13.3.x.

What you build

You read the logs of the Bookshelf service in Explore with the Loki data source. You narrow them with a line filter and a JSON parser, turn them into a metric, follow them live, open the trace that belongs to a log line in Tempo, find failed requests with a TraceQL query, and finish with the Logs app of Drilldown, which does the same exploration with clicks instead of queries.

Explore in split view: on the left Loki log lines of the Bookshelf service with the first line selected, on the right the Tempo trace of that request with the root span GET /api/books and two child spans

Before you start

  • Start the Grafana profile of the hands-on lab and wait about a minute:

    cd lab
    docker compose --profile grafana up -d
  • Open http://localhost:3000, sign in as admin with the password admin, and click Skip when Grafana 13.3 asks you to update the default password.

  • Do the previous guide, Explore metrics, first. It introduces the Explore page, the toolbar and the Builder / Code switch that this guide uses again.

  • The data sources Loki and Tempo are provisioned by the lab, so there is nothing to add. Use the data source called Loki: it has the Trace link that step 20 follows. A Loki data source that you created yourself in the data-source guide has that link only if you added the derived field trace_id to it.

  • The load generator sends traffic to the Bookshelf service in its default mode, which writes log lines and traces for every request.

  • The guide was checked on Grafana Enterprise 13.3.0 (the free image, no licence key). Reading logs and traces needs the Viewer role; admin has it.

  • The figures are drawings of the Grafana 13.3 user interface, not screenshots, so small details can differ from your screen. A highlighted box with a number marks the control of the step with the same number. Where this guide could not open a screen in the lab, the figure and the step name the control and do not describe its exact layout.

Steps

The Bookshelf log lines are JSON texts with the fields timestamp, level, logger, message, application, uri, status, trace_id and span_id, and they carry the stream labels application, job, service_name, detected_level and filename. The stream that this guide reads is {application="bookshelf"}. The screen of Explore is described in the screen map of the Explore metrics guide; the toolbar is the same here, with the data source Loki or Tempo chosen.

Open Explore and choose Loki

  1. In the left navigation, click Explore.

  2. Open the data source picker at the top left of the toolbar and click Loki.

    Explore page of Grafana 13.3 with the data source picker open: callout 1 marks the Explore item of the navigation and callout 2 marks Loki in the list of data sources, which are Loki, Prometheus, Tempo and TestData

Select the log stream

  1. In query A, click Code in the Builder / Code switch. The Builder lets you pick labels from lists instead; this guide types the queries.

    Explore with the Loki data source selected and an empty query A in Builder mode: callout 3 marks the Code option of the Builder and Code switch
  2. Click inside the query editor first, so that it has the focus, then type the stream selector. The label browser of the editor lists the available labels (application, job, service_name, detected_level and filename) if you prefer to pick the value of application instead of typing it:

    {application="bookshelf"}
  3. Click Run query in the toolbar.

    Explore with Loki in Code mode: the stream selector with the label application equal to bookshelf is typed into the editor, marked by callout 4, and the Run query button of the toolbar is marked by callout 5
  4. Below the query a chart of the log volume and the list of log lines appear. Click one log line to expand it: its fields level, uri, status, trace_id and span_id are listed.

    Explore after Run query: a logs volume chart above a list of log lines from the Bookshelf service, each line a JSON text with level, uri and status; callout 6 marks the log line to click

Filter and parse the lines

  1. Click in the editor, select all with Ctrl+A (Cmd+A on macOS) and type a query with a line filter, which keeps only the lines that contain a text:

    {application="bookshelf"} |= "/api/search"
  2. Click Run query. Only the lines of the route /api/search remain.

    Explore with Loki in Code mode: the query with the line filter for the text /api/search is typed into the editor, marked by callout 7, and the Run query button is marked by callout 8
  3. Select all again and type a query that parses the JSON body with json and filters on the extracted field status:

    {application="bookshelf"} | json | status >= 400
  4. Click Run query. The lines with a status of 400 or more remain; in the normal traffic mode these are the 404 answers.

    Explore with Loki in Code mode: the query that parses the JSON body and keeps the lines with a status of 400 or more is typed into the editor, marked by callout 9, and the Run query button is marked by callout 10

Follow the lines with Live

  1. With the query of step 9 still in place, click Live in the toolbar. New lines are added to the list as they arrive.

    Explore with the status filter query already run and the Live button of the toolbar, between the time range and Run query, marked by callout 11
  2. In a terminal, make the Bookshelf service fail, and watch lines with a status of 500 appear:

    curl -X POST localhost:8090/mode/failing
  3. Stop the live view with the stop control that the toolbar shows while Live runs, and restore normal traffic:

    curl -X POST localhost:8090/mode/normal

Count the lines as a metric

  1. Click in the editor, select all and type a metric query, which counts the lines per status over one minute:

    sum by (status) (count_over_time({application="bookshelf"} | json [1m]))
  2. Click Run query.

    Explore with Loki in Code mode: a metric query that counts the log lines per status over one minute is typed into the editor, marked by callout 14, and the Run query button is marked by callout 15
  3. A Graph panel replaces the list of lines, with one line per status. Above it, click Bars in the display switch.

    Explore after the metric query ran: a Graph panel draws one line for the status 200 and one for 404, and callout 16 marks the Bars option of the display switch Lines, Bars, Points, Stacked lines and Stacked bars

Jump from a log line to a trace

  1. Select all in the editor and type the stream selector again:

    {application="bookshelf"}
  2. Click Run query.

  3. Click a log line to expand it.

  4. Next to the field trace_id, click the Trace button. It is the derived field of the provisioned Loki data source; Grafana opens the trace with that identifier in Tempo next to the logs, as in the figure at the top of this guide.

    Explore with Loki: a log line is expanded and lists the fields level, uri, status, trace_id and span_id; callout 19 marks the log line and callout 20 marks the Trace button next to the trace_id field

Search traces with TraceQL

  1. Open the data source picker again and click Tempo.

    Explore with the data source picker open on Loki: callout 21 marks Tempo in the list of data sources
  2. In the Tempo query editor, choose the query type TraceQL. The editor can search in other ways too; this guide uses TraceQL.

  3. Click in the editor and type a TraceQL query, which selects the traces of the service bookshelf that contain a span with the status error:

    { resource.service.name = "bookshelf" && status = error }
  4. Click Run query.

    Explore with the Tempo data source: the query type TraceQL is marked by callout 22, the TraceQL query for the service bookshelf with status error is typed into the editor and marked by callout 23, and the Run query button is marked by callout 24
  5. Click a trace of the result list to open it. If the list is empty, no request has failed in the last hour: run curl -X POST localhost:8090/mode/failing, wait a minute, run the query again and restore mode/normal afterwards.

Explore the logs with Drilldown

  1. In the left navigation, click Drilldown, then Logs. It opens the app Logs Drilldown in the page /a/grafana-lokiexplore-app/explore.

    Grafana with the navigation docked at the left: callout 26 marks the Logs entry of the Drilldown menu, which lists Metrics, Logs, Traces and Profiles
  2. In the list on the tab service, click Show logs on the row bookshelf. The app shows the logs of the service with a volume chart and the values of the labels, without a query to type.

    Logs Drilldown of Grafana 13.3: controls for the data source, the labels and the time range Last 15 minutes, the tab service, and a list of service values with bookshelf and unknown_service; callout 27 marks the Show logs button of bookshelf

Check the result

  • In Explore with Loki, the query {application="bookshelf"} lists log lines, and the query of step 14 draws one line for 200 and one for 404.

  • A log line that carries a trace_id shows the Trace button, and the button opens the trace of that request in Tempo, with the root span GET /api/books for a request to that route.

  • Drilldown → Logs lists the service bookshelf on the tab service.

To produce failed requests and error logs, use the load generator, and restore normal traffic afterwards:

curl -X POST localhost:8090/mode/failing
curl -X POST localhost:8090/mode/log-errors
curl -X POST localhost:8090/mode/normal

curl localhost:8090/ shows the current mode.

Variations

  • Query the stream with {service_name="bookshelf"} or {job="bookshelf"}: the three selectors address the same lines in this lab.

  • Open Explore with Prometheus in one pane and Loki in a second pane with Split, and compare the request rate with the log volume over the same time range.

  • Start from a trace: in Tempo open a trace, then use the link of a span to the logs of the service if the data source is configured for it.

What can go wrong

Symptom Cause Fix

The query returns No data

The time range is too short or the lab started less than a minute ago, or the load generator is stopped.

Widen the time range, wait a minute, and check the mode with curl localhost:8090/; send curl -X POST localhost:8090/mode/normal if it is not normal.

The query fails with a parse error

The text was typed before the editor had the focus, or the old query was not replaced completely.

Click in the editor, select all with Ctrl+A (Cmd+A on macOS), and type the query again.

There is no Trace button next to trace_id

The data source is not the provisioned Loki, which has the derived field trace_id, or the line has no trace_id.

Choose the data source Loki, or add the derived field in the settings of your Loki data source as the data-source guide shows.

The TraceQL query returns no trace

No span with the status error exists in the time range.

Send curl -X POST localhost:8090/mode/failing, wait a minute, run the query again, and restore mode/normal.

Drilldown → Logs opens a different Loki data source

The app uses the first Loki data source in alphabetical order.

Open the Data source control at the top of the app and choose Loki.

Clean up

The guide creates nothing that Grafana stores, so there is nothing to remove. Make sure the load generator is back to curl -X POST localhost:8090/mode/normal. To stop the lab, run docker compose --profile grafana down.

Where to go next