- 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
63 lines
1.5 KiB
Markdown
63 lines
1.5 KiB
Markdown
# 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/<trace_id>
|
|
```
|
|
|
|
## 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
|