Skip to content

Instantly share code, notes, and snippets.

@perebaj
Last active March 31, 2025 03:13
Show Gist options
  • Save perebaj/ebb12266f69f144784244d6978c191ef to your computer and use it in GitHub Desktop.
Save perebaj/ebb12266f69f144784244d6978c191ef to your computer and use it in GitHub Desktop.
# How to run the prometheusremotewritereceiver in your local environment
@perebaj
Copy link
Author

perebaj commented Mar 31, 2025

First part: Run the Prometheus server locally

  1. clone the Prometheus project
  2. inside the Prometheus repo: make build
  3. Create a myconfig.yaml file and paste the following config ⬇️
# myconfig.yaml
global:
  scrape_interval: 15s
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"] # Self-scrape to collect metrics

remote_write:
  - url: "http://localhost:9091/api/v1/write"
    protobuf_message: io.prometheus.write.v2.Request # To enable PRWv2
  1. than run ./prometheus --config.file=myconfig.yaml

Second part: run the open telemetry collector locally

  1. download the OCB(Open telemetry collector builder binary) accordingly to your OS. Ref
  2. Download the open telemetry-collector-contrib repository
  3. create 2 new YAML files
# build-config.yaml
dist:
  name: otelcol-dev
  description: Development OpenTelemetry Collector with Prometheus Remote Write receiver
  output_path: ./otelcol-dev

exporters:
  - gomod:
      go.opentelemetry.io/collector/exporter/debugexporter v0.122.1

receivers:
  - gomod: "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusremotewritereceiver v0.122.0"
    import: "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusremotewritereceiver"
    name: prometheusremotewritereceiver
    path: ./receiver/prometheusremotewritereceiver
# config.yaml
receivers:
  prometheusremotewrite:
    endpoint: localhost:9091

exporters:
  debug:
    verbosity: detailed
  

service:
  pipelines:
    metrics:
      receivers: [prometheusremotewrite]
      exporters: [debug]
  1. ./ocb --config=build-config.yaml (obs: make sure that the binary that you downloaded in the first step is avaible in the same folder where you are running this command)
  2. ./otelcol-dev/otelcol-dev --config=config.yaml

Obs: Each time that you change something in the receiver, you must re-run the step 4 and 5 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment