Skip to content

feat(console): add envId and orgId to the loggers #11707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025

Conversation

aditya-goyal01
Copy link
Contributor

@aditya-goyal01 aditya-goyal01 commented May 2, 2025

Issue

https://gravitee.atlassian.net/browse/APIM-9157

Description

Summary

This Pull Request primarily introduces contextual logging functionality within the system. The changes enable the inclusion of organization and environment IDs in log entries, improving traceability and debugging capabilities.

Main Changes

  • Added a new ContextualLoggingFilter class: Implements a filter to include organization (orgId) and environment (envId) identifiers in logging contexts using SLF4J's MDC.
  • Modified security configuration files: Integrated the ContextualLoggingFilter in BasicSecurityConfigurerAdapter for both management and management-v2 modules.
  • Updated logging patterns: Adjusted logback.xml and api-configmap.yaml to support contextual logging in log outputs if enabled.
  • Introduced new Helm configuration options:
    contextualLoggingEnabled: A flag to enable/disable contextual logging.
    contextualLoggingEncoderPattern: A customizable logging pattern for contextual logs.

📚  View the storybook of this branch here

@aditya-goyal01 aditya-goyal01 added the ready_to_test Push the code from the PR into a dedicated environment label May 2, 2025
@aditya-goyal01 aditya-goyal01 force-pushed the apim-9157-add-envId-and-orgId-in-logger branch 5 times, most recently from 221ee55 to 1d306db Compare May 9, 2025 10:44
@aditya-goyal01 aditya-goyal01 force-pushed the apim-9157-add-envId-and-orgId-in-logger branch 6 times, most recently from 44b98a3 to d31bc00 Compare May 15, 2025 10:01
@aditya-goyal01 aditya-goyal01 marked this pull request as ready for review May 15, 2025 10:02
@aditya-goyal01 aditya-goyal01 requested review from a team as code owners May 15, 2025 10:02
@aditya-goyal01 aditya-goyal01 removed the ready_to_test Push the code from the PR into a dedicated environment label May 15, 2025
@aditya-goyal01 aditya-goyal01 force-pushed the apim-9157-add-envId-and-orgId-in-logger branch 6 times, most recently from f4dfbf5 to 4edb6c6 Compare May 20, 2025 11:21
helm/values.yaml Outdated
@@ -470,9 +470,11 @@ api:
name: api
logging:
debug: false
contextualLoggingEnabled: false
contextualLoggingEncoderPattern: "%d{HH:mm:ss.SSS} [%thread] [%X{orgId} %X{envId}] %-5level %logger{36} - %msg%n%n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contextualLoggingEncoderPattern: "%d{HH:mm:ss.SSS} [%thread] [%X{orgId} %X{envId}] %-5level %logger{36} - %msg%n%n"
contextualLoggingEncoderPattern: "%d{HH:mm:ss.SSS} [%thread] [%X{orgId} %X{envId}] %-5level %logger{36} - %msg%n"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

helm/values.yaml Outdated
stdout:
json: false
encoderPattern: "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
encoderPattern: "%d{HH:mm:ss.SSS} [%thread] [%X{orgId} %X{envId}] %-5level %logger{36} - %msg%n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say by default it should stay the same as before (i.e. without org and env)?
Sorry I don't remember 🤷🏻 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we agreed on that. It's updated now. 👍

@aditya-goyal01 aditya-goyal01 force-pushed the apim-9157-add-envId-and-orgId-in-logger branch 2 times, most recently from fab06a1 to 110559f Compare May 21, 2025 07:25
@aditya-goyal01 aditya-goyal01 force-pushed the apim-9157-add-envId-and-orgId-in-logger branch from 110559f to dde17ca Compare May 21, 2025 08:28
@aditya-goyal01 aditya-goyal01 merged commit bc9a3c4 into master May 21, 2025
13 of 14 checks passed
@aditya-goyal01 aditya-goyal01 deleted the apim-9157-add-envId-and-orgId-in-logger branch May 21, 2025 08:54
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.

2 participants