-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracing and host metrics with Opentelemetry (#1487)
- [x] use otel collector to collect and export metric - [x] add new docker-compose for telemetry services - [x] ~~Do something with statsd metrics~~ collect and export metrics with openTelemetry collector - [x] Add other exporters for local use - [x] Learn what was done in our prev observability [PR](febb710), which seems a lot more comprehensive - [x] Need to document how to setup - [x] Need to replace host metric collector with prometheus-based one - [x] Discuss with team issue with opentelemetry_bandit Closes #1472. --------- Co-authored-by: Valter Balegas <[email protected]> Co-authored-by: Ilia Borovitinov <[email protected]>
- Loading branch information
1 parent
07ce5e1
commit f413a68
Showing
19 changed files
with
477 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Telemetry | ||
|
||
Electric provides telemetry data — such as traces, logs, and metrics — for real-time system monitoring. | ||
|
||
## Metrics | ||
Metrics are reported in StatsD and Prometheus formats. To configure Electric to expose metric information in those formats use the following environment variables. | ||
|
||
| VARIABLE| Description | | ||
|---------------|------------| | ||
| STATSD_HOST | The address of the StatsD server | | ||
| PROMETHEUS_PORT | The scrape port for Prometheus | | ||
|
||
You can get the current status of the service by calling the `http://electric-hostname:PROMETHUES_PORT/metrics` endpoint. | ||
|
||
## OpenTelemetry | ||
Metrics, traces and logs are exported using the OpenTelemetry Protocol (OTLP). You can configure the OpenTelemetry Exporter for Electric using the following environment variables. | ||
|
||
| VARIABLE| Description | | ||
|---------------|------------| | ||
| OTEL_EXPORT | `debug` outputs telemetry data to stdout | | ||
| | `otlp` sends the telemetry data to an OTLP endpoint | | ||
| OTLP_ENDPOINT | The exporter endpoint url | | ||
|
||
Electric always adds the following resource attributes to events: | ||
```elixir | ||
%{service: %{name: service_name, version: version}, instance: %{id: instance_id}} | ||
``` | ||
|
||
Attributes `service_name` and `instance_id` can be overriden with `ELECTRIC_SERVICE_NAME` and `ELECTRIC_INSTANCE_ID` respectively. By default, `instance_id` is an uuid. | ||
|
||
Electric will also load additional resource attributes from `OTEL_RESOURCE_ATTRIBUTES`. Learn more about resource attributes in [OpenTelemetry documentation](https://opentelemetry.io/docs/languages/js/resources/). | ||
|
||
## Example | ||
You can find an example of a docker compose that runs Electric with an OpenTelemetry Collector agent that sends telemetry data to Honeycomb under `packages/sync-service/dev`. Set `HNY_DATASET` and `HNY_API_KEY` with your Honeycomb information and start the compose file like: ```docker compose -f docker-compose-otel.yml up``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ electric-*.tar | |
|
||
# The shape database, created when the Sync Service runs | ||
/shapes/ | ||
|
||
.env.dev.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
version: "3.8" | ||
name: "electric_dev_otel" | ||
|
||
services: | ||
postgres: | ||
image: postgres:16-alpine | ||
environment: | ||
POSTGRES_DB: electric | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
ports: | ||
- "54321:5432" | ||
volumes: | ||
- ./postgres.conf:/etc/postgresql.conf:ro | ||
- ./init.sql:/docker-entrypoint-initdb.d/00_shared_init.sql:ro | ||
tmpfs: | ||
- /var/lib/postgresql/data | ||
- /tmp | ||
entrypoint: | ||
- docker-entrypoint.sh | ||
- -c | ||
- config_file=/etc/postgresql.conf | ||
electric: | ||
image: electricsql/electric-next:latest | ||
environment: | ||
OTEL_EXPORT: ${OTEL_EXPORT:-otlp} | ||
OTLP_ENDPOINT: http://otel:4318/ | ||
PROMETHEUS_PORT: ${PROMETHEUS_PORT:-4000} | ||
DATABASE_URL: postgresql://postgres:password@postgres:5432/electric | ||
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES_FOR_DOCKER_COMPOSE} | ||
ports: | ||
- 3000:3000 | ||
- 4000:4000 | ||
otel: | ||
image: otel/opentelemetry-collector-contrib:0.105.0 | ||
environment: | ||
HNY_DATASET: ${HNY_DATASET} | ||
HNY_API_KEY: ${HNY_API_KEY} | ||
PROMETHEUS_SCRAPE_ENDPOINT: electric:4000 | ||
# Need to set OTEL_RESOURCE_ATTRIBUTES_FOR_DOCKER_COMPOSE | ||
# see https://github.com/docker/cli/issues/4958 | ||
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES_FOR_DOCKER_COMPOSE} | ||
ports: | ||
- 4317:4317 | ||
- 4318:4318 | ||
command: ['--config=/conf/otel-collector-config.yaml'] | ||
volumes: | ||
- ./otel-collector-honeycomb-config.yaml:/conf/otel-collector-config.yaml | ||
depends_on: | ||
- electric | ||
nginx: | ||
image: nginx:latest | ||
ports: | ||
- "3002:3002" | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
depends_on: | ||
- electric |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/sync-service/dev/otel-collector-honeycomb-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
exporters: | ||
otlp/honeycomb: | ||
endpoint: api.honeycomb.io:443 | ||
headers: | ||
x-honeycomb-team: ${env:HNY_API_KEY} | ||
x-honeycomb-dataset: ${env:HNY_DATASET} | ||
logging: | ||
loglevel: info | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
endpoint: '0.0.0.0:4317' | ||
http: | ||
endpoint: '0.0.0.0:4318' | ||
prometheus: | ||
config: | ||
scrape_configs: | ||
- job_name: otel-prometheus | ||
scrape_interval: 5s | ||
static_configs: | ||
- targets: ["${env:PROMETHEUS_SCRAPE_ENDPOINT}"] | ||
processors: | ||
resourcedetection: | ||
detectors: | ||
- env | ||
- system | ||
transform: | ||
error_mode: ignore | ||
metric_statements: | ||
- context: datapoint | ||
statements: | ||
- set(time, TruncateTime(time, Duration("1s"))) | ||
batch: | ||
send_batch_size: 8192 | ||
timeout: 200ms | ||
service: | ||
pipelines: | ||
metrics: | ||
receivers: | ||
- prometheus | ||
processors: | ||
- transform | ||
- resourcedetection | ||
- batch | ||
exporters: | ||
- otlp/honeycomb | ||
- logging | ||
traces: | ||
receivers: | ||
- otlp | ||
processors: | ||
- resourcedetection | ||
- batch | ||
exporters: | ||
- otlp/honeycomb | ||
- logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule Electric.Plug.UtilityRouter do | ||
use Plug.Router | ||
|
||
plug :match | ||
plug :dispatch | ||
|
||
get "/metrics", do: resp(conn, 200, TelemetryMetricsPrometheus.Core.scrape()) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.