Custom Panels

Six of the panel plugins Sophonz builds and installs into Grafana, the ones made for a single Sophonz view — what each one draws, the data and options it takes, and how it is configured in dashboard JSON.

Some views cannot be built from Grafana's stock panels. Laying one session's spans along a time axis, joining the services a trace passed through into a node-edge map, turning screen-to-screen navigation into a graph — each needs the data in a particular shape. Sophonz ships six of those views as panel plugins, documented here. Eight more general-purpose chart panels — TopN, Hitmap, Equalizer, Arc Equalizer, Waterfall, Line, Pie and Gauge — are in Sophonz Chart Panels. The dashboards they sit on, with every query, are in the Dashboard Reference.

How they are installed

Each panel is published to the CDN by version, and Grafana downloads it at startup via GF_INSTALL_PLUGINS.

https://cdn.sophonz.com/release/grafana/plugins/<panel id>/<version>/<panel id>.zip

Pin the version. Grafana's storage is an emptyDir, so plugins are re-downloaded on every restart; a floating version means a restart can change the dashboard under you.

The panels are unsigned, so the same ids also have to appear in GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS before Grafana will load them.

All fourteen panels install this way: the six below and the eight in Sophonz Chart Panels. Each entry in GF_INSTALL_PLUGINS is <url>;<panel id>, and entries are separated by commas.

GF_INSTALL_PLUGINS=https://cdn.sophonz.com/release/grafana/plugins/sophonz-kpi-panel/1.0.0/sophonz-kpi-panel.zip;sophonz-kpi-panel,https://cdn.sophonz.com/release/grafana/plugins/sophonz-topn-panel/1.0.0/sophonz-topn-panel.zip;sophonz-topn-panel
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=sophonz-kpi-panel,sophonz-topn-panel

The panels

Every shot below is the panel as deployed in the public demo organization. Click one to jump to its section.

PanelidVersion documentedDashboards
Sophonz KPIsophonz-kpi-panel1.0.0Service
Session Timelinesophonz-session-timeline-panel1.3.0Session, Session Detail
Screen Flowsophonz-session-timeline-graph-panel1.5.1Session, Session Detail
Service Flowsophonz-service-flow-panel1.4.0Session Detail
Request Mapsophonz-requestmap-panel1.0.2Service, Request Map
DynamicXHR Monitorsophonz-dynamicxhr-panel1.0.0Service

The chart panels are documented on their own page.

PanelidVersion documentedDashboards
Sophonz TopNsophonz-topn-panel1.0.0RUM, Charts
Sophonz Hitmapsophonz-hitmap-panel1.0.0RUM, Charts
Sophonz Equalizersophonz-equalizer-panel1.0.0RUM, Charts
Sophonz Arc Equalizersophonz-arc-equalizer-panel1.0.0RUM, Charts
Sophonz Waterfallsophonz-waterfall-panel1.0.0Charts
Sophonz Linesophonz-line-panel1.0.0RUM
Sophonz Piesophonz-pie-panel1.0.0RUM
Sophonz Gaugesophonz-gauge-panel1.0.0RUM

Common rules

These apply to the six panels on this page. The chart panels have their own.

  • Leave the field mapping options empty. Empty means the panel finds the field by column name (case-insensitive). Naming columns with AS in the query survives moving a dashboard around better than typing names into options.
  • title and showHeader control a title drawn inside the panel, top left. It is separate from the Grafana panel title, and an empty title draws nothing even with showHeader on. Sophonz dashboards use the Grafana title and leave this empty.
  • The JSON below is the panel definition taken from the live v3 dashboards. The per-query datasource is the same as the panel's and has been left out — Grafana falls back to the panel data source when it is missing.

Sophonz KPI

A metric card: one figure, its change against the preceding period, and a sparkline.

The six KPI cards at the top of Service (v3)

It takes three queries. Grafana's stat panel draws the headline number, the sparkline and the percent change from the same series, which means asking for either of the latter two stops the number being the figure for the period. Measured against a day of real traffic, summing per-bucket unique sessions overcounts the true unique session count by 31% — a session crossing a bucket boundary is counted twice — and the mean of per-bucket means is 14% above the actual mean.

So the value is asked for separately.

QueryRole
AThe value for the current period. This is the number on the card
BThe same value over the preceding period. What the change compares against
CThe series behind the card. Only ever drawn, never reduced

How values are read. For each query the panel takes the first numeric column and uses its last finite value, so A and B only need a single-row SELECT … AS v. The sparkline draws every value of C's numeric column in order, breaking the line at gaps.

Change. (A − B) / |B|. With no B query, no value, or a value of 0 there is no change indicator — the increase from nothing is infinite, so there is no number to show. A change under 0.1% shows as flat, ■.

Options

OptionDefaultMeaning
label""Card label. Falls back to the panel's own title
comparisonLabel""Caption under the change, e.g. vs previous period. Hidden when empty
unit""A Grafana unit id (short, ms, percent, bytes, …). Empty means none
decimals0Decimal places
color#015AE4Card gradient tint. The Sophonz logo three are #015AE4, #00D0CE, #FE52AF
sentimentneutralWhether a rise is good news. higher-is-better colours a rise green, lower-is-better red, neutral grey — the honest answer for something like a session count
showSparklinetrueWhether to draw the series
valueRefIdArefId of the query returning the current number
previousRefIdBrefId of the same number over the preceding period. No such query, no change indicator
seriesRefIdCrefId of the sparkline series
{
  "type": "sophonz-kpi-panel",
  "title": "",
  "datasource": {
    "type": "grafana-clickhouse-datasource",
    "uid": "clickhouse"
  },
  "targets": [
    {
      "refId": "A",
      "format": 1,
      "rawSql": "SELECT uniqCombined64(sessionID) AS v\nFROM sophonz_traces.distributed_sophonz_index_v2\nWHERE $__timeFilter(timestamp)\n  AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace)\n  AND $__conditionalAll(serviceName IN (${serviceName:singlequote}), $serviceName)"
    },
    {
      "refId": "B",
      "format": 1,
      "rawSql": "SELECT uniqCombined64(sessionID) AS v\nFROM sophonz_traces.distributed_sophonz_index_v2\nWHERE timestamp >= $__fromTime - ($__toTime - $__fromTime) AND timestamp < $__fromTime\n  AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace)\n  AND $__conditionalAll(serviceName IN (${serviceName:singlequote}), $serviceName)"
    },
    {
      "refId": "C",
      "format": 1,
      "rawSql": "SELECT $__timeInterval(timestamp) AS t, uniqCombined64(sessionID) AS v\nFROM sophonz_traces.distributed_sophonz_index_v2\nWHERE $__timeFilter(timestamp)\n  AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace)\n  AND $__conditionalAll(serviceName IN (${serviceName:singlequote}), $serviceName)\nGROUP BY t\nORDER BY t"
    }
  ],
  "options": {
    "color": "#015AE4",
    "comparisonLabel": "vs 이전 기간",
    "decimals": 0,
    "label": "세션 수",
    "previousRefId": "B",
    "sentiment": "neutral",
    "seriesRefId": "C",
    "showSparkline": true,
    "unit": "short",
    "valueRefId": "A"
  },
  "gridPos": {
    "h": 5,
    "w": 4,
    "x": 0,
    "y": 10
  }
}

Session Timeline

Every span one session produced, laid along a time axis in one lane per span type. It answers what the user did and what was slow while they did it, on one screen. The number before each lane name is its span count; the bar at the top is the whole session.

Session Timeline laying out one session's spans in lanes by type

Drawn on a canvas, so a session with thousands of spans still scrolls.

  • ctrl/cmd + wheel — zoom around the cursor
  • Hold space and drag — pan
  • Hover a span for its name, duration and type
  • Click a span — fills the dashboard variables traceId and spanId with it. Clicking empty space clears both
  • When the dashboard has screenStart and screenEnd (epoch ms), only that range is drawn, zoomed in. Screen Flow sets them when you pick a screen

Lanes. In order: render, event, xhr, fetch, error, anr, crash, route, longtask, websocket, webvitals, visibility, connectivity, app_lifecycle, log, user_event. Lanes without spans are not drawn. crash, error and anr use a warning colour; instant events such as event, route and webvitals, and spans under 10 ms, are drawn as dots. Native spans (isNative) and web spans get different colours.

Options

OptionDefaultMeaning
fullCategoriestrueOff draws only the render, event, crash and error lanes
timeField""Span start time. Empty uses the time-typed field
spanTypeField""Span type, which picks the lane
titleField""Span name shown in the tooltip
durationField""Duration in nanoseconds
hasErrorField""Error flag
isNativeField""Whether the span came from a native app (boolean). The v3 query derives it as webVersion = ''
spanIdField""Highlights the clicked span and fills var-spanId
traceIdField""Fills var-traceId on click
{
  "type": "sophonz-session-timeline-panel",
  "title": "Session Timeline",
  "datasource": {
    "type": "grafana-clickhouse-datasource",
    "uid": "clickhouse"
  },
  "targets": [
    {
      "refId": "A",
      "format": 1,
      "editorType": "sql",
      "queryType": "table",
      "rawSql": "SELECT lower(if(appSpanType != '', appSpanType, stringTagMap['span.type'])) AS spanType, timestamp AS startTime, if(httpURL != '', httpURL, if(appScreenName != '', appScreenName, name)) AS title, durationNano, hasError, (webVersion = '') AS isNative, spanID AS spanId, traceID AS traceId, '${spanId}' AS _selspan FROM sophonz_traces.distributed_sophonz_index_v2 WHERE $__timeFilter(timestamp) AND sessionID = '${sessionId}' AND isRootSpan = true AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace) ORDER BY timestamp"
    }
  ],
  "options": {
    "durationField": "durationNano",
    "fullCategories": true,
    "hasErrorField": "hasError",
    "isNativeField": "isNative",
    "showHeader": true,
    "spanIdField": "spanId",
    "spanTypeField": "spanType",
    "timeField": "startTime",
    "title": "",
    "titleField": "title",
    "traceIdField": "traceId"
  },
  "gridPos": {
    "h": 10,
    "w": 24,
    "x": 0,
    "y": 0
  }
}

Screen Flow

A session's navigation as a graph. Nodes are screens, and the number after × is the span count from that screen. Edges are transitions between screens, labelled with the count when it is more than one, and drawn thicker the more often they happen. A screen with at least one errored span is drawn red.

Screen Flow of an Android session's navigation

The graph opens up in three levels.

  1. Click a screen — it expands into groups by span type (like xhr ×12). At the same time the time spent on that screen goes into the screenStart and screenEnd variables, so the Session Timeline on the same dashboard zooms to it. Click again to collapse and clear the variables.
  2. Click a group — it expands into individual items. fetch and xhr show the status code and URL, like [200] /api/orders; events show the event and element, like click: Checkout; everything else shows the span name. A group draws at most 80 items.
  3. Click an item — fills traceId and spanId, moving the trace list and Gantt view to that trace.

Options

OptionDefaultMeaning
directionLRLayout direction. LR horizontal, TB vertical
timeField""Span time, used for ordering
screenField""Screen name. Becomes the node id
spanTypeField""Span type, which splits a screen into groups
hasErrorField""Error flag
titleField""Item name
urlField""URL for fetch/xhr items
statusField""HTTP status code for fetch/xhr items
eventField""Element name for event items
spanIdField, traceIdField""Values filled in when an item is clicked
{
  "type": "sophonz-session-timeline-graph-panel",
  "title": "화면 흐름 (Screen Flow)",
  "datasource": {
    "type": "grafana-clickhouse-datasource",
    "uid": "clickhouse"
  },
  "targets": [
    {
      "refId": "A",
      "format": 1,
      "editorType": "sql",
      "queryType": "table",
      "rawSql": "SELECT timestamp AS time, if(appScreenName != '', appScreenName, stringTagMap['screen.name']) AS screen, lower(if(appSpanType != '', appSpanType, stringTagMap['span.type'])) AS spanType, hasError, if(httpURL != '', httpURL, if(appScreenName != '', appScreenName, name)) AS title, if(stringTagMap['http.url'] != '', stringTagMap['http.url'], httpURL) AS url, responseStatusCode AS statusCode, if(stringTagMap['target_element_text'] != '', stringTagMap['target_element_text'], stringTagMap['target_element_tag']) AS elementName, spanID AS spanId, traceID AS traceId, '${spanId}' AS _selSpan, '${traceId}' AS _selTrace FROM sophonz_traces.distributed_sophonz_index_v2 WHERE $__timeFilter(timestamp) AND sessionID = '${sessionId}' AND isRootSpan = true AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace) ORDER BY timestamp"
    }
  ],
  "options": {
    "direction": "LR",
    "eventField": "elementName",
    "hasErrorField": "hasError",
    "screenField": "screen",
    "showHeader": true,
    "spanIdField": "spanId",
    "spanTypeField": "spanType",
    "statusField": "statusCode",
    "timeField": "time",
    "title": "",
    "titleField": "title",
    "traceIdField": "traceId",
    "urlField": "url"
  },
  "gridPos": {
    "h": 13,
    "w": 12,
    "x": 0,
    "y": 10
  }
}

Service Flow

The services a session (or a trace) passed through, as a node-edge map. Nodes are services; click one to expand it into its components. The panel header shows the service, call and trace counts.

Service Flow of a web session going through an Express server down to Prisma and the pg client

Component names. The span type when there is one; otherwise decided from the span name.

Span nameComponent
Starts with prisma:prisma
Starts with pg.pg
Starts with middlewaremiddleware
Starts with request handlerhandler
Planner, Executor, SeqScan, IndexScan …query plan
Service name is postgres, mysql, redis or clickhousedatabase
Anything elseserver (page for a frontend service)

Tiers. Decide the node colour.

TierHow it is decided
FrontendAny span of the service has clientPlatform web or browser
InfrastructureThe service name contains postgres, mysql, maria, mongo, redis, clickhouse, elastic, kafka, rabbit, memcached, cassandra or dynamodb
BackendEverything else

NOTE — Mobile apps are drawn as Backend

Frontend only checks for web and browser. A service reported by the iOS or Android SDK is drawn in the Backend colour unless its name matches one of the patterns above.

Edges come from parent/child span ids, not timestamps. There is clock skew between a browser and a server, so a time-ordered reconstruction can put the calls in the wrong order. No edge is drawn when the parent span is missing from the result, so an isRootSpan filter in the query removes every call between services.

Calls between the same two nodes merge into one edge, labelled 12.3ms for a single call or 12.3ms avg · 5× for several. Service edges only appear between different services, component edges only between different components.

Options

OptionDefaultMeaning
directionLRLayout direction. LR horizontal, TB vertical
expandAllfalseStart with every service opened to its components. Suits a single trace; leave off for a whole session
spanIdField""Empty means spanID
parentSpanIdField""Empty means parentSpanID
serviceField""Empty means serviceName
nameField""Span name, used to name components when a span has no type
durationField""Empty means durationNano. Read as milliseconds when the field name ends in ms
hasErrorField""Empty means hasError
spanTypeField""Empty means appSpanType
clientPlatformField""Empty means clientPlatform. Decides Frontend

A result frame without fields for spanID and serviceName is skipped. A traceID column, when present, is used to count traces.

{
  "type": "sophonz-service-flow-panel",
  "title": "Service Flow",
  "datasource": {
    "type": "grafana-clickhouse-datasource",
    "uid": "clickhouse"
  },
  "targets": [
    {
      "refId": "A",
      "format": 1,
      "editorType": "sql",
      "rawSql": "SELECT\n  spanID, parentSpanID, serviceName, name, appSpanType, clientPlatform,\n  durationNano, hasError, traceID\nFROM sophonz_traces.distributed_sophonz_index_v2\nWHERE $__timeFilter(timestamp)\n  AND sessionID = '${sessionId}'\n  AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace)\nORDER BY timestamp ASC\nLIMIT 20000"
    }
  ],
  "options": {
    "direction": "LR",
    "durationField": "",
    "expandAll": false,
    "hasErrorField": "",
    "nameField": "",
    "parentSpanIdField": "",
    "serviceField": "",
    "showHeader": true,
    "spanIdField": "",
    "spanTypeField": "",
    "title": ""
  },
  "gridPos": {
    "h": 13,
    "w": 12,
    "x": 12,
    "y": 10
  }
}

Request Map

A heatmap of HTTP and XHR latency over time. Time runs across, response time up (log scale, up to 10 s). A cell's colour is the dominant status class in it (2xx/3xx/4xx/5xx), and its shade is the request count in five steps.

The request heatmap on Service (v3). Hovering a cell shows its range and counts by status

Hovering a cell shows its time range, response-time range, total requests and the count per status class.

Cell size. Cells are square. The time bin is the smallest of 2.5 s, 5 s, 10 s, 15 s, 30 s, 1 m, 2 m, 5 m and 10 m that keeps cells at least 4 px wide. Cells are at most 18 px, with 8–120 rows. A status code outside 2xx–5xx (such as 0) counts as 5xx.

Options

OptionDefaultMeaning
binMs0Time bin width in ms. 0 fits the panel size. A width that would make cells narrower than 4 px is raised to a wider step
timeField""Request time. Empty uses the time-typed field
responseTimeField""Response time in ms. Empty picks a numeric column whose name contains responsetime, duration, latency, elapsed, …
statusField""HTTP status code. Empty looks for statuscode, status, code, …
countField""Request count for pre-aggregated rows. Empty looks for a numeric column named like count, hits, requests or total, otherwise each row is one request

A result frame where neither a response time nor a status field can be found is skipped. For a high-traffic service, passing pre-aggregated rows with countField is lighter than raw rows.

{
  "type": "sophonz-requestmap-panel",
  "title": "리퀘스트 히트맵 (Request Map)",
  "datasource": {
    "type": "grafana-clickhouse-datasource",
    "uid": "clickhouse"
  },
  "targets": [
    {
      "refId": "A",
      "format": 1,
      "editorType": "sql",
      "queryType": "table",
      "rawSql": "SELECT timestamp AS time, durationNano / 1e6 AS responseTime, responseStatusCode AS statusCode FROM sophonz_traces.distributed_sophonz_index_v2 WHERE $__timeFilter(timestamp) AND lower(if(appSpanType != '', appSpanType, stringTagMap['span.type'])) IN ('xhr','fetch') AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace) AND $__conditionalAll(serviceName IN (${serviceName:singlequote}), $serviceName) ORDER BY timestamp LIMIT 100000"
    }
  ],
  "options": {
    "binMs": 0,
    "countField": "",
    "responseTimeField": "responseTime",
    "showHeader": true,
    "statusField": "statusCode",
    "timeField": "time",
    "title": ""
  },
  "gridPos": {
    "h": 10,
    "w": 12,
    "x": 12,
    "y": 0
  }
}

DynamicXHR Monitor

An animated view of request traffic. Requests stream in as dots and pass through a band in the middle, split into success (blue) and failure (pink) by ratio. The ratios sit on the band, the session count bottom left, and the success and error counts bottom right.

DynamicXHR Monitor showing requests and the failure ratio for the time range

It is less something you read a number off than a way to see at a glance whether traffic is flowing at all.

How values are read. It takes three numbers: total, error and session. For a time series, each column's last value is used. The failure ratio is round(error / total × 100) and success is the rest; error is capped at total. The v3 query counts xhr/fetch with a status code of 0 or 400 and above as failures.

Options

OptionDefaultMeaning
showCountstrueThe Sessions / OK / Errors counts at the bottom. 1000 and above is shortened, like 62.1k
showPercenttrueSuccess and failure ratios in the middle. Hidden when there are no requests
bounceDirectionhorizontalThe axis the band bounces along. horizontal or vertical
totalField""Total requests. Empty picks a numeric column named like total, request, count, …
errorField""Failures. Empty looks for error, fail, 5xx, 4xx, …
sessionField""Sessions. Empty looks for session, user, visitor, …

Anything not found by name is filled from the remaining numeric columns in order: total, then session, then error. Name the columns AS total, AS error and AS session and there is nothing to guess.

{
  "type": "sophonz-dynamicxhr-panel",
  "title": "DynamicXHR Monitor",
  "datasource": {
    "type": "grafana-clickhouse-datasource",
    "uid": "clickhouse"
  },
  "targets": [
    {
      "refId": "A",
      "format": 1,
      "editorType": "sql",
      "queryType": "table",
      "rawSql": "SELECT countIf(lower(if(appSpanType != '', appSpanType, stringTagMap['span.type'])) IN ('xhr','fetch')) AS total, countIf(lower(if(appSpanType != '', appSpanType, stringTagMap['span.type'])) IN ('xhr','fetch') AND (responseStatusCode = 0 OR responseStatusCode >= 400)) AS error, uniqCombined64(sessionID) AS session FROM sophonz_traces.distributed_sophonz_index_v2 WHERE $__timeFilter(timestamp) AND $__conditionalAll(serviceNamespace IN (${serviceNamespace:singlequote}), $serviceNamespace) AND $__conditionalAll(serviceName IN (${serviceName:singlequote}), $serviceName)"
    }
  ],
  "options": {
    "bounceDirection": "horizontal",
    "errorField": "error",
    "sessionField": "session",
    "showCounts": true,
    "showHeader": true,
    "showPercent": true,
    "title": "",
    "totalField": "total"
  },
  "gridPos": {
    "h": 10,
    "w": 12,
    "x": 0,
    "y": 0
  }
}