Skip to content

This page is about collecting telemetry data from instrumented R packages. If you need help with instrumenting your R package, see Getting Started in the otel package.

Value

Not applicable.

Usage

  • Instrument your R package or project using the otel package. Alternatively, use Zero Code Instrumentation to automatically instrument selected packages.

  • Install the otelsdk package.

  • Choose an exporter from the otelsdk package. The http exporter sends OpenTelemetry output through OTLP/HTTP.

  • Set the OTEL_TRACES_EXPORTER environment variable to point to the exporter of your choice. E.g. for OTLP/HTTP set OTEL_TRACES_EXPORTER=http.

  • If you are sending telemetry data through HTTP, then you typically need to configure the URL of your OpenTelemetry collector, and you possibly also need to supply a token in an HTTP header, possibly some resource attributes. Follow the instructions of the provider of your collector. They typically don't have instructions for R, but generic instructions about environment variables will work for the otelsdk R package. E.g. for Grafana you need something like

    OTEL_EXPORTER_OTLP_PROTOCOL="http"
    OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-central-0.grafana.net/otlp" \
    OTEL_RESOURCE_ATTRIBUTES="service.name=<name-of-your-app>,service.namespace=<name-of-your-namespace>,deployment.environment=test"
    OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20<base64-encoded-token>"

    See more examples below.

  • See all environment variables and the manual of your chosen provider for details on configuring otelsdk exporters.

  • Start R and your app. Telemetry data will be exported to the chosen exporter.

Setup

Setup for remote collectors

There are a lot of services that offer an OpenTelemetry collector for tracers, logs and metrics, many of them supporting all three of them. There are also local apps that work as a collector. We tried otelsdk with the following ones:

Grafana

Follow the documentation. Create an API token. You'll need to use the Grafana instrance ID as your username, and the token as the password in HTTP Basic auth. E.g. in R do this to get the base64 encoded token. instance-id is a (currently seven digit) number and a string with a glc_ prefix.

openssl::base64_encode("<instance-id>:<api-token>")

Then use this encoded token to set the Authorization header:

OTEL_EXPORTER_OTLP_PROTOCOL="http"
OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-central-0.grafana.net/otlp" \
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20<base64-encoded-token>"
OTEL_RESOURCE_ATTRIBUTES="service.name=<name-of-your-app,service.namespace=<name-of-your-namespace>,deployment.environment=test"

Your endpoint URL is probably different, use the one that you see on your dashboard.

If you want to export logs and/or metrics, set these environment variables, respectively:


OTEL_LOGS_EXPORTER=http
OTEL_LOG_LEVEL=debug
OTEL_METRICS_EXPORTER=http

It also makes sense to set the desired log level.

Grafana suggests running an OpenTelemetry collector on premise instead of sending telemetry data to them directly. But nevertheless you can start out without running your own collector, they call this "quick start" mode.

Pydantic Logfire

Create a project and a write token. Note that the URLs you need to use are different if you are within the EU! You probably need to replace us with eu in the URL if you are in the EU. Set these environment variables:

OTEL_TRACES_EXPORTER=http
OTEL_EXPORTER_OTLP_ENDPOINT="https://logfire-us.pydantic.dev"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=<your-write-token>"

For logs also set OTEL_LOGS_EXPORTER and the desired log level:

OTEL_LOGS_EXPORTER=http
OTEL_LOG_LEVEL=debug

For exporting metrics also set

OTEL_METRICS_EXPORTER=http

Setup for local collectors

otel-tui

otel-tui is a terminal app that supports traces, logs and metrics. It is great for development, as you can keep all your telemetry local while instrumenting your package or app. Follow the installation instructions and then run the app from a terminal:

otel-tui

It listens on the default port, so the setup is very simple, set these environment variables (or a subset if you don't want metrics or logs):

OTEL_TRACES_EXPORTER=http
OTEL_LOGS_EXPORTER=http
OTEL_LOG_LEVEL=debug
OTEL_METRICS_EXPORTER=http

otel-desktop-viewer

otel-desktop-viewer is similar to otel-tui, but has a web UI. Follow the installation instructions and start the app from a terminal:

otel-desktop-viewer

It should start a new windows or tab in your local web browser. Set the usual environment variable for your R app:

OTEL_TRACES_EXPORTER=http

Jaeger

If you have Docker, you can start a Jaeger container on the default port:

docker run --rm --name jaeger \
 -p 16686:16686 \
 -p 4317:4317 \
 -p 4318:4318 \
 -p 5778:5778 \
 -p 9411:9411 \
 jaegertracing/jaeger:2.4.0

Go to http://localhost:16686/ to view the Jaeger UI.

SigNoz

To run SigNoz locally with Docker, clone the repository at https://github.com/SigNoz/signoz:

git clone --depth 1 https://github.com/SigNoz/signoz

and then run Docker Compose from the deploy/docker/ subdirectory:

cd deploy/docker
docker compose up

Go to http://localhost:8080 to see the SigNoz UI.

Examples

# See above