Menu
Open source

OpenTelemetry

Grafana k6 can push test run metrics in the OpenTelemetry (OTEL) metrics format to an OTEL metrics collector or a metrics backend that supports the OTEL metrics format by using the xk6-output-opentelemetry extension.

Note

This is an extension, and we’re looking for feedback and contributions and aiming to graduate it as an experimental output within Grafana k6 in a future release. Feel free to open an issue if you have any feedback or suggestions.

Metrics mapping

k6 converts all k6 metric types to an equivalent OTEL metric type, and all k6 tags to OTEL attributes. When possible, the units are also passed with the metrics.

k6 MetricOpenTelemetry Metric
CounterFloat64CounterOption
GaugeFloat64ObservableGauge
RateSplit into two Int64Counter counters named metric_name.occurred and metric_name.total. metric_name.occurred counts only the number of non-zero occurrences, and metric_name.total registers the total number of positive and negative occurrences. This might change in the future, refer to xk6-output-opentelemetry#12 for more details.
TrendFloat64Histogram

Build the k6 version

To build a k6 binary with the extension, first, make sure you have Go and Git installed on your machine.

Then, open your terminal and run the following commands:

bash
# Install xk6
go install go.k6.io/xk6/cmd/xk6@latest

# Build the k6 binary
xk6 build --with github.com/grafana/xk6-output-opentelemetry

... [INFO] Build environment ready
... [INFO] Building k6
... [INFO] Build complete: ./k6

xk6 will create the new k6 binary in the local folder.

Note

To learn more about how to build custom k6 versions, refer to xk6.

Run the k6 test

Using the k6 binary you built in the previous step, you can use the --out xk6-opentelemetry option when running your tests to use this extension:

bash
$ ./k6 run --out xk6-opentelemetry script.js

Configuration

The following options can be configured:

NameValue
K6_OTEL_METRIC_PREFIXMetric prefix. Default is empty.
K6_OTEL_FLUSH_INTERVALHow frequently to flush metrics from k6 metrics engine. Default is 1s.
K6_OTEL_EXPORT_INTERVALConfigures the intervening time between metrics exports. Default is 10s.
K6_OTEL_HEADERSConfigures headers in the W3C Correlation-Context format without additional semi-colon delimited metadata (i.e. “k1=v1,k2=v2”). Passes the headers to the exporter.
K6_OTEL_TLS_INSECURE_SKIP_VERIFYDisables server certificate verification.
K6_OTEL_TLS_CERTIFICATEConfigures the path to the root CA certificate file for TLS credentials. If it is not provided but TLS is enabled then the host’s root CAs set is used.
K6_OTEL_TLS_CLIENT_CERTIFICATEConfigures the path to the client certificate file.
K6_OTEL_TLS_CLIENT_KEYConfigures the path to the client key file.
K6_OTEL_GRPC_EXPORTER_INSECUREDisables client transport security for the gRPC exporter.
K6_OTEL_GRPC_EXPORTER_ENDPOINTConfigures the gRPC exporter endpoint. Default is localhost:4317.
K6_OTEL_HTTP_EXPORTER_INSECUREDisables client transport security for the HTTP exporter.
K6_OTEL_HTTP_EXPORTER_ENDPOINTConfigures the HTTP exporter endpoint. Default is localhost:4318.
K6_OTEL_HTTP_EXPORTER_URL_PATHConfigures the HTTP exporter path. Default is /v1/metrics.

You can also use the OpenTelemetry SDK configuration environment variables to configure the OpenTelemetry output, like the gRPC exporter configuration. The K6_OTEL_* environment variables take precedence over the OpenTelemetry SDK configuration environment variables.