Prompt

How do I map service dependencies from distributed traces

Technology / Observability1 observationLast seen Oct 28, 2026

Latest observation

Oct 28, 2026OpenAI APIWeb search: off

To map service dependencies from distributed traces, you typically turn each trace into a set of parent→child service call edges, then aggregate those edges across many traces to build a dependency graph.

Basic idea

A distributed trace is a tree or DAG of spans. Each span usually has:

  • trace_id
  • span_id
  • parent_span_id
  • service.name or equivalent
  • timing information

If span A is the parent of span B, and they belong to different services, then that implies a dependency:

  • service of A → service of B

Over many traces, you count these edges to discover the service topology.


Step-by-step approach

1) Normalize span data

Make sure you can extract:

  • Trace ID
  • Span ID
  • Parent span ID
  • Service name
  • Start/end time

Common sources:

  • OpenTelemetry
  • Jaeger
  • Zipkin
  • Honeycomb
  • Datadog traces

2) Build parent-child relationships per trace

For each trace:

  • group spans by trace_id
  • index spans by span_id
  • for each span, find its parent via parent_span_id

3) Convert span relationships to service edges

For each parent-child span pair:

  • let src = parent.service.name
  • let dst = child.service.name
  • if src != dst, record edge src -> dst

You can optionally deduplicate edges within a trace if you only want one edge per service pair per trace.

4) Aggregate across traces

Count:

  • number of calls from src to dst
  • total latency
  • error rate
  • percentiles
  • number of unique traces containing the edge

This gives you a weighted service dependency graph.

5) Visualize the graph

Represent:

  • nodes = services
  • edges = dependencies
  • edge thickness = call volume
  • edge color = error rate or latency

Tools:

  • Graphviz
  • Gephi
  • D3.js
  • Cytoscape
  • service maps in observability platforms

Example

Suppose a trace contains spans:

span_idparent_span_idservice
s1nullapi-gateway
s2s1auth-service
s3s1orders-service
s4s3inventory-service

Then the service edges are:

  • api-gateway → auth-service
  • api-gateway → orders-service
  • orders-service → inventory-service

If this pattern appears in many traces, aggregate counts might look like:

sourcetargetcount
api-gatewayauth-service1200
api-gatewayorders-service980
orders-serviceinventory-service850

Important considerations

Same-service spans

Not every parent-child span implies a service dependency if both spans are in the same service. Usually you ignore those for service maps.

Async messaging

For queues, pub/sub, and event-driven systems, parent-child relationships may not always be preserved directly. You may need to infer dependencies from:

  • messaging span attributes
  • producer/consumer semantics
  • headers propagated across messages
  • span kind (PRODUCER, CONSUMER)

A dependency may then be:

  • service A publishes to topic X
  • service B consumes from topic X

Batch / fan-out / retries

A single trace can show multiple edges to the same target service. Decide whether to:

  • count every span-level invocation
  • count unique service pairs per trace
  • treat retries separately or collapse them

Cross-trace causality

Traditional traces show causality within one trace only. If you need end-to-end service dependency across asynchronous boundaries, you may need additional correlation IDs or message tracing.

Sampling

If traces are sampled, your graph is an estimate. Ensure sampling is sufficient or weighted appropriately.


Practical algorithm

Pseudocode:

from collections import defaultdict

edges = defaultdict(int)

for trace in traces:
    spans = {span.span_id: span for span in trace.spans}
    for span in trace.spans:
        if span.parent_span_id is None:
            continue
        parent = spans.get(span.parent_span_id)
        if not parent:
            continue
        if parent.service != span.service:
            edges[(parent.service, span.service)] += 1

To add latency aggregation:

edge_stats = defaultdict(lambda: {"count": 0, "latency_sum": 0})

for trace in traces:
    spans = {span.span_id: span for span in trace.spans}
    for span in trace.spans:
        if span.parent_span_id is None:
            continue
        parent = spans.get(span.parent_span_id)
        if not parent:
            continue
        if parent.service != span.service:
            key = (parent.service, span.service)
            edge_stats[key]["count"] += 1
            edge_stats[key]["latency_sum"] += span.duration_ms

If you already use OpenTelemetry

OpenTelemetry span fields commonly used:

  • service.name
  • trace_id
  • span_id
  • parent_span_id
  • span.kind
  • peer.service or network attributes
  • rpc.system, http.route, messaging.system

For service dependency mapping, service.name plus parent-child relationships is the main requirement.


Recommended output schema

A useful edge record might include:

  • source_service
  • target_service
  • call_count
  • unique_trace_count
  • avg_latency_ms
  • p95_latency_ms
  • error_count
  • error_rate
  • relationship_type (sync, async, db, etc.)

Summary

To map service dependencies from traces:

  1. Group spans by trace
  2. Link spans through parent_span_id
  3. Convert cross-service parent→child span pairs into service edges
  4. Aggregate counts and performance metrics across traces
  5. Visualize as a dependency graph

If you want, I can also show:

  • a SQL approach for trace data in a warehouse
  • a Python example using OpenTelemetry/Jaeger JSON
  • how to infer dependencies for Kafka / RabbitMQ / async workflows

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.