🎯 Рекомендуемые коллекции
Балансированные коллекции примеров кода из различных категорий, которые вы можете исследовать
Примеры Распределенного Трейсинга
Комплексные примеры распределенного трейсинга с использованием Jaeger, OpenTelemetry и современных инструментов
⚙️ Настройка Jaeger
🟡 intermediate
⭐⭐⭐
Полная конфигурация Jaeger для сквозного трейсинга
⏱️ 20 min
🏷️ jaeger, collector, agent, deployment, sampling, storage
# Jaeger Configuration File
# Complete setup for production distributed tracing
version: '3.8'
services:
# Jaeger Collector
jaeger-collector:
image: jaegertracing/jaeger-collector:1.45
environment:
- SPAN_STORAGE_TYPE=elasticsearch
- ES_SERVER_URLS=http://elasticsearch:9200
- ES_USERNAME=elastic
- ES_PASSWORD=changeme
- ES_INDEX_PREFIX=jaeger
- COLLECTOR_ZIPKIN_HOST_PORT=:9411
- COLLECTOR_OTLP_ENABLED=true
ports:
- "14269:14269"
- "14268:14268"
- "14250:14250"
- "9411:9411"
depends_on:
- elasticsearch
# Jaeger Agent
jaeger-agent:
image: jaegertracing/jaeger-agent:1.45
command: ["--reporter.grpc.host-port=jaeger-collector:14250"]
ports:
- "6831:6831/udp"
- "6832:6832/udp"
depends_on:
- jaeger-collector
# Jaeger Query Service
jaeger-query:
image: jaegertracing/jaeger-query:1.45
environment:
- SPAN_STORAGE_TYPE=elasticsearch
- ES_SERVER_URLS=http://elasticsearch:9200
- ES_USERNAME=elastic
- ES_PASSWORD=changeme
- ES_INDEX_PREFIX=jaeger
- JAEGER_UI_CONFIG_JSON=/etc/jaeger-ui-config.json
ports:
- "16686:16686"
- "16687:16687"
volumes:
- ./jaeger-ui-config.json:/etc/jaeger-ui-config.json
depends_on:
- elasticsearch
# Elasticsearch Backend
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.8.0
environment:
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms1g -Xmx1g
- xpack.security.enabled=false
ports:
- "9200:9200"
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
volumes:
elasticsearch_data:
📝 Поток Микросервисов
🟡 intermediate
⭐⭐⭐
Полный пример трассировки потока между сервисами
⏱️ 10 min
🏷️ microservices, request-flow, correlation, context-propagation, span-tree
{
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"spans": [
{
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"span_id": "550e8400-e29b-41d4-a716-446655440001",
"parent_span_id": null,
"operation_name": "HTTP GET /api/orders",
"service_name": "api-gateway",
"start_time": 1701954645123000000,
"end_time": 1701954645156000000,
"duration_ms": 33,
"tags": {
"http.method": "GET",
"http.url": "/api/orders",
"http.status_code": "200",
"component": "netty"
},
"logs": [
{
"timestamp": 1701954645140000000,
"level": "info",
"message": "Request authenticated successfully"
}
]
},
{
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"span_id": "550e8400-e29b-41d4-a716-446655440002",
"parent_span_id": "550e8400-e29b-41d4-a716-446655440001",
"operation_name": "UserService.GetUser",
"service_name": "user-service",
"start_time": 1701954645130000000,
"end_time": 1701954645145000000,
"duration_ms": 15,
"tags": {
"user.id": "12345",
"db.system": "postgresql",
"operation.type": "query"
}
},
{
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"span_id": "550e8400-e29b-41d4-a716-446655440003",
"parent_span_id": "550e8400-e29b-41d4-a716-446655440001",
"operation_name": "OrderService.GetOrders",
"service_name": "order-service",
"start_time": 1701954645132000000,
"end_time": 1701954645152000000,
"duration_ms": 20,
"tags": {
"user.id": "12345",
"operation.type": "business"
}
}
]
}
💻 Распространение Контекста
🟡 intermediate
⭐⭐⭐
Пример реализации распространения контекста между сервисами
⏱️ 15 min
🏷️ context-propagation, headers, cross-service, correlation, baggage
# Performance Analysis Configuration
# Example setup for performance bottleneck detection
# Custom Span Attributes
attributes:
- database.query.duration
- cache.hit_ratio
- memory.usage
- cpu.utilization
# Performance Thresholds
thresholds:
slow_query: 100ms
high_memory: 80%
high_cpu: 90%
# Alert Configuration
alerts:
- name: Slow Database Queries
condition: span.duration > 100ms
severity: warning
⚙️ Инструментация OpenTelemetry
🔴 complex
⭐⭐⭐⭐
Конфигурация авто-инструментации для разных языков
⏱️ 25 min
🏷️ opentelemetry, instrumentation, auto-instrument, telemetry, metrics, tracing
# OpenTelemetry Auto-Instrumentation Configuration
# Example configuration for Java applications
# Environment Variables
export OTEL_SERVICE_NAME=my-service
export OTEL_RESOURCE_ATTRIBUTES=service.name=my-service,service.version=1.0.0
export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
export OTEL_TRACES_SAMPLER=traceidratio
export OTEL_TRACES_SAMPLER_ARG=1.0
# Java Agent Configuration
-javaagent:/app/opentelemetry-javaagent.jar -Dotel.service.name=my-service -Dotel.resource.attributes=service.name=my-service,service.version=1.0.0 -Dotel.exporter.otlp.endpoint=http://otel-collector:4317 -Dotel.traces.sampler=traceidratio -Dotel.traces.sampler.arg=1.0 -Dotel.javaagent.extensions=io.opentelemetry.extension.noopapi.NoOpApiExtension
# Custom Span Creation (Java Example)
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
Tracer tracer = OpenTelemetry.getGlobalTracer("my-service");
Span span = tracer.spanBuilder("custom-operation")
.setAttribute("user.id", "12345")
.setAttribute("operation.type", "business")
.startSpan();
// Do work here...
span.end();
⚙️ Анализ Узких Мест
🔴 complex
⭐⭐⭐⭐
Расширенная конфигурация для анализа производительности
⏱️ 30 min
🏷️ performance, bottleneck, analysis, optimization, error-tracking, metrics
# Performance Analysis Configuration
# Example setup for performance bottleneck detection
# Custom Span Attributes
attributes:
- database.query.duration
- cache.hit_ratio
- memory.usage
- cpu.utilization
# Performance Thresholds
thresholds:
slow_query: 100ms
high_memory: 80%
high_cpu: 90%
# Alert Configuration
alerts:
- name: Slow Database Queries
condition: span.duration > 100ms
severity: warning
⚙️ Конвейер OTEL Collector
🔴 complex
⭐⭐⭐⭐
Конфигурация обработки и экспорта данных
⏱️ 25 min
🏷️ otel-collector, pipeline, processors, exporters, receivers
# Performance Analysis Configuration
# Example setup for performance bottleneck detection
# Custom Span Attributes
attributes:
- database.query.duration
- cache.hit_ratio
- memory.usage
- cpu.utilization
# Performance Thresholds
thresholds:
slow_query: 100ms
high_memory: 80%
high_cpu: 90%
# Alert Configuration
alerts:
- name: Slow Database Queries
condition: span.duration > 100ms
severity: warning