feat: Add OpenTelemetry OTLP HTTP receiver

- 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
This commit is contained in:
2026-02-06 14:59:29 -03:00
parent 8b6e59d346
commit 771cf6cf50
11 changed files with 1053 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
// ═══════════════════════════════════════════════════════════
// 🔭 OpenTelemetry Tracing Setup for Ophion
// ═══════════════════════════════════════════════════════════
//
// This file initializes OpenTelemetry tracing and sends spans
// to Ophion's OTLP HTTP endpoint.
//
// Usage: node --require ./tracing.js app.js
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
// Configure the OTLP exporter to send to Ophion
const traceExporter = new OTLPTraceExporter({
// Ophion OTLP endpoint - adjust host/port as needed
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:8080/v1/traces',
headers: {
// Optional: add authorization if Ophion requires it
// 'Authorization': `Bearer ${process.env.OPHION_API_KEY}`,
},
});
// Create the SDK with auto-instrumentation
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'nodejs-example',
[SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0',
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV || 'development',
}),
traceExporter,
instrumentations: [
getNodeAutoInstrumentations({
// Disable fs instrumentation to reduce noise
'@opentelemetry/instrumentation-fs': { enabled: false },
}),
],
});
// Start the SDK
sdk.start();
console.log('🔭 OpenTelemetry tracing initialized - sending to Ophion');
// Graceful shutdown
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('OpenTelemetry SDK shut down'))
.catch((error) => console.error('Error shutting down SDK', error))
.finally(() => process.exit(0));
});