# OpenTelemetry custom metrics

Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fintegrations%2Fdata-ingestion%2Fopentelemetry-custom-metrics.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fintegrations%2Fdata-ingestion%2Fopentelemetry-custom-metrics.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

Coralogix provides a scalable Prometheus-compatible managed service for time-series data. Employ our **custom metric endpoint**, including serverless computing and quick cURL-like calls, to send counters, gauges, and histograms to Coralogix.

## Overview[​](#overview "Direct link to Overview")

Coralogix supports ingesting metrics in multiple ways. Our most common integrations are [Prometheus](https://coralogix.com/docs/docs/integrations/metrics/prometheus/.md) & [OpenTelemetry](https://coralogix.com/blog/tag/opentelemetry/), as well as metric-specific integrations such as [CloudWatch metrics](https://coralogix.com/docs/docs/integrations/aws/amazon-data-firehose/aws-cloudwatch-metric-streams-with-amazon-data-firehose/.md) and [AWS Kinesis Firehose](https://coralogix.com/docs/docs/integrations/aws/amazon-data-firehose/send-logs-using-amazon-data-firehose/.md). View a full list of available integrations [here](https://coralogix.com/integrations/).

This tutorial presents a series of use cases employing our custom metric endpoint, referred to as the <!-- -->ingress.:443<!-- --> endpoint, to send your data to Coralogix. The examples below employ gRPCurl and OpenTelemetry Java SDK.

Coralogix metrics employs the [Prometheus data model](https://prometheus.io/docs/concepts/data_model/), wherein metrics sent can be in the form of counters, gauges, and histograms.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

If you are sending us your data using gRPCurl, you are required to have [Git](https://git-scm.com/) and [gRPCurl](https://github.com/fullstorydev/grpcurl) installed.

## Data model[​](#data-model "Direct link to Data model")

The custom logs API implementation is based on the OpenTelemetry [metric specification](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto). This ensures that our logging implementation adheres to industry best practices and can seamlessly integrate with other components and tools in the OpenTelemetry ecosystem.

### Counter & gauge example[​](#counter--gauge-example "Direct link to Counter & gauge example")

```
{

  "resource_metrics": {

    "resource": {

      "attributes": [

        {

          "key": "cx.application.name",

          "value": {

            "string_value": "my-test-application"

          }

        },

        {

          "key": "cx.subsystem.name",

          "value": {

            "string_value": "my-test-subsystem"

          }

        },

        {

          "key": "service.name",

          "value": {

            "string_value": "my-test-service"

          }

        }

      ]

    },

    "scope_metrics": {

      "metrics": [{

        "name": "grpc_sample_gauge1",

        "gauge": {

          "data_points": [{

            "as_double": 0.8,

            "start_time_unix_nano": 1657079957000000000,

            "time_unix_nano": 1657079957000000000

          }]

        }

      },{

        "name": "grpc_sample_counter1",

        "gauge": {

          "data_points": [{

            "as_int": 100,

            "start_time_unix_nano": 1657079957000000000,

            "time_unix_nano": 1657079957000000000

          }]

        }

      }]

    }

  }

}
```

**Notes**:

* Currently both timestamps as well as `service.name` are mandatory.

## Sending data with gRPCurl[​](#sending-data-with-grpcurl "Direct link to Sending data with gRPCurl")

gRPC is a modern way of calling APIs on top of HTTP/2. Similar to cURL, [gRPCurl](https://github.com/fullstorydev/grpcurl) is a command-line tool used to communicate with gRPC services.

Coralogix supports OTLP/gRPC and OTLP/HTTP (binary protobuf or JSON payloads) for its custom metrics endpoint.

Assuming the example in the data model is saved as `metrics.json`, use the following command to send your data to Coralogix:

```
# Clone OpenTelemetry protobuf definitions

git clone https://github.com/open-telemetry/opentelemetry-proto.git

# Send metrics to Coralogix 

grpcurl -v -d @ \

  -rpc-header 'Authorization: Bearer <send-your-data-api-key>' \

  -proto opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto \

  -import-path opentelemetry-proto \

  ingress.eu2.coralogix.com:443 \

  opentelemetry.proto.collector.metrics.v1.MetricsService/Export \

  < metrics.json
```

**Notes**:

* For `<open-telemetry-endpoint>`, select the <!-- -->ingress.:443<!-- --> endpoint that corresponds to your Coralogix [domain](https://coralogix.com/docs/docs/user-guides/account-management/account-settings/coralogix-domain/.md) using the domain selector at the top of the page.

* For the `<send-your-data-api-key>`, input your Coralogix [Send-Your-Data API key](https://coralogix.com/docs/docs/user-guides/account-management/api-keys/send-your-data-api-key/.md).

* Set the `start_time_unix_nano` and the `time_unix_nano` in the `metrics.json` to a timestamp that is within the last 24 hours.

## Sending data using the OpenTelemetry Java SDK[​](#sending-data-using-the-opentelemetry-java-sdk "Direct link to Sending data using the OpenTelemetry Java SDK")

The example below guides you using OpenTelemetry Java SDK to send your custom traces to Coralogix. Others [SDKs](https://opentelemetry.io/docs/concepts/sdk-configuration/) may also be used.

**STEP 1**. Add to your maven pom.xml the following libraries:

```
<dependency>

  <groupId>io.opentelemetry</groupId>

  <artifactId>opentelemetry-sdk-metrics</artifactId>

  <version><!-- put a recent version of opentelemetry sdk here --><version>

</dependency>

<dependency>

  <groupId>io.opentelemetry</groupId>

  <artifactId>opentelemetry-exporter-otlp</artifactId>

  <version><!-- put a recent version of opentelemetry sdk here --><version>

</dependency>
```

**STEP 2**. Use this code snippet to generate a counter and a gauge:

```
SdkMeterProvider meterProvider =

      SdkMeterProvider.builder()

        .registerMetricReader(

          PeriodicMetricReader.builder(

            OtlpGrpcMetricExporter.builder()

              .setEndpoint("https://ingress.eu2.coralogix.com:443")

              .addHeader("Authorization", "Bearer <send-your-data-api-key>")

              .build()

          ).build()

        )

        .setResource(Resource.create(Attributes.of(

          ResourceAttributes.SERVICE_NAME, "my-test-service",

          AttributeKey.stringKey("cx.application.name"), "my-test-application",

          AttributeKey.stringKey("cx.subsystem.name"), "my-test-subsystem")))

        .build();



    Meter meter = meterProvider.meterBuilder("test").build();



    LongCounter counter = meter

      .counterBuilder("otlp_test_counter1")

      .setDescription("Processed jobs")

      .build();

    counter.add(100);



    meter

      .gaugeBuilder("otlp_test_gauge1")

      .buildWithCallback(measurement -> {

        measurement.record(0.8);

      });

    meterProvider.forceFlush();
```

**Notes**:

* Currently the `service.name` attribute is mandatory on each metric.

## Limits & quotas[​](#limits--quotas "Direct link to Limits & quotas")

* Coralogix places a **hard limit of 10MB** of data to our OpenTelemetry [endpoints](https://coralogix.com/docs/docs/integrations/coralogix-endpoints/.md), with a **recommendation of 2MB**.

* Metric names must be a maximum of 255 characters.

* Attribute keys for metric data must be a maximum of 255 characters.

Limits apply to single requests, regardless of timespan.

## Additional resources[​](#additional-resources "Direct link to Additional resources")

|               |                                                                                             |
| ------------- | ------------------------------------------------------------------------------------------- |
| Documentation | [Coralogix Endpoints](https://coralogix.com/docs/docs/integrations/coralogix-endpoints/.md) |
| External      | [GitHub](https://github.com/coralogix/custom-metrics-examples)                              |
