Distributed Tracing Samples
Comprehensive distributed tracing examples using Jaeger, OpenTelemetry, and other modern observability tools for microservices architecture
Key Facts
- Category
- Observability
- Items
- 6
- Format Families
- json, yaml, text
Sample Overview
Comprehensive distributed tracing examples using Jaeger, OpenTelemetry, and other modern observability tools for microservices architecture This sample set belongs to Observability and can be used to test related workflows inside Elysia Tools.
⚙️ Jaeger Distributed Tracing Setup
Complete Jaeger deployment configuration with collectors, agents, and UI for end-to-end distributed tracing
# 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:
📝 Microservices Request Flow Trace
Sample distributed trace showing request flow across multiple microservices with correlation IDs and context propagation
{
"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"
}
}
]
}
💻 Cross-Service Context Propagation
Implementation example of context propagation between microservices using OpenTelemetry context API and custom headers
// Context propagation across services (Node.js + OpenTelemetry)
import { context, propagation, trace } from '@opentelemetry/api'
const tracer = trace.getTracer('orders-service')
export async function handleIncomingRequest(req, res) {
// Extract trace context from inbound HTTP headers
const parentContext = propagation.extract(context.active(), req.headers)
await context.with(parentContext, async () => {
const span = tracer.startSpan('handle-order-request')
try {
span.setAttribute('http.route', req.url)
span.setAttribute('service.name', 'orders-service')
// Inject context when calling downstream service
const headers = {}
const spanContext = trace.setSpan(context.active(), span)
propagation.inject(spanContext, headers)
const response = await fetch('http://inventory-service/check', {
method: 'POST',
headers: {
...headers,
'content-type': 'application/json'
},
body: JSON.stringify({ sku: req.body.sku, quantity: req.body.quantity })
})
if (!response.ok) {
span.setAttribute('error', true)
span.setAttribute('http.status_code', response.status)
}
res.status(200).json({ ok: true })
} catch (error) {
span.recordException(error)
span.setAttribute('error', true)
res.status(500).json({ ok: false })
} finally {
span.end()
}
})
}
⚙️ OpenTelemetry Auto-Instrumentation
OpenTelemetry auto-instrumentation configuration for Java, Python, Node.js, and Go applications with custom spans
# 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();
⚙️ Performance Bottleneck Detection
Advanced tracing configuration for identifying performance bottlenecks with detailed span attributes and error tracking
# 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 Collector Pipeline
OpenTelemetry Collector configuration for processing, filtering, and exporting traces to multiple backends
# OpenTelemetry Collector Configuration
receivers:
otlp:
protocols:
grpc:
http:
processors:
memory_limiter:
check_interval: 5s
limit_mib: 512
batch:
timeout: 5s
send_batch_size: 1024
attributes:
actions:
- key: environment
value: production
action: insert
exporters:
otlp/jaeger:
endpoint: jaeger-collector:4317
tls:
insecure: true
logging:
loglevel: info
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch, attributes]
exporters: [otlp/jaeger, logging]