Skip to main content

Datasource Configuration

Learning Objectives

  • Configure a Prometheus (xMetrics) datasource with xScaler authentication
  • Configure a xLogs datasource with xScaler authentication
  • Configure a xTraces datasource with xScaler authentication
  • Set up trace-to-logs and trace-to-metrics correlation
  • Use YAML provisioning for GitOps-managed datasource configuration

Prerequisites

Before configuring datasources, you need:

  • Grafana instance running (local dev: https://<slug>.g.xscalerlabs.com)
  • xScaler tenant ID (xs_...)
  • xScaler API key (xag_...)
  • xScaler endpoint URLs (from tenant details)

Metrics Datasource (Prometheus → xMetrics)

  1. Navigate to Connections → Data Sources → Add data source
  2. Select Prometheus
  3. Configure:

[Screenshot: Grafana Prometheus datasource configuration page showing URL and header fields]

FieldValue
NamexScaler Metrics
URLhttps://euw1-01.m.xscalerlabs.com/prometheus
HTTP MethodPOST
Custom Headers → Header 1 NameAuthorization
Custom Headers → Header 1 ValueBearer xag_your_api_key
Custom Headers → Header 2 NameX-Scope-OrgID
Custom Headers → Header 2 Valuexs_your_tenant_id
  1. Click Save & Test → expected: "Data source connected and labels found."
# grafana/provisioning/datasources/xscaler.yaml
apiVersion: 1
datasources:
- name: xScaler Metrics
type: prometheus
access: proxy
url: https://euw1-01.m.xscalerlabs.com/prometheus
uid: xscaler-metrics
isDefault: true
jsonData:
httpMethod: POST
timeInterval: 30s
manageAlerts: true
alertmanagerUid: xscaler-alertmanager
customQueryParameters: ""
secureJsonData:
httpHeaderName1: Authorization
httpHeaderValue1: "Bearer xag_your_api_key"
httpHeaderName2: X-Scope-OrgID
httpHeaderValue2: xs_your_tenant_id

Logs Datasource (xLogs)

  1. Connections → Add data source → xLogs
FieldValue
NamexScaler Logs
URLhttps://euw1-01.l.xscalerlabs.com
Custom Headers → AuthorizationBearer xag_your_api_key
Custom Headers → X-Scope-OrgIDxs_your_tenant_id
  1. Configure Derived Fields for trace correlation:

[Screenshot: xLogs datasource with Derived Fields section showing TraceID regex pattern]

FieldValue
NameTraceID
Regextrace_id=(\w+)
Query(link to xTraces datasource)
Internal linkSelect xScaler Traces datasource
- name: xScaler Logs
type: loki
access: proxy
url: https://euw1-01.l.xscalerlabs.com
uid: xscaler-logs
jsonData:
derivedFields:
- datasourceUid: xscaler-traces
matcherRegex: "trace_id=(\\w+)"
name: TraceID
url: "${__value.raw}"
secureJsonData:
httpHeaderName1: Authorization
httpHeaderValue1: "Bearer xag_your_api_key"
httpHeaderName2: X-Scope-OrgID
httpHeaderValue2: xs_your_tenant_id

Traces Datasource (xTraces)

  1. Connections → Add data source → xTraces
FieldValue
NamexScaler Traces
URLhttps://euw1-01.t.xscalerlabs.com
Custom Headers → AuthorizationBearer xag_your_api_key
Custom Headers → X-Scope-OrgIDxs_your_tenant_id
  1. Configure Trace to Logs:

    • Data source: xScaler Logs
    • Filter by Trace ID: ✓
    • Tags: service.name, deployment.environment
  2. Configure Trace to Metrics:

    • Data source: xScaler Metrics
    • Tags: service.name → service
  3. Enable Service Map:

    • Data source: xScaler Metrics
- name: xScaler Traces
type: tempo
access: proxy
url: https://euw1-01.t.xscalerlabs.com
uid: xscaler-traces
jsonData:
httpMethod: GET
tracesToLogs:
datasourceUid: xscaler-logs
filterByTraceID: true
filterBySpanID: false
tags: ["service.name", "deployment.environment"]
tracesToMetrics:
datasourceUid: xscaler-metrics
tags: [{key: "service.name", value: "service"}]
queries:
- name: Error rate
query: "sum(rate(http_errors_total{$__tags}[5m]))"
serviceMap:
datasourceUid: xscaler-metrics
nodeGraph:
enabled: true
lokiSearch:
datasourceUid: xscaler-logs
secureJsonData:
httpHeaderName1: Authorization
httpHeaderValue1: "Bearer xag_your_api_key"
httpHeaderName2: X-Scope-OrgID
httpHeaderValue2: xs_your_tenant_id

Hands-On Exercise

Exercise 5.3 — Configure All Three Datasources

# For local dev environment
export GRAFANA_URL="https://<your-org-slug>.g.xscalerlabs.com"
export GRAFANA_USER="admin"
export GRAFANA_PASS="admin"

# Create Metrics datasource via Grafana API
curl -s -X POST "$GRAFANA_URL/api/datasources" \
-u "$GRAFANA_USER:$GRAFANA_PASS" \
-H "Content-Type: application/json" \
-d '{
"name": "Training Metrics",
"type": "prometheus",
"access": "proxy",
"url": "http://xMetrics:9009/prometheus",
"jsonData": {
"httpHeaderName1": "X-Scope-OrgID"
},
"secureJsonData": {
"httpHeaderValue1": "'"<your-tenant-id>"'"
}
}' | jq '.message'

# Test the datasource
DS_ID=$(curl -s "$GRAFANA_URL/api/datasources/name/Training%20Metrics" \
-u "$GRAFANA_USER:$GRAFANA_PASS" | jq '.id')

curl -s "$GRAFANA_URL/api/datasources/$DS_ID/health" \
-u "$GRAFANA_USER:$GRAFANA_PASS" | jq .

Exercise 5.4 — Verify Cross-Signal Correlation

  1. In Grafana Explore, select xTraces datasource
  2. Click Search → Run Query
  3. Click any trace → expand a span
  4. Click the Logs button — you should see log lines from xLogs filtered by trace_id

[Screenshot: xTraces trace view with a span expanded and "Logs for this span" panel showing log lines from xLogs]


Validation

  • All three datasources show green status (✓) in Connections → Data Sources
  • PromQL rate(http_requests_total[5m]) returns data in Metrics datasource
  • LogQL {service=~".+"} returns log streams in Logs datasource
  • xTraces search returns trace results
  • Clicking a trace span opens the related xLogs logs panel

Troubleshooting

Datasource returns 401

Verify the API key is valid and the tenant ID is correct:

curl -s https://euw1-01.m.xscalerlabs.com/prometheus/api/v1/query \
-H "Authorization: Bearer $API_KEY" \
-H "X-Scope-OrgID: $TENANT_ID" \
--data-urlencode 'query=up' | jq .status
xTraces datasource: 'No traces found'

Check that traces are being ingested:

curl -s "https://<edge>.t.xscalerlabs.com/api/v2/search" \
-H "X-Scope-OrgID: $TENANT_ID" | jq .traces
xLogs derived field TraceID not linking

Verify the regex matches the actual log format. Check a real log line:

{service=~".+"} |= "trace_id"

Key Takeaways

Session 5.3 Summary
  • Three datasources required: Prometheus (xMetrics), xLogs, xTraces
  • All three require Authorization: Bearer xag_... and X-Scope-OrgID: xs_... headers
  • Use secureJsonData for header values — they are stored encrypted in Grafana
  • Derived fields in xLogs connect log entries to traces via trace_id
  • Trace to Logs and Trace to Metrics enable cross-signal correlation in xTraces
  • Use YAML provisioning for GitOps-managed, reproducible datasource configuration

← Previous: Deployment Options
Next: Session 6 Overview →