- Add POST /v1/traces endpoint for OTLP JSON trace ingestion - Convert OTLP spans to internal format and save to PostgreSQL - Manual JSON parsing (no Go 1.24 dependencies) - Add Node.js instrumentation example with Express - Add Python instrumentation example with Flask - Auto-instrumentation support for both languages
1.5 KiB
1.5 KiB
Node.js OpenTelemetry Example for Ophion
This example demonstrates how to instrument a Node.js application with OpenTelemetry and send traces to Ophion.
Setup
# Install dependencies
npm install
# Start Ophion server (in another terminal)
# cd ~/projetos_jarvis/ophion && go run cmd/server/main.go
# Run the app with tracing
npm run trace
Environment Variables
| Variable | Default | Description |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
http://localhost:8080/v1/traces |
Ophion OTLP endpoint |
OTEL_SERVICE_NAME |
nodejs-example |
Service name in traces |
PORT |
3000 |
App HTTP port |
Test Endpoints
# Health check
curl http://localhost:3000/health
# Get all users (generates trace)
curl http://localhost:3000/users
# Get single user
curl http://localhost:3000/users/1
# Create order (complex trace with nested spans)
curl -X POST http://localhost:3000/orders \
-H "Content-Type: application/json" \
-d '{"items": [{"id": 1, "qty": 2}]}'
# Trigger error (error trace)
curl http://localhost:3000/error
View Traces in Ophion
# List recent traces
curl http://localhost:8080/api/v1/traces
# Get specific trace
curl http://localhost:8080/api/v1/traces/<trace_id>
How It Works
tracing.js- Initializes OpenTelemetry SDK with OTLP HTTP exporter- Auto-instrumentation captures HTTP requests automatically
- Manual spans in
app.jsadd custom business logic traces - All spans are sent to Ophion's
/v1/tracesendpoint in OTLP JSON format