Skip to content

[TT-11125] Add trace_id to traffic logs

8941d7f
Select commit
Loading
Failed to load commit list.
Closed

[TT-11125] Add trace_id to traffic logs #899

[TT-11125] Add trace_id to traffic logs
8941d7f
Select commit
Loading
Failed to load commit list.
probelabs / Visor: overview succeeded Oct 2, 2025 in 4m 47s

✅ Check Passed

overview check completed successfully with no issues found.

Details

📊 Summary

  • Total Issues: 1

🐛 Issues by Category

📚 Documentation (1)

  • ℹ️ AI_RESPONSE:1 - ### Pull Request Analysis: [TT-11125] Add trace_id to traffic logs

This analysis provides a comprehensive overview of the pull request, focusing on its impact, technical changes, and architectural implications.

1. Change Impact Analysis

What this PR accomplishes

This pull request enhances the observability of API traffic by embedding a distributed tracing identifier (trace_id) into the core analytics data. By adding TraceID to the AnalyticsRecord struct, Tyk Pump can now collect, process, and store this identifier alongside other request metrics. This allows developers and operators to correlate a specific API request log with a complete distributed trace, making it significantly easier to debug issues, monitor performance, and understand the end-to-end journey of a request across multiple services.

Key Technical Changes

  1. Data Model Extension: The AnalyticsRecord struct in analytics/analytics.go has been updated with a new TraceID field. This field is tagged for proper serialization to JSON (json:"trace_id") and for persistence in SQL databases via GORM (gorm:"column:traceid").
  2. Data Export Integration: The GetFieldNames() and GetLineValues() methods have been updated to include the new TraceID field. This ensures that pumps exporting data to formats like CSV will automatically include the trace identifier in their output.
  3. Comprehensive Testing: New unit tests were added in analytics/analytics_test.go to validate the functionality of the TraceID field. These tests cover:
    • Storing and retrieving the TraceID.
    • Inclusion in field name and value lists for data export.
    • Correct handling by the RemoveIgnoredFields function, ensuring it can be selectively excluded from the record if needed.

Affected System Components

  • Data Ingestion: Any part of the system that creates or deserializes AnalyticsRecord objects will now handle the TraceID.
  • Data Persistence (Pumps): All persistence-related pumps are affected. The TraceID will be automatically stored in any backend that relies on the fields of the AnalyticsRecord struct. This includes:
    • SQL Databases (e.g., PostgreSQL): The gorm tag ensures the traceid column is populated.
    • NoSQL/Document Databases (e.g., MongoDB, Elasticsearch): The json tag ensures the trace_id field is included in the stored document.
    • File-based Pumps (e.g., CSV): The changes to GetFieldNames and GetLineValues ensure the TraceID is written to files.
  • Testing Framework: The test suite has been expanded to ensure the new field is correctly handled.

2. Architecture Visualization

The following diagram illustrates how the AnalyticsRecord, now enriched with TraceID, flows through the Tyk Pump ecosystem. The change ensures that the tracing information captured at the gateway is propagated to all configured data sinks.

I was unable to complete your request due to reaching the maximum number of tool iterations.
Loading

Generated by Visor - AI-powered code review

Annotations

Check notice on line 1 in AI_RESPONSE

See this annotation in the file changed.

@probelabs probelabs / Visor: overview

documentation Issue

### **Pull Request Analysis: [TT-11125] Add trace_id to traffic logs**

This analysis provides a comprehensive overview of the pull request, focusing on its impact, technical changes, and architectural implications.

### **1. Change Impact Analysis**

#### **What this PR accomplishes**

This pull request enhances the observability of API traffic by embedding a distributed tracing identifier (`trace_id`) into the core analytics data. By adding `TraceID` to the `AnalyticsRecord` struct, Tyk Pump can now collect, process, and store this identifier alongside other request metrics. This allows developers and operators to correlate a specific API request log with a complete distributed trace, making it significantly easier to debug issues, monitor performance, and understand the end-to-end journey of a request across multiple services.

#### **Key Technical Changes**

1.  **Data Model Extension:** The `AnalyticsRecord` struct in `analytics/analytics.go` has been updated with a new `TraceID` field. This field is tagged for proper serialization to JSON (`json:"trace_id"`) and for persistence in SQL databases via GORM (`gorm:"column:traceid"`).
2.  **Data Export Integration:** The `GetFieldNames()` and `GetLineValues()` methods have been updated to include the new `TraceID` field. This ensures that pumps exporting data to formats like CSV will automatically include the trace identifier in their output.
3.  **Comprehensive Testing:** New unit tests were added in `analytics/analytics_test.go` to validate the functionality of the `TraceID` field. These tests cover:
    *   Storing and retrieving the `TraceID`.
    *   Inclusion in field name and value lists for data export.
    *   Correct handling by the `RemoveIgnoredFields` function, ensuring it can be selectively excluded from the record if needed.

#### **Affected System Components**

*   **Data Ingestion:** Any part of the system that creates or deserializes `AnalyticsRecord` objects will now handle the `TraceID`.
*   **Data Persistence (Pumps):** All persistence-related pumps are affected. The `TraceID` will be automatically stored in any backend that relies on the fields of the `AnalyticsRecord` struct. This includes:
    *   **SQL Databases (e.g., PostgreSQL):** The `gorm` tag ensures the `traceid` column is populated.
    *   **NoSQL/Document Databases (e.g., MongoDB, Elasticsearch):** The `json` tag ensures the `trace_id` field is included in the stored document.
    *   **File-based Pumps (e.g., CSV):** The changes to `GetFieldNames` and `GetLineValues` ensure the `TraceID` is written to files.
*   **Testing Framework:** The test suite has been expanded to ensure the new field is correctly handled.

### **2. Architecture Visualization**

The following diagram illustrates how the `AnalyticsRecord`, now enriched with `TraceID`, flows through the Tyk Pump ecosystem. The change ensures that the tracing information captured at the gateway is propagated to all configured data sinks.

```mermaid
I was unable to complete your request due to reaching the maximum number of tool iterations.
```