Small two‑service TypeScript/Node.js app to generate OpenTelemetry traces, metrics, and logs across REST, Kafka (request‑reply and fire‑and‑forget), gRPC, PostgreSQL, and Elasticsearch.
- Gateway service [HTTP 9980]
- Processor service [HTTP 9981, gRPC 9090]
./build.sh
docker-compose up
# Stop
docker-compose down
# Clean volumes
docker-compose down -vThis app produces telemetry only; it does not store or display traces/metrics/logs. It relies on an OpenTelemetry Collector (or a vendor endpoint) to receive and forward/export that data.
- Transport: OTLP over HTTP (http/protobuf), not OTLP/gRPC. The Node.js SDK uses
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf.
Default wiring (Docker Compose):
gateway-serviceandprocessor-serviceexport OTLP/HTTP tootel-test-collector:5318inside the compose network.- The local test collector writes a copy to
otel-logs/telemetry.logand proxies everything to the host athttp://host.docker.internal:4318. - You can change the proxy target in
otel-collector-config.yaml(exporterotlphttp/production).
Send data to your own collector/vendor:
- Option A (direct): set
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, andOTEL_EXPORTER_OTLP_LOGS_ENDPOINTon each service to your collector URLs (HTTP/4318) and keepOTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf. - Option B (proxy via local collector — default): keep services pointed at
otel-test-collector:5318and changeexporters.otlphttp/production.endpointinotel-collector-config.yamlto your vendor ingest URL. - Option C (dev‑only logs): keep the default and tail
otel-logs/telemetry.logfor quick local verification.
Quick verification:
docker-compose logs otel-test-collector
# and
tail -f otel-logs/telemetry.log- Gateway HTTP: 9980
- Processor HTTP: 9981
- Processor gRPC: 9090
- Kafka broker: 9092
- PostgreSQL: 5432
- Elasticsearch: 9200 (HTTP), 9300 (transport)
- OTLP HTTP receiver on the local test collector (inside Docker): 5318
- Default OTLP HTTP endpoint on your host/vendor collector: 4318
/rest-chain— REST call to processor/kafka-rr— Kafka request‑reply/kafka-ff— Kafka fire‑and‑forget/db-ops— PostgreSQL write + read/es-ops— Elasticsearch index + get/grpc— gRPC call to processor
KAFKA_BROKERS— e.g.kafka:29092in Docker orlocalhost:9092locallyPROCESSOR_URL— e.g.http://processor-service:9981PROCESSOR_GRPC_URL— e.g.processor-service:9090POSTGRES_*—POSTGRES_HOST,POSTGRES_PORT,POSTGRES_DB,POSTGRES_USER,POSTGRES_PASSWORDELASTICSEARCH_NODE— e.g.http://elasticsearch:9200- Optional OTEL:
OTEL_SERVICE_NAME,OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf,OTEL_RESOURCE_ATTRIBUTES
Kafka topics:
gateway-processor-request— request‑reply requestsgateway-processor-reply— request‑reply responsesgateway-processor-fire-forget— fire‑and‑forget events
# Gateway
cd gateway-service
npm install
npm run dev
# In another shell — Processor
cd processor-service
npm install
npm run devEnsure PostgreSQL, Kafka, and Elasticsearch are available or adjust env vars.
- Auto‑instrumentation via
@opentelemetry/sdk-nodeand friends; OTLP/HTTP exporters for traces, metrics, and logs. - Elasticsearch is instrumented through
@elastic/opentelemetry-node(works with@elastic/elasticsearchv8+). The community@opentelemetry/instrumentation-elasticsearchtargets the deprecatedelasticsearchv16.x and is not used here.
- Ports free: 9980, 9981, 9090, 9092, 5432, 9200, 5318
- Logs:
docker-compose logs -f - Kafka topics: use console consumer tools
- ES health: http://localhost:9200
- gRPC test:
grpcurl -plaintext -d '{"message":"test"}' localhost:9090 processor.ProcessorService/ProcessData - OTEL export: verify
docker-compose logs otel-test-collector
docker-compose logs otel-test-collector
# or
tail -f otel-logs/telemetry.log