How alibaba/opentelemetry-go-auto-instrumentation works
Main Components Overview
The system should be divided into these primary components:
a) Core Instrumentation Engine
• Located in /pkg/core
• Handles the fundamental instrumentation logic
• Manages meters and telemetry data collection
b) Rules Engine
• Located in /pkg/rules
• Contains all supported library instrumentations
• Manages different instrumentation strategies for various frameworks
c) Tool Chain
• Located in /tool
• Handles the compile-time instrumentation process
• Includes preprocessing, instrumentation, and resource management
Key Relationships to Highlight
[Build Command (otel go build)] → [Tool Chain]
• ↓
[Source Code] → [Preprocessor] → [Instrumenter] → [Instrumented Binary]
• ↓
[Rules Engine] ← [Core Engine] → [OpenTelemetry SDK]
Component Details
a) Tool Chain Layer:
• Preprocessing component (/tool/preprocess)
• Instrumentation component (/tool/instrument)
• Resource management (/tool/resource)
• Configuration handling (/tool/config)
b) Rules Layer:
• Framework-specific rules (HTTP, gRPC, Redis, etc.)
• Custom rule support
• Rule definition and processing
c) Core Layer:
• API implementations (/pkg/api)
• Instrumenter implementations (/pkg/inst-api)
• Metric collection (/pkg/core/meter)
Data Flow
Following flows:
1. Build Flow:
Source Code → Preprocessor → Rule Application → Instrumented Code → Binary
2. Runtime Flow:
Application → Instrumented Code → OpenTelemetry SDK → Exporters
Integration Points
Key integration points:
• OpenTelemetry SDK integration
• Framework/library hook points
• Exporter configurations
• Custom rule injection points
Additional Details
Important aspects:
• Configuration points
• Supported library versions (from the compatibility table)
• Extension points for custom rules
• Metric/trace collection paths