Skip to content

[TT-15935] Feature Request - Standardize Log Message Key Across All Tyk Components#8236

Merged
shults merged 2 commits into
masterfrom
TT-15935-feature-request-standardize-log-message-key-across-all-tyk-components
Jun 10, 2026
Merged

[TT-15935] Feature Request - Standardize Log Message Key Across All Tyk Components#8236
shults merged 2 commits into
masterfrom
TT-15935-feature-request-standardize-log-message-key-across-all-tyk-components

Conversation

@shults

@shults shults commented May 18, 2026

Copy link
Copy Markdown
Contributor

Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

Ticket Details

TT-15935
Status In Dev
Summary Feature Request - Standardize Log Message Key Across All Tyk Components

Generated at: 2026-05-18 14:13:09

@probelabs

probelabs Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

This PR standardizes the log message key from msg to message across all non-legacy logging formats in Tyk to improve consistency for log processing and analysis.

This is achieved by introducing a new FieldMap utility that wraps logrus.FieldMap to handle the remapping of log field keys. This utility is integrated into the standard JSONFormatter and TextFormatter. A new defaultFieldMap function establishes the default mapping of msg to message, which is now applied to all standard formatters. The legacy log formatter remains unchanged to ensure backward compatibility.

Files Changed Analysis

  • log/field_map.go & log/field_map_test.go (New): These files introduce the FieldMap struct, which provides a Resolve method to look up and replace log field keys. This is the core logic for the remapping. Comprehensive unit tests are included.
  • log/json_formatter.go (Modified): The custom JSONFormatter is updated to include and use the new FieldMap. It now resolves standard log keys (msg, level, time, error) to their mapped values before serializing the log entry.
  • log/log.go (Modified): The functions that create log formatters (newFormatterText, newFormatterJson, newFormatterLogrusJson) are updated to use a new defaultFieldMap function, applying the msg to message mapping. The legacy formatter is explicitly configured with an empty map to be excluded from this change.

Architecture & Impact Assessment

  • What this PR accomplishes: It standardizes the primary log message key to message for all text and JSON log outputs. This change simplifies log parsing and querying for downstream observability platforms.
  • Key technical changes introduced: A FieldMap utility has been introduced to handle the remapping of log field keys. This map is now integrated into the gateway's log formatters to apply the new standard key.
  • Affected system components: The change affects the global logging subsystem of the Tyk Gateway. All logs generated by the gateway (except those using the legacy format) will now use "message" instead of "msg" as the key for the log entry's main text. This could be a breaking change for any external log monitoring or aggregation systems that have parsing rules specifically targeting the msg field.

Log Formatting Flow

graph TD
    A[Log Event Triggered] --> B[logrus.Entry Created];
    B --> C{Formatter Selected};
    C --> D[JSONFormatter / TextFormatter];
    
    subgraph "Format() Method"
        F["defaultFieldMap: msg -> message"] --> G["FieldMap.Resolve(key)"];
        G --> H["Remap 'msg' key to 'message'"];
    end

    D --> F;
    H --> I[Formatted Log String/JSON];
    I --> J[Log Output];
Loading

Scope Discovery & Context Expansion

The changes are localized within the log package but have a global impact on the application's logging output. The central log.NewFormatter function, used throughout the gateway to initialize logging, now configures this new field mapping by default. Consequently, any component using the standard logger will automatically adopt the new log format. While this PR doesn't modify other modules directly, its effect is system-wide. This could impact users' custom scripts, dashboards, and alerting rules that rely on the previous log structure.

Metadata
  • Review Effort: 2 / 5
  • Primary Label: feature

Powered by Visor from Probelabs

Last updated: 2026-06-10T13:18:48.473Z | Triggered by: pr_updated | Commit: 6c38135

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs

probelabs Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Performance Check Passed

No performance issues found – changes LGTM.

✅ Security Check Passed

No security issues found – changes LGTM.

\n\n \n\n

✅ Performance Check Passed

No performance issues found – changes LGTM.

\n\n

Quality Issues (1)

Severity Location Issue
🟡 Warning log/json_formatter.go:13
A grammatical error was introduced in a comment. 'then' was used where 'than' is grammatically correct.
💡 SuggestionChange 'then' back to 'than' to correct the grammar in the comment.
🔧 Suggested Fix
	// The format to use is the same than for time.Format or time.Parse from the standard

Powered by Visor from Probelabs

Last updated: 2026-06-10T13:18:03.277Z | Triggered by: pr_updated | Commit: 6c38135

💡 TIP: You can chat with Visor using /visor ask <your question>

@shults

shults commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

/visor ask Wrong assumption regarding FieldMap; logrus.FieldMap uses fieldKey type as a key, and it makes imposiible getting the value from map; I can't initiate logrus.fieldKey; I have to remap all the keys

@probelabs

probelabs Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Powered by Visor from Probelabs

Last updated: 2026-05-19T07:52:35.295Z | Triggered by: shults | Commit: a1c3b37

💡 TIP: You can chat with Visor using /visor ask <your question>

@shults

shults commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

/visor ask look at my prev question. wtyd?

@probelabs

probelabs Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Powered by Visor from Probelabs

Last updated: 2026-05-19T11:48:41.016Z | Triggered by: shults | Commit: a1c3b37

💡 TIP: You can chat with Visor using /visor ask <your question>

@shults
shults requested a review from MaciekMis May 26, 2026 13:41
@shults
shults enabled auto-merge (squash) June 10, 2026 13:16
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Jira Linter Failed

Commit: 6c38135
Failed at: 2026-06-10 13:17:08 UTC

The Jira linter failed to validate your PR. Please check the error details below:

🔍 Click to view error details
failed to get Jira issue: failed to fetch Jira issue TT-15935: Issue does not exist or you do not have permission to see it.: request failed. Please analyze the request body for more details. Status code: 404

Next Steps

  • Ensure your branch name contains a valid Jira ticket ID (e.g., ABC-123)
  • Verify your PR title matches the branch's Jira ticket ID
  • Check that the Jira ticket exists and is accessible

This comment will be automatically deleted once the linter passes.

@github-actions

Copy link
Copy Markdown
Contributor

🎯 Recommended Merge Targets

Based on JIRA ticket TT-15935: Feature Request - Standardize Log Message Key Across All Tyk Components

Fix Version: Tyk 5.14.0

⚠️ Warning: Expected release branches not found in repository

Required:

  • master - No matching release branches found. Fix will be included in future releases.

📋 Workflow

  1. Merge this PR to master first

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
95.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@shults
shults merged commit fc6d5ca into master Jun 10, 2026
51 of 55 checks passed
@shults
shults deleted the TT-15935-feature-request-standardize-log-message-key-across-all-tyk-components branch June 10, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants