Skip to main content

Crate grafana_plugin_sdk

Crate grafana_plugin_sdk 

Source
Expand description

A lean, protocol-first SDK for building Grafana backend plugins in Rust.

Backend plugins communicate with Grafana via gRPC (the pluginv2 protocol), run as a go-plugin subprocess. This crate implements that protocol.

The default build is intentionally small and dependency-light — it implements only what a resource/health plugin needs: custom HTTP-style requests (CallResource) and health checks (CheckHealth). Dataframe queries and streaming are opt-in behind cargo features (see below).

The crate is organised into:

The prelude re-exports the [GrafanaPlugin] derive macro and, with the data feature, the traits for building frames and fields.

The low-level generated structs are exposed in the pluginv2 module as an escape hatch, if required.

See the docs on backend plugins on grafana.com for an introduction to backend Grafana plugins.

§Logging

Emit logs with the tracing macros; install backend::layer, call backend::init_hclog_subscriber before bootstrap work, or enable Plugin::init_subscriber so they are written in the hclog format Grafana understands. This is the idiomatic replacement for the Go SDK’s backend/log logger.

§Build information

build_info! captures the plugin’s BuildInfo (id and version) from its Cargo metadata.

§Feature flags

  • automtls — go-plugin automatic mTLS, required to connect to a Grafana instance that serves backend plugins with AutoMTLS (the default). Opt-in.
  • data — dataframe support: the data module (Frame/Field), DataService/QueryData, and Arrow IPC serialization. Pulls in Apache Arrow.
  • stream — Grafana Live StreamService (implies data).
  • httpadapter — a ResourceService that serves CallResource requests by running them through an axum::Router.
  • reqwest — adds the httpclient module and an IntoHttpResponse implementation for reqwest::Response.
  • prometheus — encodes a prometheus::Registry directly into CollectMetricsResponse.
  • opentelemetry — extracts distributed trace context from Grafana’s incoming gRPC metadata and attaches it to each request’s tracing span.
  • gen-proto — regenerate the protobuf bindings using a vendored protoc binary.

Re-exports§

pub use arrow;

Modules§

backend
Functionality for use by backend plugins.
buildinfo
Plugin build information.
data
Data types used throughout the SDK.
httpadapter
Serve Grafana CallResource requests using an axum::Router.
httpclient
A configurable HTTP client for calling Grafana or other services.
live
Grafana Live features, providing streaming functionality to Grafana.
pluginv2
The low-level structs generated from protocol definitions.
prelude
Contains useful helper traits, in particular the [GrafanaPlugin] derive macro and (with the data feature) the traits for constructing Fields and Frames.

Macros§

build_info
Capture BuildInfo from the calling crate’s Cargo package metadata.

Attribute Macros§

main
Generates a main function that starts a Plugin with the returned service struct.