We are designing an API observability correlation layer. The goal is to stitch together synthetic tests (active probing), passive monitoring (real user traffic, logs, metrics, traces), and customer feedback loops (e.g., user-reported issues, satisfaction scores). The layer should correlate data from these sources to provide a unified view, help in root cause analysis, and improve system reliability and user experience.
Key components and considerations:
Data Collection:
Synthetic tests: Scheduled or on-demand calls to API endpoints, measuring latency, correctness, etc.
Passive monitoring: Collecting metrics (e.g., Prometheus), logs (e.g., ELK stack), traces (e.g., Jaeger, Zipkin), and real user monitoring (RUM) data.
Customer feedback: Integrating with ticketing systems (e.g., Zendesk), feedback forms, NPS/CSAT scores, etc.
Data Normalization and Storage:
Need to normalize data from different sources into a common schema or data model that allows correlation.
Consider time-series data, event data, and structured logs.
Use a time-series database (e.g., InfluxDB, Prometheus) for metrics, a log storage (e.g., Elasticsearch) for logs, and a distributed tracing storage (e.g., Jaeger) for traces. But for correlation, we might need a central data store or a way to link these.
Correlation Engine:
The core of the layer: correlate events, metrics, logs, and traces based on common attributes (e.g., timestamp, request ID, user ID, endpoint, service, etc.).
Use a unique identifier that flows through the system (e.g., a trace ID or correlation ID) to link synthetic tests, passive monitoring, and feedback.
For synthetic tests, we can generate a correlation ID and propagate it in the request (if the system under test supports it) or at least record the test run ID and compare with traces and logs.
For customer feedback, we might not have a direct correlation ID, but we can correlate by time window, user ID (if available in feedback), and the specific endpoint or user action.
Query and Analysis:
Provide a unified query interface (e.g., GraphQL, REST API) to retrieve correlated data.
Allow querying by time range, service, endpoint, error type, user ID, etc.
Visualize the correlated data in dashboards (e.g., Grafana) or a custom UI.
Alerting and Anomaly Detection:
Set up alerts based on correlated insights (e.g., if synthetic test fails and there is an increase in error logs and user reports for the same endpoint).
Use machine learning for anomaly detection across multiple data sources.
Feedback Loop Integration:
When a customer reports an issue, automatically pull related metrics, logs, and traces for the reported time and user (if possible).
Conversely, when monitoring detects an anomaly, check if there are any recent customer feedback that might be related.
Scalability and Performance:
Handle high volume of data, especially from passive monitoring (logs, traces, metrics).
Consider sampling for traces and logs if necessary.
Privacy and Security:
Ensure that customer data is handled appropriately, especially when correlating with user IDs.
Implementation Outline:
a. Ingestion:
- Set up collectors for each data source (synthetic test results, metrics, logs, traces, feedback).
- Enrich data with common context (e.g., service name, environment, region) and generate correlation IDs where possible.
b. Processing:
- Stream processing (e.g., Apache Flink, Kafka Streams) or batch processing (e.g., Spark) to correlate events in real-time or near-real-time.
- Alternatively, use a graph database (e.g., Neo4j) to model relationships between entities (requests, users, tests, feedback).
c. Storage:
- Choose a storage that supports the query patterns. For time-series correlation, a time-series database with log and trace linkage (like Grafana Loki which can link logs and traces) or a dedicated observability platform (like Datadog, New Relic) might be used. But for custom, we might design a hybrid.
d. API and UI:
- Build an API that allows querying by various dimensions and returns a correlated view.
- Build a UI that shows a timeline of events (synthetic test results, metrics, logs, traces, feedback) for a given incident.
e. Alerting:
- Define rules that combine conditions from multiple sources.
f. Feedback Loop:
- Integrate with feedback systems via webhooks or APIs to ingest feedback and also push insights back (e.g., automatically update ticket with relevant logs).
Example Correlation Scenario:
A synthetic test for endpoint /api/v1/users fails at 10:00 AM.
At the same time, there is a spike in 5xx errors in metrics and error logs for that endpoint.
A user reports at 10:05 AM that they cannot access their profile.
The correlation layer should be able to show that the synthetic test failure, the error spike, and the user report are likely related and show the traces and logs for the failing requests.
Challenges:
Different data sources have different resolutions and latencies.
Not all data may have the same identifiers (e.g., user feedback may not have a request ID).
Volume of data: storing and correlating large volumes of logs and traces.
Possible Technologies:
Data pipeline: Apache Kafka for streaming, Flink for processing.
Storage: Elasticsearch for logs, Jaeger for traces, Prometheus for metrics, and a relational or graph database for feedback and correlation metadata.
Alternatively, use an existing observability platform that supports correlation (like Dynatrace, AppDynamics) and build the feedback loop integration on top.
Given the complexity, we might design a modular system where each data source is collected and stored in its optimal storage, and then a correlation service queries across these storages and assembles the correlated view.
Let's design a high-level architecture:
Data Sources:
Synthetic Test Runner: Sends requests and records results (status, latency, response). It can generate a test run ID and include a header (like X-Correlation-ID) if the system supports it. Otherwise, we record the test run ID and the time.
Application Metrics: Exposed via Prometheus endpoint or pushed to a StatsD. We also record metadata (service, endpoint).
Application Logs: Structured logs (JSON) with fields like timestamp, service, endpoint, trace ID (if distributed tracing is enabled), user ID (if available), etc.
Distributed Traces: Each request gets a trace ID and span IDs. Traces are collected and stored in Jaeger.
Customer Feedback: Ingested via API or webhook. Contains user ID (if logged in), timestamp, description, and optionally the page/endpoint where the issue occurred.
Correlation Service:
This service receives queries (e.g., "show me everything for endpoint X between time T1 and T2") and then:
Queries metrics storage for time-series data of the endpoint.
Queries log storage for error logs in that time range.
Queries trace storage for traces that have the endpoint as a span operation.
Queries feedback storage for feedback in that time range that mentions the endpoint or user.
Also, if synthetic tests were run for that endpoint in that time, include the results.
The challenge is to join these across different storages without a common index. We can use time and endpoint as the primary keys. For more precise correlation, we rely on trace IDs (which link logs and traces) and user IDs (which can link feedback and traces if the user ID is in the trace context).
Enrichment:
When ingesting data, we can try to extract and store common fields (service, endpoint, user ID, trace ID) in a separate index (like in Elasticsearch) that can be used for quick lookups.
Implementation Steps:
Step 1: Ingest each data source into its own storage, but also send a copy of the metadata (timestamp, service, endpoint, trace ID, user ID, test run ID) to a central correlation database (could be a graph database or a relational database with appropriate indexes).
Step 2: In the correlation database, create tables/collections for each data type but link them by foreign keys (or edges in graph) based on the common attributes.
Step 3: Build an API that, given a time range and a set of filters (service, endpoint, user, etc.), retrieves the related entities and their details from the respective storages.
Alternatively, we can use a single storage that can handle all these data types, like Elasticsearch (which can store metrics, logs, and even traces if we flatten them) and use its search and aggregation capabilities. But note: traces are hierarchical and might be too large for Elasticsearch. However, there are patterns for storing traces in Elasticsearch (like the Jaeger storage plugin for Elasticsearch). So we might use Elasticsearch as the primary store for all except high-cardinality metrics? But metrics are time-series and better in a time-series DB.
1. Event Ingestion → Normalization → Enrichment
- Add missing context from user/session service
- Ge IP → location mapping
- Device parsing from User-Agent
2. Correlation Scoring:
- Time window: ±5min for user actions, ±30min for batch events
- Entity matching: exact ID > session > time+endpoint
- Bayesian scoring: P(correlated|evidence) = 0.75
3. Graph Assembly:
- Build incident graph with all connected entities
- Calculate root cause probability per node
- Identify "impact radius" (affected users/transactions)
4. Deduplication & Merging:
- Collapse duplicate traces from same user session
- Merge feedback with same root cause
3. Unified Query API
A. Query Endpoints
GET /api/v1/correlations/incidents
# Params: start_time, end_time, service, endpoint, user_id, feedback_id
GET /api/v1/correlated/data?trace_id=trace_123
# Returns: synthetic tests, all logs, metrics, feedback
GET /api/v1/impact-analysis?endpoint=/api/v2/payments
# Returns: affected users, revenue impact, feedback sentiment
POST /api/v1/feedback/enrich
# Payload: {feedback_id, user_id, session_id}
# Returns: correlated traces, metrics, related synthetics
Correlation Coverage: % of user feedback connected to technical data
MTTR Reduction: Time to detect vs. time to correlate
False Positive Rate: Invalid correlations per incident
User Satisfaction: CSAT improvement correlated to faster resolutions
Synthetic Efficacy: % of synthetic failures that predict real incidents
10. Privacy & Compliance
PII Handling: Hash/redact user PII in correlation layer
Data Retention: Configurable per source (GDPR compliant)
Audit Trail: All correlation decisions logged for review
Access Control: RBAC on correlation data (e.g., support sees feedback+traces, eng sees everything)
Technology Stack Recommendations
Ingestion: Apache Kafka/Flink for streaming
Processing: Flink/Beam for windowed correlations
Graph DB: Neo4j (mature) or JanusGraph (scalable)
Search: Elasticsearch for logs + Jaeger traces
Metrics: Prometheus + Thanos for long-term
ML: Scikit-learn/TensorFlow for models, MLflow for tracking
API: FastAPI (Python) or Go with gRPC
Frontend: React + D3.js for visualizations
This design provides a layered correlation approach that starts with exact matches and progressively uses temporal, semantic, and learned patterns to connect disparate signals. The system becomes smarter over time as more correlation evidence accumulates, creating a living map of API health that bridges technical monitoring with real user experience.
Given the trade-offs, a hybrid approach:
Metrics: Prometheus (for real-time aggregation) and long-term storage in Thanos or Cortex.
Logs and Traces: Elasticsearch (using Jaeger's Elasticsearch storage for traces). We can store traces as documents in Elasticsearch, and then we can do full-text search and joins by common fields.
Feedback: A relational database (PostgreSQL) or also in Elasticsearch for easier search.
Then, the correlation service can query Elasticsearch for logs, traces, and feedback (if in ES) and query Prometheus for metrics. We can use Elasticsearch as the primary index because we can store metadata from all sources there.
Let's design the Elasticsearch index pattern:
We can have separate indices for each type but with a common set of fields for correlation:
metrics-*: time-series, but we can also create a denormalized index for correlation that has one document per metric timestamp? That might be too heavy. Alternatively, we can query Prometheus directly and then use the time-series data as is.
Another idea: use a single index for all events? But metrics are high frequency and might not fit well.
Alternatively, we can create a "correlation view" that is materialized by joining data from multiple sources periodically (batch) and storing in a relational database for quick querying. But that introduces latency.
Given the complexity, perhaps the best approach is to use an existing observability platform that already correlates metrics, logs, and traces (like Datadog, New Relic, etc.) and then build the feedback loop integration on top of that platform's API. But the requirement is to design a layer, so we assume we are building from scratch.
Let's assume we are using the ELK stack for logs and traces (with Jaeger storage in Elasticsearch) and Prometheus for metrics. We'll also have a PostgreSQL for feedback.
We need to correlate:
By time and endpoint: easy because all have timestamps and endpoint (or service) information.
By trace ID: logs and traces have trace ID. We can also include trace ID in metrics? Not typically, but we can have metrics per trace? That's too granular. Instead, we can have metrics aggregated by endpoint and status code, and then when we see a spike, we look at logs and traces for that endpoint and time.
So the correlation service will:
Accept a query: e.g., GET /api/v1/users?time=2024-01-01T10:00:00Z&window=5m
Break down:
Get metrics for the endpoint (from Prometheus) for the time window.
Get logs for the endpoint (from Elasticsearch) for the time window, and also filter by error level if needed.
Get traces for the endpoint (from Elasticsearch via Jaeger index) for the time window. Note: in Jaeger, the operation name is often the endpoint, so we can search by operationName and startTime.
Get feedback (from PostgreSQL or Elasticsearch) for the time window that mentions the endpoint or the user (if we have user ID from the request context?).
Then, we can also try to link by user ID: if we have a user ID in the logs (from the request context) and in the feedback (if the user is logged in when reporting), we can link those.
But note: the feedback might not have the endpoint, but we can still show it if it's in the same time window for the same user? That might be too broad.
Alternatively, we can have a feedback webhook that, when a user reports an issue, we ask for the current URL (which might be the endpoint) and the user ID (if logged in). Then we store that.
So, the correlation is primarily by time, endpoint, and optionally by user and trace ID.
We can also generate a correlation ID for synthetic tests and include it as a header in the request. Then, if the application propagates that header, it will appear in logs and traces. Then we can directly link the synthetic test run to the traces and logs.
For passive monitoring, we rely on the trace ID that is generated by the application (if distributed tracing is enabled) and that appears in logs and traces. We don't have a synthetic test ID in production traffic unless we inject one.
So, the correlation layer will have two modes:
Incident-based: given a time range and an endpoint (or service), pull all related data.
Feedback-based: given a feedback ID, pull all related data (by time, user, endpoint).
We can also have a third: synthetic test failure-based: given a test run ID, pull the related traces (if the test included the correlation ID) and logs for that time and endpoint.
Implementation:
We'll build a service (in a language of choice, say Go or Python) that:
Has connectors to:
Prometheus: to query metrics (using PromQL).
Elasticsearch: to query logs (using Lucene queries) and traces (using Jaeger's Elasticsearch index structure).
PostgreSQL: for feedback.
Defines a common response format that includes:
Metrics: time series data for the endpoint (latency, error rate, etc.)
Logs: list of log entries (with message, level, etc.)
Traces: list of trace IDs and their details (spans) for the endpoint.
Feedback: list of feedback entries.
Synthetic tests: list of test runs for the endpoint in the time window.
The service can also try to stitch together a single request from the logs and traces if we have a trace ID. But note: one trace might have multiple spans for the same endpoint? Actually, an endpoint might be hit multiple times in a trace. So we might want to show the traces that include the endpoint.
To reduce data volume, we might limit the number of logs and traces returned, or paginate.
The UI would then display these in a correlated timeline.
Example query:
GET /correlate?service=user-service&endpoint=/api/v1/users&start=2024-01-01T10:00:00Z&end=2024-01-01T10:05:00Z
Then, in the UI, we can show a timeline with all these events and allow the user to drill down.
Advanced: we can also try to automatically correlate by finding logs and traces that have the same endpoint and time and then group them. Also, if a trace has an error and there is a feedback at the same time from the same user (if user ID is in the trace context), then we can highlight that.
Challenges:
The same user might make multiple requests. We need to be careful not to over-correlate.
Time windows: we need to choose an appropriate window. The user might specify, or we can infer from the data (e.g., when an anomaly starts).
Data volume: we might need to sample logs and traces if there are too many.
To handle high volume, we can:
Pre-aggregate metrics and only store raw logs and traces for a limited time (e.g., 7 days) and then aggregate or sample.
Use the correlation service to query only the most relevant logs and traces (by filtering on error level, status codes, etc.).
Another idea: use a graph database to store the relationships. For each request (trace) we have nodes for: trace, spans, logs (linked by trace ID and timestamp), user (if available), and feedback (if available). Then, given a starting point (e.g., a feedback), we can traverse to related traces and logs. But building that graph in real-time from multiple sources is complex.
Given the complexity and the need for real-time or near-real-time, we might start with the time-based correlation and then add more advanced linking as we have more context.
Steps to build:
Set up data collection for each source (synthetic tests, Prometheus, Filebeat for logs, Jaeger for traces, feedback API).
Set up storage for each.
Build the correlation service that can query each storage and combine results.
Build a simple UI that displays the combined results.
Add alerting: for example, if there is a synthetic test failure and an increase in error logs for the same endpoint, send an alert.
Enhance correlation by enriching data with common fields (like user ID) where possible.
We must ensure that the application logs and traces include user IDs (if available) and that the synthetic tests can pass a user context (if needed) to test user-specific flows.
This is a high-level design. The actual implementation would require careful consideration of data volumes, query performance, and storage costs.
But note: the correlation service queries all these databases directly.
Alternatively, we can have a central event store:
All sources -> Kafka -> Stream Processor -> Central Event Store (Elasticsearch?) -> Correlation Service -> UI
The stream processor would normalize and enrich events with common fields (service, endpoint, user ID, trace ID) and write to a central store. Then the correlation service only queries that central store.
This might be more scalable for ad-hoc queries because we have one store with all events. But we still need to store the large binary traces? We might store only the trace metadata in the central store and keep the full trace in Jaeger storage. Similarly for metrics, we might store aggregated metrics in the central store and raw in Prometheus.
So, the central store could be a "correlation index" that maps:
For logs: store the log message and metadata (including trace ID).
For traces: store the trace ID, service, operation, start time, duration, and maybe a link to the full trace in Jaeger storage.
For metrics: store aggregated data points (maybe we don't store raw metrics in the central store, but we can store the time series in Prometheus and the correlation service queries both).
For feedback: store the feedback text and metadata.
For synthetic tests: store the test result and metadata.
Then the central store (Elasticsearch) can be used to quickly find all events for an endpoint and time range, and then we fetch the full traces and metrics as needed.
This seems a good compromise.
Let's design the central index mapping for Elasticsearch:
We'll have one index per day for each type? Or one index for all events? We can use a single index with a type field (or separate indices but same mapping for common fields). Common fields:
@timestamp: the event time.
service: the service name (for logs and traces, we can extract from the span or log tag).
endpoint or operation: the endpoint or operation name.
But note: metrics are time-series and we might not want to store every data point in Elasticsearch because of volume. Instead, we can store metrics as events only when there is an anomaly or we can store aggregated metrics (e.g., per minute) in Elasticsearch for correlation. Or we can skip storing metrics in Elasticsearch and query Prometheus separately.
Given the volume, I'd say:
Logs: store all in Elasticsearch (with index rotation).
Traces: store in Jaeger storage (which might be Elasticsearch) but also index the trace metadata (like traceID, service, operation, start time, duration) in the central Elasticsearch for quick lookup? Actually, Jaeger's Elasticsearch storage already indexes these fields. So we can query Jaeger's Elasticsearch index directly. So maybe we don't need a separate central index for traces? But then we have two different Elasticsearch clusters (one for logs, one for traces) or two indices in the same cluster. We can use the same Elasticsearch cluster for logs and traces, but they are in different indices. Then our correlation service would query both indices.
So, we might not need a separate central index if we use the same Elasticsearch for logs and traces. Then we can query both indices with a multi-index search.
For metrics and feedback, we might want to bring them into Elasticsearch for unified search.
Metrics: We can use a Metricbeat to ship Prometheus metrics to Elasticsearch? Or we can have a connector that queries Prometheus and writes aggregated metrics (like per minute error rates) to Elasticsearch. Alternatively, we can leave metrics in Prometheus and query it separately. But for correlation, we want to see metrics in the same timeline. So we can write metrics to Elasticsearch as events too. We can use a tool like prometheus-es-exporter to write metrics to Elasticsearch.
Feedback: Use an application that writes feedback to Elasticsearch (index: feedback-*).
Synthetic tests: The test runner writes results to Elasticsearch (index: synthetic-*).
Then, we have all events in Elasticsearch (logs, traces, metrics, feedback, synthetic) and we can query across them by time and other fields.
We need to define the mapping for each type but with common fields.
But note: Prometheus metrics are counters and gauges. We might want to store the raw samples or the aggregated per minute? We can store the raw samples if the volume is not too high, but typically Prometheus scrapes every 15 seconds. So we can store each scrape as an event? That might be too many. Instead, we can store the rate over a window? But then we lose granularity.
Alternatively, we can leave metrics in Prometheus and have the correlation service query Prometheus for the time series and then return that data separately. This avoids duplicating high-cardinality metrics in Elasticsearch.
Given the trade-offs, I think it's acceptable to have metrics in Prometheus and the rest in Elasticsearch. Then the correlation service will:
Query Elasticsearch for logs, traces, feedback, synthetic tests.
Query Prometheus for metrics.
And then combine in the response.
So, the central correlation index is not needed; we use Elasticsearch as a common store for everything except metrics.
Steps for the correlation service:
Receive query with time range and filters (service, endpoint, user, etc.).
Query Elasticsearch for all indices (logs, jaeger, feedback, synthetic) with the filters. Use a bool query with should clauses for each type and then filter by time and endpoint.
Query Prometheus for metrics: we need to know which metrics to query. We can assume the user wants common metrics like request rate, error rate, latency percentiles. We can have a configuration that maps endpoints to PromQL queries. Or we can return all metrics for the service? That might be too many.
Alternatively, we can define a set of standard metrics per service and endpoint (like Golden Signals). We can have a configuration file that defines for each service and endpoint which metrics to show.
So the correlation service will:
For a given service and endpoint, look up the metric names (or PromQL queries) from a config.
Execute the PromQL queries for the time range.
Combine the results.
This way, we don't need to store metrics in Elasticsearch.
Correlation service: a web service that queries both and returns a combined view.
The correlation service can be written in any language. We'll use Go for performance.
We'll need:
Elasticsearch client.
Prometheus client (to query Prometheus HTTP API).
The response will be a JSON with:
{
"metrics": {
"query1": { "datapoints": [ ... ] },
"query2": { ... }
},
"logs": [ ... ],
"traces": [ ... ], // but note: traces might be large, so we might return only trace IDs and let the UI fetch details from Jaeger UI?
"feedback": [ ... ],
"synthetic_tests": [ ... ]
}
For traces, we might return only the trace IDs and let the user open in Jaeger UI for details, because traces can be large and we don't want to duplicate storage.
Alternatively, we can return the trace summary (like service, operation, duration, status) and a link to Jaeger.
So, the trace query from Elasticsearch (Jaeger index) would return:
And then we can provide a link: http://jaeger-ui:16686/trace/abc.
Similarly, for logs, we return the log messages.
For synthetic tests, we return the test result and the request/response details.
Now, about correlation by user ID:
If the feedback has a user ID and the logs/traces have a user ID (from the authenticated user), then we can link them. But in the query, if we filter by user ID, we might get more relevant results.
So, the correlation service should also accept a user_id filter.
But note: not all logs have user ID. We need to make sure the application logs include the user ID for authenticated requests.
Synthetic tests might run as a test user, so we can set a user ID for synthetic tests.
So, the design is:
We have multiple data sources stored in Elasticsearch (logs, traces, feedback, synthetic tests) and metrics in Prometheus.
The correlation service queries Elasticsearch and Prometheus and combines the results.
The UI displays the combined results.
This is a simplified but practical design.
Next steps for implementation:
Set up Elasticsearch and index patterns for logs, traces (Jaeger), feedback, synthetic tests.
Set up Prometheus and ensure metrics are collected.
Write the correlation service.
Build a simple UI.
We must also consider:
Time zones: use UTC everywhere.
Pagination: because logs can be many, we should paginate the results.
Let's design the Elasticsearch queries:
For a given time range and endpoint, we want to get:
Logs: index logs-*, query: @timestamp in range, endpoint match, optionally userID match. We might also filter by level: error if the user is interested in errors? But the query might be generic.
Traces: index jaeger-*, query: startTime in range, operationName match (or we have indexed endpoint as a tag? In Jaeger, the operation name is the span operation, which is often the endpoint. We can also index the http.route tag if available. So we might need to adjust.
Synthetic tests: index synthetic-*, query: @timestamp in range, endpoint match.
Feedback: index feedback-*, query: @timestamp in range, endpoint match or userID match.
We can run these as separate queries and then combine, or use a multi-index search with a bool query that has should for each type and then filter by type? But then we have to parse the results by type.
Alternatively, we can run separate queries for each type to have more control over pagination and sorting.
Since the data types are different, separate queries might be easier.
But for the UI, we want a unified timeline. So we need to merge the results by timestamp. We can do:
Get logs, traces, feedback, synthetic tests from Elasticsearch for the time range and endpoint (and user if provided).
Sort all by timestamp.
Then group by type in the UI.
But note: metrics are time-series and we want to show them as a chart. So we keep metrics separate.
Then the UI can plot the metrics and show the events in a timeline below.
This seems workable.
Now, about the correlation by trace ID:
When we get a log, it might have a traceID. We can then also fetch the trace from Jaeger and include it in the event? But that would duplicate. Alternatively, we can have an event for the trace itself (the root span) and then the logs are separate. But then the UI can show that the log and trace are related by the same traceID.
So in the events array, we might have:
A trace event (the root span) with traceID.
Log events with the same traceID.
Then the UI can group them.
But note: a trace might have multiple logs. We don't want to list the trace for every log. So we list the trace once and then the logs separately, and the UI can group by traceID.
So, we can return the events as is, and the UI can group by traceID if needed.
Alternatively, we can structure the response to have:
{
"metrics": ...,
"traces": [ // list of traces with their logs embedded?
{
"traceID": "abc",
"spans": [...],
"logs": [ ... ] // logs that have this traceID?
}
],
"feedback": [...],
"synthetic_tests": [...]
}
But then we are duplicating logs if they belong to multiple traces? No, a log typically belongs to one trace. But if we have context propagation, a log might have one traceID. So we can attach logs to traces.
However, we might have logs without traceID (e.g., from a part of the system that doesn't do tracing). So we should also have a separate list of logs without traceID.
So, we can:
Query logs that have traceID and group by traceID, and then for each traceID, also fetch the trace from Jaeger.
Then, we have a list of traces with their logs.
And then separate logs without traceID.
But that might be heavy because for each trace we are fetching the trace details. We might do:
Step 1: Query logs for the time range and endpoint. Get the distinct traceIDs from logs that have traceID.
Step 2: Query Jaeger for those traceIDs (and also for the time range and endpoint? But we already have traceIDs).
Step 3: For each trace, get the logs that have that traceID (we already have them from step1) and attach.
But note: the logs we get in step1 might be a subset (we might limit the number of logs). We might miss some logs for a trace if we paginate logs? We need to be careful.
Given the complexity, maybe it's simpler to return everything separately and let the frontend group by traceID.
So, we return:
A list of traces (from Jaeger) for the time range and endpoint. Each trace has a traceID.
A list of logs (from Elasticsearch logs index) for the time range and endpoint. Each log has a traceID (or null).
Then the frontend can: for each trace, collect the logs with the same traceID and show them under the trace.
But then we might have traces without logs? That's possible if the logs were not indexed or if the trace has no logs? Actually, if we have distributed tracing, each span might have logs, but they are stored in the trace storage (Jaeger) as part of the span? In Jaeger, logs are stored within spans. So when we query Jaeger for traces, we get the spans and their logs. So we don't need to query the separate logs index for logs that are part of a trace. But we might have application logs that are not part of a span (e.g., background jobs). So we need both.
So, we have two types of logs:
Application logs that are not part of a distributed trace (or not indexed as part of a trace). These are in the logs index.
Logs that are part of a trace: these are stored within the spans in Jaeger (and also possibly in the logs index if we ship all logs to Elasticsearch). There might be duplication.
To avoid duplication, we can:
Only use the logs from Jaeger for traces, and for non-traced logs, use the logs index.
But then if we want to see all logs for an endpoint, we need to combine:
Logs from Jaeger (for traced requests) and logs from Elasticsearch (for non-traced). But note: the same log might be in both if we ship all logs to Elasticsearch and Jaeger also stores logs? Actually, Jaeger stores logs as part of the span, and we might also ship the same logs to Elasticsearch via Filebeat. That would duplicate.
To avoid duplication, we can:
Configure the application to not log to both? Or we can deduplicate by traceID and log message and timestamp? That's messy.
Alternatively, we can rely on Jaeger for all logs that are part of a trace and use Elasticsearch only for logs that are not part of a trace (or for logs from services that don't do tracing). But then we lose the ability to search all logs in one place.
Given the complexity, I think it's acceptable to have duplication and then in the UI, we can show:
For each trace, we show the spans and their logs (from Jaeger).
Additionally, we show logs from the logs index that are within the time range and for the endpoint, even if they have a traceID? That would duplicate with the logs in the trace. So we should filter out logs that have a traceID and that are part of a trace we are already showing? But then we might miss logs that are part of a trace but not captured by Jaeger? Unlikely.
So, we can:
Query Jaeger for traces for the endpoint and time range. Get the trace IDs.
Query the logs index for logs that are in the time range and endpoint but with traceID not in the set of trace IDs we got from Jaeger? That would give us logs that are not part of any traced request? But what if the trace is not found in Jaeger (maybe due to sampling)? Then we would show the log anyway.
This is getting complicated.
Let's simplify:
We are building an observability correlation layer for an API. We assume that the API is instrumented with distributed tracing (OpenTelemetry) and that all requests are traced. Then, all logs that are part of a request have a traceID. We can then:
Store all application logs in Elasticsearch.
Store all traces in Jaeger (which also stores the logs that are part of the spans).
But then we have two copies of the same logs. To avoid duplication in the UI, we can:
When we query for logs for an endpoint and time range, we also get the traceIDs from the traces we fetched. Then, we filter out logs that have a traceID that is in the set of traceIDs we are already showing via traces.
But note: the logs index might contain logs that are not part of a request (e.g., startup logs) and we want to see those. So we want to see:
All traces for the endpoint.
All logs that are not part of any trace (or that are part of traces that we are not showing?).
Actually, if we show all traces for the endpoint, then we should not show the logs that belong to those traces because they are already in the trace. So we can:
Step 1: Query Jaeger for traces for the endpoint and time range. Get list of traceIDs.
Step 2: Query Elasticsearch logs for the endpoint and time range and with traceID not in the list from step1 (or without traceID). This gives us logs that are not part of the traced requests we found.
But what if a trace has logs that are not in the trace? That shouldn't happen if we are using OpenTelemetry and the logs are attached to spans. But if we have logs that are not attached to spans (e.g., logged in a background thread without context) then they might have a traceID (if the context is propagated) but not be in the trace because the trace was not sent? That's a corner case.
Given the complexity, for the first version, we can:
Show traces from Jaeger (with their embedded logs).
Show logs from Elasticsearch that are within the time range and for the endpoint, without any filtering. This will duplicate the logs that are in the traces, but we can live with that for now.
We can later add deduplication.
So, the plan:
The correlation service will have:
Endpoint: GET /correlate
Parameters:
service (required): service name.
endpoint (required): endpoint path.
start (required): start time in RFC3339.
end (required): end time in RFC3339.
user_id (optional): user ID to filter.
max_results (optional): max number of events (logs, traces, etc.) to return.
Steps:
Query Prometheus for metrics. We have a config that maps (service, endpoint) to a list of PromQL queries. We run each query for the time range and return the results.
Query Jaeger for traces:
Use the Jaeger Elasticsearch index. We need to know the index pattern (e.g., jaeger-span-*).
Query: operationName = endpoint and startTime >= start and startTime <= end. Also, if service is provided, we can filter by process.serviceName = service.
We might also filter by userID tag if we tag traces with user ID. We can include that if available.
Return the traces (with their spans and logs). But note: the trace might be large. We can return only the root span? Or we can return the trace summary and a link. Let's return the trace as stored in Jaeger (with all spans) but we might limit the number of traces (e.g., 10) by sorting by startTime descending (most recent first) and size.
Query Elasticsearch logs index (e.g., logs-*) for logs with @timestamp in range, endpoint match, and service match. Also, if user_id provided, filter by userID. We can also filter by level: error if we want only errors? But the query is generic. We might return all logs? That could be too many. We should paginate and limit. We can return the most recent 100 logs, for example.
Query Elasticsearch feedback index for feedback with @timestamp in range and endpoint match (or user_id match). We can also match by user_id if provided.
Query Elasticsearch synthetic index for synthetic tests with @timestamp in range, endpoint match.
Combine the results into the events array, but we have traces already with their logs. We don't want to duplicate the logs that are in the traces? But we are also querying logs separately. So we might have:
events = []
for each trace in traces:
events.push({ type: 'trace', timestamp: trace.startTime, data: trace })
for each span in trace.spans:
for each log in span.logs:
events.push({ type: 'trace_log', timestamp: log.timestamp, data: log, traceID: trace.traceID })
then add logs from logs index (which include logs not in traces? but we might have duplicates with the trace_logs). We can skip logs that have a traceID that is in the set of traceIDs we got from Jaeger? But then we might miss logs that are in the logs index and also in the trace (because we already added them as trace_log). So we can filter out logs from the logs index that have a traceID in the set of traceIDs.
But note: the logs index might have logs that are part of a trace but we didn't get the trace from Jaeger (maybe because of sampling or because the trace is too old? we are querying by time, so if the trace started in the time range, we should get it). So we can:
Collect all traceIDs from the traces we got.
When querying logs index, exclude logs with traceID in that set.
But then we might have logs with traceID that we didn't get the trace for? That's possible if the trace is not in Jaeger (maybe because of retention). Then we would show the log without the trace. That's acceptable.
So:
Step 2.5: Collect traceIDs from the traces.
Step 3: Query logs index with condition: (traceID NOT IN (list) OR traceID NOT EXISTS).
Also, we might have logs that are part of a trace but we didn't get the trace because the trace's startTime is outside the range? But the log's timestamp is within. Then we would show the log without the trace. That's acceptable because the trace might be outside the window.
For synthetic tests and feedback, they don't have traceID typically, so we just add them.
Then, we sort all events by timestamp.
Return the response.
This seems workable.
Now, about the metric queries: we need to define the PromQL queries for each endpoint. We can have a configuration file:
We can also have default metrics for all endpoints (like request rate, error rate, latency) if not specified.
The correlation service loads this config and for the given service and endpoint, it runs the PromQL queries.
We assume that the Prometheus server has the metrics with labels service and endpoint.
Now, the implementation:
We'll write a Go service that:
Loads the metric config from a file.
Has handlers for /correlate.
Uses the Elasticsearch client to query:
Jaeger index (we need to know the index pattern, e.g., jaeger-span-*). We can make it configurable.
Logs index pattern (e.g., logs-*).
Feedback index (e.g., feedback-*).
Synthetic index (e.g., synthetic-*).
Uses the Prometheus HTTP API to query metrics.
We'll need to handle authentication if these systems are secured.
This is a basic design. We might need to adjust based on actual data volumes and performance.
Let's consider scalability:
The Elasticsearch queries might be heavy if we have a lot of logs and traces. We should use time-based indices and limit the time range (e.g., max 1 hour). We can also use pagination for logs.
The Jaeger query might return many traces. We should limit the number of traces (e.g., 100) and sort by startTime (most recent first).
The Prometheus queries are efficient because Prometheus is optimized for time-series.
We can also cache results if needed.
Now, the UI:
We can build a simple React app that:
Has a form to input service, endpoint, time range, and optional user ID.
Shows a chart for metrics (using a charting library like Recharts) and a timeline for events.
The timeline can be a list of events with icons for type (log, trace, feedback, synthetic) and the timestamp. Clicking on a trace opens the Jaeger UI in a new tab. Clicking on a log shows the full log message. etc.
This should cover the basic requirements.
Advanced: we can also add the ability to correlate by user session: if we have a session ID that flows through the system, we can use that. But that's future work.
Finally, we must not forget to instrument our own applications with OpenTelemetry to get traces and include user IDs in the context.
This design is a starting point and will evolve as we learn more.
I'll design a comprehensive API observability correlation layer that integrates synthetic testing, passive monitoring, and customer feedback into a unified system.