When an API request is slow, which service caused it? Logs tell you what happened, metrics tell you aggregate statistics, but distributed tracing tells you exactly where time was spent across every service involved in handling a request. Setting up OpenTelemetry with Jaeger on a Hong Kong VPS gives your engineering team the visibility to pinpoint bottlenecks in multi-service applications — identifying whether latency comes from a slow database query, a downstream API call, or network overhead on the CN2 GIA path.
The Three Pillars of Observability
- Logs — discrete events (error messages, access logs). Already covered: Nginx access logs, structured application logging with Winston/slog
- Metrics — aggregated measurements over time (request rates, error rates, CPU). Already covered: Prometheus + Grafana
- Traces — the full lifecycle of a single request through your distributed system. This guide.
Architecture
[Client Request]
↓
[Nginx] → propagates trace context headers
↓
[Node.js/Go API] → creates spans, sends to collector
↓ ↓
[PostgreSQL] [Redis] ← spans capture query duration
↓
[OpenTelemetry Collector] → batches and forwards
↓
[Jaeger] → stores and visualises traces
Step 1: Deploy Jaeger and OpenTelemetry Collector
<code">apt install -y docker.io docker-compose-plugin
mkdir -p /opt/observability && cd /opt/observability
cat > docker-compose.yml << 'EOF' version: '3.8' services: jaeger: image: jaegertracing/all-in-one:latest container_name: jaeger restart: unless-stopped ports: - "127.0.0.1:16686:16686" # Jaeger UI - "127.0.0.1:4317:4317" # OTLP gRPC (internal) environment: - COLLECTOR_OTLP_ENABLED=true - SPAN_STORAGE_TYPE=memory # Use elasticsearch for production - MEMORY_MAX_TRACES=100000 otel-collector: image: otel/opentelemetry-collector-contrib:latest container_name: otel-collector restart: unless-stopped command: ["--config=/etc/otel-collector-config.yaml"] volumes: - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml ports: - "127.0.0.1:4318:4318" # OTLP HTTP (for apps) - "127.0.0.1:8888:8888" # Collector metrics depends_on: - jaeger EOF cat > otel-collector-config.yaml << 'EOF'
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
send_batch_size: 1000
timeout: 10s
memory_limiter:
limit_mib: 256
exporters:
jaeger:
endpoint: jaeger:4317
tls:
insecure: true
logging:
loglevel: warn
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [jaeger]
EOF
docker compose up -d
docker compose logs otel-collector
Step 2: Expose Jaeger UI via Nginx
<code">cat > /etc/nginx/sites-available/jaeger << 'EOF'
server {
listen 443 ssl http2;
server_name traces.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/traces.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/traces.yourdomain.com/privkey.pem;
# Restrict to engineering team IPs
allow YOUR_OFFICE_IP;
deny all;
location / {
proxy_pass http://127.0.0.1:16686;
proxy_set_header Host $host;
}
}
EOF
ln -s /etc/nginx/sites-available/jaeger /etc/nginx/sites-enabled/
certbot --nginx -d traces.yourdomain.com
nginx -t && systemctl reload nginx
Step 3: Instrument Node.js Application
<code">npm install @opentelemetry/sdk-node \ @opentelemetry/auto-instrumentations-node \ @opentelemetry/exporter-trace-otlp-http \ @opentelemetry/resources \ @opentelemetry/semantic-conventions
<code"># Create instrumentation.js — import BEFORE your app code
cat > instrumentation.js << 'EOF' const { NodeSDK } = require('@opentelemetry/sdk-node'); const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node'); const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); const { Resource } = require('@opentelemetry/resources'); const { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION } = require('@opentelemetry/semantic-conventions'); const sdk = new NodeSDK({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'hk-api', [SEMRESATTRS_SERVICE_VERSION]: '1.0.0', 'deployment.environment': 'production', 'service.location': 'hong-kong-cn2gia', }), traceExporter: new OTLPTraceExporter({ url: 'http://127.0.0.1:4318/v1/traces', }), instrumentations: [ getNodeAutoInstrumentations({ // Auto-instruments: http, express, pg, mysql2, redis, axios, fetch '@opentelemetry/instrumentation-http': { enabled: true }, '@opentelemetry/instrumentation-express': { enabled: true }, '@opentelemetry/instrumentation-pg': { enabled: true }, '@opentelemetry/instrumentation-redis': { enabled: true }, }), ], }); sdk.start(); process.on('SIGTERM', () => sdk.shutdown());
EOF
<code"># Start your app with instrumentation loaded first:
node --require ./instrumentation.js server.js
# Or in PM2 ecosystem.config.js:
module.exports = {
apps: [{
name: 'api',
script: 'server.js',
node_args: '--require ./instrumentation.js',
// ...
}]
};
Step 4: Instrument Python/Django Application
<code">pip install opentelemetry-distro opentelemetry-exporter-otlp \ opentelemetry-instrumentation-django opentelemetry-instrumentation-psycopg2 \ opentelemetry-instrumentation-redis --break-system-packages # Auto-configure OpenTelemetry opentelemetry-bootstrap -a install # In your systemd service or start command: # ExecStart=opentelemetry-instrument \ # --service_name=django-api \ # --exporter_otlp_endpoint=http://127.0.0.1:4318 \ # gunicorn myproject.wsgi:application
<code"># In Django settings.py: DJANGO_SETTINGS_MODULE = 'myproject.settings' # OpenTelemetry reads these environment variables: # OTEL_SERVICE_NAME=django-api # OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 # OTEL_TRACES_EXPORTER=otlp
Step 5: Custom Spans for Business Logic
<code"># Node.js: add custom spans to trace specific operations
const { trace, context } = require('@opentelemetry/api');
const tracer = trace.getTracer('hk-api');
async function processPayment(orderId, amount) {
const span = tracer.startSpan('process-payment', {
attributes: {
'payment.order_id': orderId,
'payment.amount': amount,
'payment.currency': 'HKD',
}
});
try {
// Call payment gateway
const result = await alipayClient.createOrder({ orderId, amount });
span.setAttribute('payment.status', result.status);
span.setAttribute('payment.gateway_latency_ms', result.latencyMs);
return result;
} catch (err) {
span.recordException(err);
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
throw err;
} finally {
span.end();
}
}
Custom spans make Jaeger traces show exactly how long each business operation took — payment gateway call, image processing, external API request — separated from database and Redis latency that auto-instrumentation already captures.
Step 6: Reading Traces in Jaeger UI
Visit https://traces.yourdomain.com and:
- Select your service from the dropdown (
hk-api,django-api) - Set a time range and click Find Traces
- Click any trace to open the waterfall view — each span shows duration, tags, and logs
What to Look For
- Wide spans — operations taking much longer than expected. Check the span’s tags for the SQL query or Redis command that caused it
- Spans without children — operations that should be parallel are running sequentially
- Error spans (shown in red) — failed operations with exception stack traces attached
- Database spans — the SQL query text is captured automatically; slow queries are immediately visible
Step 7: Trace-Based Alerting
<code"># Generate Prometheus metrics from trace data using the OTEL Collector
# Add spanmetrics connector to otel-collector-config.yaml:
connectors:
spanmetrics:
histogram:
explicit:
buckets: [5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2s, 5s]
dimensions:
- name: http.method
- name: http.status_code
- name: service.name
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [jaeger, spanmetrics]
metrics/spanmetrics:
receivers: [spanmetrics]
exporters: [prometheus]
This generates Prometheus metrics from your trace data — P50/P95/P99 latency per endpoint, error rates, and request counts — that your Grafana dashboard can alert on. You get the granularity of traces with the alerting convenience of metrics.
Conclusion
OpenTelemetry with Jaeger on a Hong Kong VPS gives your engineering team request-level visibility across every service in your application. When Asian users report slowness, traces pinpoint whether the bottleneck is a database query, a Redis miss, a slow external API (Alipay, WeChat Pay, third-party services), or network overhead — eliminating the guesswork that makes production performance issues time-consuming to diagnose. The auto-instrumentation for Node.js, Python, and Go requires minimal code changes and captures database queries, HTTP calls, and cache operations automatically.
Add observability: Browse Server.HK Hong Kong VPS plans — the Jaeger + OpenTelemetry Collector stack runs efficiently on a dedicated 2 GB monitoring VPS or alongside your application on any 4+ GB plan.