Sending and reading data with the OPCP Observability gateway
Find out how to send logs, metrics and traces to the Observability service and read them back through the gateway of your Organization, with curl, Grafana Alloy and the OpenTelemetry SDK
Alpha version — This guide documents the alpha version of Cloud Store. Features, interfaces and procedures will change until general availability (GA), and this guide will be updated along with them.
Objective
This guide shows Organization users how to send logs, metrics and traces to the Observability service, and read them back, through the gateway of their Organization.
It starts with how the gateway works, then gives three end-to-end examples: curl, Grafana Alloy on a server, and an application with the OpenTelemetry SDK.
Requirements
- The Observability service enabled for your Organization by your IT Admin (see the "Enabling the service for an Organization" section of the "Deploying the Observability service on OPCP" guide).
- The address of the gateway: the
gateway_urllink in theOverviewtab of the service in the OPCP Cloud Console. - Three values from your IT Admin: a client ID, a client secret and the token URL of your Organization's realm (see the "Giving an Organization push credentials" section of the "Deploying the Observability service on OPCP" guide).
- A Linux machine with
curlandjqfor the examples.
Instructions
Which example do you need?
How the gateway works
- The gateway is one HTTPS address for all the data of your Organization. Your Grafana uses it too.
- Each request carries a token from your Organization's Keycloak realm, in an
Authorization: Bearerheader. Without a valid token, the gateway answers401. - The gateway stores and reads the data in the space of your Organization. You never set a tenant yourself.
- It speaks the standard APIs of Loki, Mimir (Prometheus) and Tempo, and OTLP (OpenTelemetry). Most tools that support them work as they are.
In the Alpha, a token gives full access to the data of your Organization: write, read, alert rules and deletion. Keep the client secret like a password.
Gateway API
Add the path to the gateway_url.
Write:
Read:
Not supported: OTLP over gRPC, and OTLP JSON for logs and metrics.
Limits: logs, metrics and traces above a rate limit are refused with an HTTP 429 error, and agents send them again later. A metrics request may be up to 16Â MiB. A logs or traces request must stay under 4Â MiB, the burst limit of your Organization: a larger one is always refused, so send smaller batches. Agents and SDKs send much smaller batches by default. The Observability limits of your Organization are listed in the "Data retention and limits" section of the "Using the Observability service on OPCP" guide.
Getting a token
A token expires after a few minutes. When the gateway returns 401, run TOKEN=$(token) again. Alloy and the OpenTelemetry Collector renew the token by themselves.
Example 1: writing and reading with curl
Run the commands in the "Getting a token" section first.
Logs
-
Write a log line. A
204response means it was accepted: -
Read it back:
Traces
-
Write a span. A
200response means it was accepted: -
Read the trace by its ID, or search for it. A new trace can take a few seconds to show up:
Metrics
Metrics are written in binary formats (remote write, OTLP protobuf), so curl is not practical for writing them: use Example 2 or Example 3. Reading works with curl:
Example 2: Grafana Alloy on a server
This example installs Grafana Alloy on a Debian server. Alloy:
- sends the systemd journal to Loki;
- sends the system metrics (CPU, memory, disk, network) to Mimir;
- accepts OTLP from the server's applications on
127.0.0.1:4318and forwards it (see Example 3).
Alloy gets and renews the token, keeps the data and resends it when the gateway temporarily refuses it.
-
Install Alloy:
On a server without Internet access, copy the Alloy
.debpackage to the server, install it withsudo apt-get install ./alloy_<version>_amd64.deb, then runsudo usermod -aG systemd-journal alloy. -
Store the client secret in
/etc/default/alloy, by adding the line: -
Replace the content of
/etc/alloy/config.alloywith the following, after filling in<gateway_url>,<client-id>and<token-url>: -
Restart Alloy and check that it runs without errors:
-
Check the data, in Grafana
Exploreor with curl as in Example 1:- Loki:
{job="systemd-journal"}shows the system logs; - Mimir:
node_load1shows the load of the server.
- Loki:
If curl or Alloy reports a certificate error, add the CA certificate of your platform to the server: copy it to /usr/local/share/ca-certificates/ with the extension .crt, then run sudo update-ca-certificates and restart Alloy. Your IT Admin can give you the certificate.
Example 3: an application with the OpenTelemetry SDK
The application sends its traces, metrics and logs with the OpenTelemetry SDK to the local Alloy of Example 2, which forwards them to the gateway:
The application needs no credentials: Alloy adds and renews the token.
This example instruments a small Python web application without changing its code.
-
Create a Python virtual environment, then install Flask and the OpenTelemetry packages:
-
Create
app.py: -
Point the SDK at Alloy and start the application:
-
In another terminal, call the application a few times:
-
Check the data in Grafana
Explore:- Tempo:
{resource.service.name="my-app"}shows the requests as traces; - Loki:
{service_name="my-app"}shows the log lines; - Mimir: open the
Metrics browserand search forhttp_serverto see the request metrics.
- Tempo:
The OTEL_SERVICE_NAME and OTEL_EXPORTER_OTLP_* variables work the same way with the OpenTelemetry SDKs and agents for other languages, for example Java, Go, Node.js and .NET.
For a quick test without Alloy, the SDK can send directly to the gateway with OTEL_EXPORTER_OTLP_ENDPOINT=<gateway_url>/otlp and OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>". The SDK does not renew the token, so this stops working after a few minutes.
Go further
Using the Observability service on OPCP
Deploying the Observability service on OPCP
For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.
Join our community of users.