# Node.js OpenTelemetry Example for Ophion This example demonstrates how to instrument a Node.js application with OpenTelemetry and send traces to Ophion. ## Setup ```bash # 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 ```bash # 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 ```bash # List recent traces curl http://localhost:8080/api/v1/traces # Get specific trace curl http://localhost:8080/api/v1/traces/ ``` ## How It Works 1. `tracing.js` - Initializes OpenTelemetry SDK with OTLP HTTP exporter 2. Auto-instrumentation captures HTTP requests automatically 3. Manual spans in `app.js` add custom business logic traces 4. All spans are sent to Ophion's `/v1/traces` endpoint in OTLP JSON format