Prompt
I need service dependency mapping from traces automatically
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
You can do this automatically from distributed traces by building a service dependency graph.
What to extract from traces
From each trace/span, capture at least:
trace_idspan_idparent_span_idservice.namespan.kind(SERVER,CLIENT,PRODUCER,CONSUMER)peer.service/ destination host / RPC target- timestamps and latency
Basic mapping rule
A dependency usually exists when a span from service A causes a child span in service B.
Common patterns:
- HTTP/gRPC sync call:
A -> B - Messaging:
- producer service
Apublishes to topic/queue - consumer service
Bprocesses it - map as
A -> topic -> Bor directlyA -> Bif you want service-to-service only
- producer service
Recommended approach
1) Ingest traces
Use OpenTelemetry / Jaeger / Zipkin trace data.
2) Normalize spans
Convert each span to a canonical form:
{
"trace_id": "...",
"span_id": "...",
"parent_span_id": "...",
"service": "orders",
"kind": "CLIENT",
"peer_service": "payments",
"operation": "POST /charge"
}
3) Build edges
For each span:
- If
kind = CLIENTandpeer_serviceexists:- create edge
service -> peer_service
- create edge
- If parent span belongs to a different service than child:
- create edge
parent_service -> child_service
- create edge
- Aggregate counts, latency, error rates per edge
4) Aggregate into graph
For each edge:
- call count
- p95 latency
- error rate
- first seen / last seen
Example:
orders -> payments 1284 calls p95=42ms errors=0.7%
orders -> inventory 980 calls p95=18ms errors=0.1%
payments -> fraud 220 calls p95=75ms errors=1.9%
Output formats
You can emit:
- JSON graph
- Graphviz DOT
- Neo4j / graph DB
- Prometheus metrics
- OpenTelemetry topology service map
Example JSON:
{
"nodes": ["orders", "payments", "inventory", "fraud"],
"edges": [
{"from": "orders", "to": "payments", "count": 1284, "p95_ms": 42},
{"from": "orders", "to": "inventory", "count": 980, "p95_ms": 18}
]
}
Tooling options
- OpenTelemetry Collector for ingestion/export
- Jaeger topology/service graph
- Grafana Tempo + service graph
- AWS X-Ray service map
- Elastic APM service map
- Neo4j / custom pipeline if you want full control
If you want to implement it yourself
A simple algorithm:
- Group spans by
trace_id - Build span tree using
parent_span_id - For each parent-child pair across different services, add edge
- Merge edges across traces
- Compute metrics
Pseudo-code:
for trace in traces:
spans = trace.spans
by_id = {s.span_id: s for s in spans}
for s in spans:
if s.parent_span_id and s.parent_span_id in by_id:
p = by_id[s.parent_span_id]
if p.service != s.service:
edges[(p.service, s.service)].count += 1
edges[(p.service, s.service)].latencies.append(s.duration_ms)
Important caveats
- Sampling can hide dependencies.
- Messaging systems need special handling.
- Async calls may not have direct parent-child service relationships.
- Repeated retries can inflate edge counts.
- You may need heuristics for missing
peer.service.
If you want, I can provide:
- a Python script to generate a service graph from OTLP/Jaeger traces,
- a database schema for storing dependencies, or
- a Kubernetes/OpenTelemetry architecture for doing this in production.