Skip to content

Latest commit

 

History

History

opentelemetry-push-custom

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Autometrics + OTLP push controller (custom)

This example demonstrates how you can push autometrics via OTLP gRPC protocol to the OpenTelemetry Collector or another OTel-compatible solution without using the Autometrics provided interface.

Running the example

Start a basic OTEL-Collector

You can use the otel-collector-config.yml file to start an otel-collector container that listens on 0.0.0.0:4317 for incoming otlp-gRPC traffic, and exports the metrics it receives to stdout.

Run the following command in a second terminal to start a container in interactive mode:

docker run -it --name otel-col \
    -p 4317:4317 -p 13133:13133 \
    -v $PWD/otel-collector-config.yml:/etc/otelcol/config.yaml \
    otel/opentelemetry-collector:latest

You should see the collector initialization output, that should end with something like:

...
2023-06-07T15:56:42.617Z        info    otlpreceiver@v0.75.0/otlp.go:94 Starting GRPC server    {"kind": "receiver", "name": "otlp", "data_type": "metrics", "endpoint": "0.0.0.0:4317"}
2023-06-07T15:56:42.618Z        info    service/service.go:146  Everything is ready. Begin running and processing data.

Execute example code

Then come back on your primary shell and run this example:

cargo run -p example-opentelemetry-push-custom

Check the output

On the stdout of the terminal where you started the opentelemetry-collector container, you should see the metrics generated by autometrics macro being pushed every 10 seconds since example exit, like:

...
Metric #0
Descriptor:
     -> Name: function.calls
     -> Description: Autometrics counter for tracking function calls
     -> Unit:
     -> DataType: Sum
     -> IsMonotonic: true
     -> AggregationTemporality: Cumulative
NumberDataPoints #0
Data point attributes:
     -> caller: Str()
     -> function: Str(do_stuff)
     -> module: Str(example_opentelemetry_push)
StartTimestamp: 2023-06-07 16:01:08.549300623 +0000 UTC
Timestamp: 2023-06-07 16:01:48.551531429 +0000 UTC
Value: 10
Metric #1
Descriptor:
     -> Name: build_info
     -> Description: Autometrics info metric for tracking software version and build details
     -> Unit:
     -> DataType: Sum
     -> IsMonotonic: false
     -> AggregationTemporality: Cumulative
NumberDataPoints #0
Data point attributes:
     -> branch: Str()
     -> commit: Str()
     -> version: Str(0.0.0)
StartTimestamp: 2023-06-07 16:01:08.549300623 +0000 UTC
Timestamp: 2023-06-07 16:01:48.551531429 +0000 UTC
Value: 1.000000
Metric #2
Descriptor:
     -> Name: function.calls.duration
     -> Description: Autometrics histogram for tracking function call duration
     -> Unit:
     -> DataType: Sum
     -> IsMonotonic: false
     -> AggregationTemporality: Cumulative
NumberDataPoints #0
Data point attributes:
     -> function: Str(do_stuff)
     -> module: Str(example_opentelemetry_push)
StartTimestamp: 2023-06-07 16:01:08.549300623 +0000 UTC
Timestamp: 2023-06-07 16:01:48.551531429 +0000 UTC
Value: 0.000122
        {"kind": "exporter", "data_type": "metrics", "name": "logging"}
...

Cleanup

In the end, to stop the opentelemetry collector container just hit ^C.

Then delete the container with

docker rm otel-col

OpenTelemetry Metrics Push Controller

The metric push controller is implemented as from this example from opentelemetry-rust crate.