fix: add agent key auth for ingest endpoints
This commit is contained in:
31
examples/docker/python-instrumented/Dockerfile
Normal file
31
examples/docker/python-instrumented/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 🐍 OPHION - Python Instrumented App Dockerfile
|
||||
# Example showing how to add OpenTelemetry to any Python app
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
|
||||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Install OpenTelemetry auto-instrumentation
|
||||
RUN pip install --no-cache-dir \
|
||||
opentelemetry-distro \
|
||||
opentelemetry-exporter-otlp \
|
||||
opentelemetry-instrumentation
|
||||
|
||||
# Auto-install all available instrumentations
|
||||
RUN opentelemetry-bootstrap -a install
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 5000
|
||||
|
||||
# Start with auto-instrumentation wrapper
|
||||
# opentelemetry-instrument auto-configures tracing based on env vars
|
||||
CMD ["opentelemetry-instrument", "python", "app.py"]
|
||||
105
examples/docker/python-instrumented/app.py
Normal file
105
examples/docker/python-instrumented/app.py
Normal file
@@ -0,0 +1,105 @@
|
||||
"""
|
||||
═══════════════════════════════════════════════════════════
|
||||
🐍 OPHION - Example Python Application
|
||||
This app is automatically instrumented by OpenTelemetry
|
||||
No code changes needed - just env vars!
|
||||
═══════════════════════════════════════════════════════════
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
from flask import Flask, jsonify
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
"""Home endpoint"""
|
||||
logger.info("Home endpoint called")
|
||||
return jsonify({
|
||||
'message': 'Hello from Python!',
|
||||
'instrumented': True,
|
||||
'otel_endpoint': os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT', 'not set')
|
||||
})
|
||||
|
||||
@app.route('/health')
|
||||
def health():
|
||||
"""Health check endpoint"""
|
||||
return jsonify({
|
||||
'status': 'healthy',
|
||||
'service': 'python-example'
|
||||
})
|
||||
|
||||
@app.route('/api/users')
|
||||
def get_users():
|
||||
"""Get users - simulates DB call"""
|
||||
logger.info("Fetching users")
|
||||
# Simulate some work
|
||||
time.sleep(random.uniform(0.01, 0.1))
|
||||
return jsonify([
|
||||
{'id': 1, 'name': 'Alice'},
|
||||
{'id': 2, 'name': 'Bob'},
|
||||
{'id': 3, 'name': 'Charlie'}
|
||||
])
|
||||
|
||||
@app.route('/api/slow')
|
||||
def slow_endpoint():
|
||||
"""Slow endpoint - good for testing trace visualization"""
|
||||
logger.info("Starting slow operation")
|
||||
# Simulate slow operation
|
||||
time.sleep(0.5)
|
||||
logger.info("Slow operation completed")
|
||||
return jsonify({
|
||||
'message': 'Slow response',
|
||||
'delay': '500ms'
|
||||
})
|
||||
|
||||
@app.route('/api/chain')
|
||||
def chain_endpoint():
|
||||
"""Simulates a chain of operations"""
|
||||
logger.info("Starting chain operation")
|
||||
|
||||
# Step 1: Validate
|
||||
time.sleep(random.uniform(0.01, 0.05))
|
||||
logger.info("Validation complete")
|
||||
|
||||
# Step 2: Process
|
||||
time.sleep(random.uniform(0.05, 0.1))
|
||||
logger.info("Processing complete")
|
||||
|
||||
# Step 3: Save
|
||||
time.sleep(random.uniform(0.02, 0.08))
|
||||
logger.info("Save complete")
|
||||
|
||||
return jsonify({
|
||||
'message': 'Chain completed',
|
||||
'steps': ['validate', 'process', 'save']
|
||||
})
|
||||
|
||||
@app.route('/api/error')
|
||||
def error_endpoint():
|
||||
"""Endpoint that raises an error - good for testing error traces"""
|
||||
logger.error("About to raise an error")
|
||||
raise ValueError("Intentional error for testing traces")
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def handle_error(error):
|
||||
"""Global error handler"""
|
||||
logger.exception(f"Unhandled error: {error}")
|
||||
return jsonify({
|
||||
'error': str(error),
|
||||
'type': type(error).__name__
|
||||
}), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = int(os.getenv('PORT', 5000))
|
||||
logger.info(f"🚀 Python server starting on port {port}")
|
||||
logger.info(f"📊 OTEL Endpoint: {os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT', 'not configured')}")
|
||||
logger.info(f"🏷️ Service Name: {os.getenv('OTEL_SERVICE_NAME', 'unknown')}")
|
||||
app.run(host='0.0.0.0', port=port)
|
||||
62
examples/docker/python-instrumented/docker-compose.yml
Normal file
62
examples/docker/python-instrumented/docker-compose.yml
Normal file
@@ -0,0 +1,62 @@
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 🐍 OPHION - Python Auto-Instrumentation Example
|
||||
# Demonstrates automatic tracing for Python applications
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
#
|
||||
# Usage:
|
||||
# docker-compose up -d
|
||||
#
|
||||
# This example shows how to instrument ANY Python app without
|
||||
# code changes using opentelemetry-instrument command
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
python-app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "5001:5000"
|
||||
environment:
|
||||
# ════════════════════════════════════════════════════
|
||||
# OpenTelemetry Auto-Instrumentation Configuration
|
||||
# ════════════════════════════════════════════════════
|
||||
|
||||
# Service identification
|
||||
- OTEL_SERVICE_NAME=python-example-app
|
||||
- OTEL_SERVICE_VERSION=1.0.0
|
||||
|
||||
# OTLP Exporter configuration (pointing to Ophion collector)
|
||||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
|
||||
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
|
||||
- OTEL_TRACES_EXPORTER=otlp
|
||||
- OTEL_METRICS_EXPORTER=otlp
|
||||
- OTEL_LOGS_EXPORTER=otlp
|
||||
|
||||
# Resource attributes
|
||||
- OTEL_RESOURCE_ATTRIBUTES=deployment.environment=development,service.namespace=ophion-examples
|
||||
|
||||
# Sampling (1.0 = 100% of traces)
|
||||
- OTEL_TRACES_SAMPLER=parentbased_traceidratio
|
||||
- OTEL_TRACES_SAMPLER_ARG=1.0
|
||||
|
||||
# Propagation format
|
||||
- OTEL_PROPAGATORS=tracecontext,baggage,b3multi
|
||||
|
||||
# Python-specific: auto-detect instrumentations
|
||||
- OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
|
||||
|
||||
networks:
|
||||
- ophion
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "http://localhost:5000/health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
|
||||
networks:
|
||||
ophion:
|
||||
external: true
|
||||
4
examples/docker/python-instrumented/requirements.txt
Normal file
4
examples/docker/python-instrumented/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
# Python dependencies for instrumented example
|
||||
flask>=3.0.0
|
||||
gunicorn>=21.2.0
|
||||
requests>=2.31.0
|
||||
Reference in New Issue
Block a user