Grafana Guide: Add a Data Source

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 add five data sources of your own, each prefixed guide-: guide-prometheus for metrics, guide-loki for logs, guide-tempo for traces, guide-postgres for the Bookshelf database and guide-testdata for generated sample data. You test every connection with Save & test, and you link logs to traces by giving guide-loki a derived field that opens the trace of a log line in guide-tempo. The later guides query these data sources, and the provisioned ones stay untouched.

Data sources page of Grafana 13.3 after the guide: the new data sources guide-loki, guide-postgres, guide-prometheus, guide-tempo and guide-testdata are listed above the four provisioned ones, Loki, Prometheus as the default, Tempo and TestData

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, First steps in Grafana, or at least know how to sign in and use the left navigation.

  • The lab provisions four data sources, Prometheus (the default), Loki, Tempo and TestData. They are read-only in the interface. The lab does not provision a PostgreSQL data source, which is why this guide adds it by hand with the connection values of the lab database.

  • The connection URLs use the host names of the lab network (prometheus, loki, tempo, postgres), because Grafana runs inside it. localhost would point at the Grafana container itself.

  • The guide was checked on Grafana Enterprise 13.3.0 (the free image, no licence key). Adding data sources needs the Admin role of the organization; 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.

Steps

Grafana 13.3 creates a data source at once when you click its type card, with a placeholder name such as prometheus-1, and the settings page has no Name field any more. You rename the data source with the pencil next to its title.

Open the data sources page

  1. In the left navigation, click Connections.

  2. Click Data sources. The list shows Loki, Prometheus (marked as the default), Tempo and TestData.

  3. Click Add new data source. The entry Add new connection of the same group opens the plugin catalogue, which needs internet access; do not use it here.

    Data sources page of Grafana 13.3 with the Connections group of the navigation open: callout 1 marks Connections, callout 2 marks Data sources and callout 3 marks the Add new data source button; the list shows Loki, Prometheus as the default, Tempo and TestData

Add Prometheus

  1. On the page Add data source, click the card Prometheus. Grafana creates the data source and opens its settings page under the name prometheus-1.

    Add data source page of Grafana 13.3 listing the type cards of Time series databases: Prometheus with its logo, Graphite, InfluxDB and OpenTSDB; callout 4 marks the Prometheus card
  2. Click the pencil (Edit title) next to the title, replace the name with guide-prometheus and confirm it.

    Settings page of the new data source, which Grafana 13.3 created at once under the name prometheus-1: callout 5 marks the Edit title pencil next to the title; the page has the tabs Settings, Permissions, Insights and Cache
  3. Under Connection, type the address of the Prometheus container in Prometheus server URL:

    http://prometheus:9090
  4. Leave Authentication method at No Authentication and click Save & test at the bottom of the page.

    Settings page of guide-prometheus: the field Prometheus server URL holds http://prometheus:9090 (callout 6) and the Save and test button at the bottom is marked by callout 7
  5. A green alert reads Successfully queried the Prometheus API. The data source is ready. Do not click Make default: the provisioned Prometheus stays the default.

    Settings page of guide-prometheus after Save and test: a green alert reads Successfully queried the Prometheus API, marked by callout 8

Add Loki and Tempo

  1. Open Connections → Data sources, click Add new data source, and click the card Loki.

  2. Click the pencil next to the title and rename the data source to guide-loki.

  3. Under Connection, type the address of the Loki container in URL:

    http://loki:3100
  4. Click Save & test. The message Data source successfully connected. appears, followed by a hint to build a dashboard or to open Explore.

    Settings page of guide-loki: the pencil next to the title is marked by callout 10, the field URL holds http://loki:3100 (callout 11) and the Save and test button is marked by callout 12
  5. Open Connections → Data sources, click Add new data source, and click the card Tempo.

  6. Click the pencil next to the title and rename the data source to guide-tempo.

  7. Under Connection, type the address of the Tempo container in URL:

    http://tempo:3200
  8. Click Save & test. The message Data source is working appears.

    Settings page of guide-tempo: the pencil next to the title is marked by callout 14, the field URL holds http://tempo:3200 (callout 15) and the Save and test button is marked by callout 16

Add PostgreSQL

  1. Open Connections → Data sources, click Add new data source, and type postgres in the box Filter by name or type.

  2. Click the card PostgreSQL.

    Add data source page of Grafana 13.3 with postgres typed into the filter box, marked by callout 17, and the single remaining card PostgreSQL with its logo, marked by callout 18
  3. Click the pencil next to the title and rename the data source to guide-postgres.

  4. Under Connection, type the address of the database container in Host URL:

    postgres:5432
  5. In Database name, type bookshelf.

  6. Under Authentication, type bookshelf in Username.

  7. In Password, type changeme. This is the demo password of the lab database, never a value for a real system.

  8. Set TLS/SSL Mode to disable, because the lab database does not use TLS.

  9. Click Save & test. The message Database Connection OK appears.

    Settings page of guide-postgres with the sections Connection and Authentication: the pencil next to the title is marked by callout 19, Host URL holds postgres:5432 (20), Database name holds bookshelf (21), Username holds bookshelf (22), Password holds dots (23), TLS/SSL Mode shows disable (24) and the Save and test button is marked by callout 25

Add TestData

  1. Open Connections → Data sources, click Add new data source, type testdata in the filter box, and click the card TestData.

  2. Click the pencil next to the title and rename the data source to guide-testdata.

  3. Click Save & test. The data source has no required fields, and the message Data source is working appears.

    Settings page of guide-testdata, which has no required fields: the pencil next to the title is marked by callout 27 and the Save and test button is marked by callout 28

The Bookshelf service writes the trace identifier into every log line as trace_id. A derived field turns that value into a link that opens the trace in Tempo.

  1. Open Connections → Data sources and click guide-loki.

  2. Scroll to Additional settings, open Derived fields and click Add.

    Settings page of guide-loki scrolled to Additional settings: the groups Advanced HTTP settings, Alerting, Queries and Derived fields are listed and the Add button of Derived fields is marked by callout 30
  3. In the new row, give the derived field the name trace_id.

  4. Type the regular expression that captures the identifier from the log line:

    "trace_id":\s*"(\w+)"
  5. Type the query that the link sends to Tempo; it is the captured value:

    ${__value.raw}
  6. Turn on the internal link of the row and choose guide-tempo as its data source.

  7. Give the link the label Trace.

  8. Click Save & test. The message of step 12 appears again.

    Derived field row of guide-loki with five values and no field labels: the name trace_id (callout 31), the regular expression for the trace_id in the log line (32), the query ${__value.raw} (33), the internal link switch on with the data source guide-tempo (34) and the link label Trace (35); callout 36 marks the Save and test button

The figure draws the five values of the row in the order of the steps and leaves out the field labels, because the exact wording of these labels was not checked in the lab. Match each value to its field by its meaning: the name, the regular expression, the query, the internal link with its data source, and the link label.

Check the result

Open Connections → Data sources. The list must show the five new data sources guide-loki, guide-postgres, guide-prometheus, guide-tempo and guide-testdata above the four provisioned ones, and each one must have answered Save & test with its success message.

To see data flow through a new data source, open Explore, choose guide-prometheus in the data source picker and run the query up with the blue Run query button. Generate some traffic first and restore it afterwards:

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

Variations

  • Add the same data sources from files instead: the lab provisions its own with the file grafana/provisioning/datasources/datasources.yaml, which the reference page Data sources explains.

  • The settings page of guide-prometheus has more options under Advanced settings, for example Scrape interval and Query timeout. The defaults are fine for these guides.

What can go wrong

Symptom Cause Fix

Save & test reports a connection error for Prometheus, Loki or Tempo

The URL uses localhost, or the container is still starting.

Use the container host names of the steps (prometheus, loki, tempo), wait a minute and click Save & test again.

PostgreSQL answers with an authentication or connection error

A typing mistake in Host URL, Username or Password, or the database container is not running.

Check the values of steps 20 to 24 and run docker compose --profile grafana ps in the lab folder; start the profile again if postgres is missing.

The data source has the name prometheus-1 or similar

The pencil step was skipped, and 13.3 gives a placeholder name at creation.

Click the pencil next to the title, enter the guide- name and click Save & test again.

The derived field shows a link but the trace does not open

The data source of the internal link is not guide-tempo, or the query is not the captured value.

Open the derived field again, check the data source and the query of steps 33 and 34, and save.

The provisioned data sources cannot be edited

The lab provisions them from files, which makes them read-only.

Edit your own guide- data sources instead, or change the provisioning file.

Clean up

Keep the data sources: the following guides query them. To delete one, open it from Connections → Data sources and click Delete at the bottom of its settings page. Stopping the profile with docker compose --profile grafana down -v also removes everything the lab stores, including these data sources.

Where to go next