OpenTelemetry Protocol(OTLP)

OpenTelemetry is a vendor-neutral open-source observability framework for instrumenting, generating, collecting, and exporting telemetry data such as traces, metrics, logs. The OpenTelemetry Protocol (OTLP) defines the encoding, transport, and delivery mechanism of telemetry data between telemetry sources, intermediate processes such as collectors and telemetry backends.

OTLP/HTTP

GreptimeDB can be used as a collector to receive OpenTelemetry Metrics via the OTLP/HTTP protocol.

API

To send OpenTelemetry Metrics to GreptimeDB through OpenTelemetry SDK libraries, use the following information:

  • URL: https://<host>/v1/otlp/v1/metrics
  • Headers:
    • X-Greptime-DB-Name: <dbname>
    • Authorization: Basic authentication, which is a Base64 encoded string of <username>:<password>. For more information, please refer to Authentication and HTTP API

The request uses binary protobuf to encode the payload, so you need to use packages that support HTTP/protobuf. For example, in Node.js, you can use exporter-trace-otlp-proto; in Go, you can use go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp; in Java, you can use io.opentelemetry:opentelemetry-exporter-otlp; and in Python, you can use opentelemetry-exporter-otlp-proto-http.

NOTE

The package names may change according to OpenTelemetry, so we recommend that you refer to the official OpenTelemetry documentation for the most up-to-date information.

For more information about the OpenTelemetry SDK, please refer to the official documentation for your preferred programming language.

Example Code

Here are some example codes about how to setup the request in different languages:

TypeScriptGoJavaPython

ts

  1. const auth = Buffer.from(`${username}:${password}`).toString('base64')
  2. const exporter = new OTLPMetricExporter({
  3. url: `https://${dbHost}/v1/otlp/v1/metrics`,
  4. headers: {
  5. Authorization: `Basic ${auth}`,
  6. "X-Greptime-DB-Name": db,
  7. },
  8. timeoutMillis: 5000,
  9. })

Go

  1. auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", *username, *password)))
  2. exporter, err := otlpmetrichttp.New(
  3. context.Background(),
  4. otlpmetrichttp.WithEndpoint(*dbHost),
  5. otlpmetrichttp.WithURLPath("/v1/otlp/v1/metrics"),
  6. otlpmetrichttp.WithHeaders(map[string]string{
  7. "X-Greptime-DB-Name": *dbName,
  8. "Authorization": "Basic " + auth,
  9. }),
  10. otlpmetrichttp.WithTimeout(time.Second*5),
  11. )

Java

  1. String endpoint = String.format("https://%s/v1/otlp/v1/metrics", dbHost);
  2. String auth = username + ":" + password;
  3. String b64Auth = new String(Base64.getEncoder().encode(auth.getBytes()));
  4. OtlpHttpMetricExporter exporter = OtlpHttpMetricExporter.builder()
  5. .setEndpoint(endpoint)
  6. .addHeader("X-Greptime-DB-Name", db)
  7. .addHeader("Authorization", String.format("Basic %s", b64Auth))
  8. .setTimeout(Duration.ofSeconds(5))
  9. .build();

python

  1. auth = f"{username}:{password}"
  2. b64_auth = base64.b64encode(auth.encode()).decode("ascii")
  3. endpoint = f"https://{host}/v1/otlp/v1/metrics"
  4. exporter = OTLPMetricExporter(
  5. endpoint=endpoint,
  6. headers={"Authorization": f"Basic {b64_auth}", "X-Greptime-DB-Name": db},
  7. timeout=5)

You can find executable demos on GitHub at the links: Go, Java, Python, and Node.js.

NOTE

The example codes above may be outdated according to OpenTelemetry. We recommend that you refer to the official OpenTelemetry documentation for the most up-to-date information.

For more information on the example code, please refer to the official documentation for your preferred programming language.

Data Model

The OTLP metrics data model is mapped to the GreptimeDB data model according to the following rules:

  • The name of the Metric will be used as the name of the GreptimeDB table, and the table will be automatically created if it does not exist.
  • All attributes, including resource attributes, scope attributes, and data point attributes, will be used as tag columns of the GreptimeDB table.
  • The timestamp of the data point will be used as the timestamp index of GreptimeDB, and the column name is greptime_timestamp.
  • The data of Gauge/Sum data types will be used as the field column of GreptimeDB, and the column name is greptime_value.
  • Each quantile of the Summary data type will be used as a separated data column of GreptimeDB, and the column name is greptime_pxx, where xx is the quantile, such as 90/99, etc.
  • Histogram and ExponentialHistogram are not supported yet, we may introduce the Histogram data type to natively support these two types in a later version.