-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Add standardized property to distinguish a group of applications #39957
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,10 @@ logging: | |
pattern: | ||
correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}] " | ||
include-application-name: false | ||
include-application-group: false | ||
---- | ||
|
||
NOTE: In the example above, configprop:logging.include-application-name[] is set to `false` to avoid the application name being duplicated in the log messages (configprop:logging.pattern.correlation[] already contains it). | ||
NOTE: In the example above, configprop:logging.include-application-name[] and configprop:logging.include-application-group[] is set to `false` to avoid the application name being duplicated in the log messages (configprop:logging.pattern.correlation[] already contains it). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
It's also worth mentioning that configprop:logging.pattern.correlation[] contains a trailing space so that it is separated from the logger name that comes right after it by default. | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.logging.logback; | ||
|
||
import ch.qos.logback.classic.pattern.ClassicConverter; | ||
import ch.qos.logback.classic.pattern.PropertyConverter; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
|
||
import org.springframework.boot.logging.LoggingSystemProperty; | ||
|
||
/** | ||
* Logback {@link ClassicConverter} to convert the | ||
* {@link LoggingSystemProperty#APPLICATION_GROUP APPLICATION_GROUP} into a value suitable | ||
* for logging. Similar to Logback's {@link PropertyConverter} but a non-existent property | ||
* is logged as an empty string rather than {@code null}. | ||
* | ||
* @author Jakob Wanger | ||
* @since 3.4.0 | ||
*/ | ||
public class ApplicationGroupConverter extends ClassicConverter { | ||
|
||
@Override | ||
public String convert(ILoggingEvent event) { | ||
String applicationGroup = event.getLoggerContextVO() | ||
.getPropertyMap() | ||
.get(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName()); | ||
if (applicationGroup == null) { | ||
applicationGroup = System.getProperty(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName()); | ||
if (applicationGroup == null) { | ||
applicationGroup = ""; | ||
} | ||
} | ||
return applicationGroup; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,16 @@ Default logback configuration provided for import | |
|
||
<included> | ||
<conversionRule conversionWord="applicationName" converterClass="org.springframework.boot.logging.logback.ApplicationNameConverter" /> | ||
<conversionRule conversionWord="applicationGroup" converterClass="org.springframework.boot.logging.logback.ApplicationGroupConverter" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: these rules are ordered based on the conversion word so |
||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> | ||
<conversionRule conversionWord="correlationId" converterClass="org.springframework.boot.logging.logback.CorrelationIdConverter" /> | ||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> | ||
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> | ||
|
||
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName[%15.15t]){faint} %clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> | ||
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName[%15.15t]){faint} %clr(---){faint} %clr(%applicationGroup[%15.15t]){faint} %clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> | ||
<property name="CONSOLE_LOG_CHARSET" value="${CONSOLE_LOG_CHARSET:-${file.encoding:-UTF-8}}"/> | ||
<property name="CONSOLE_LOG_THRESHOLD" value="${CONSOLE_LOG_THRESHOLD:-TRACE}"/> | ||
<property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- %applicationName[%t] ${LOG_CORRELATION_PATTERN:-}%-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> | ||
<property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- %applicationName[%t] --- %applicationGroup[%t] ${LOG_CORRELATION_PATTERN:-}%-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> | ||
<property name="FILE_LOG_CHARSET" value="${FILE_LOG_CHARSET:-${file.encoding:-UTF-8}}"/> | ||
<property name="FILE_LOG_THRESHOLD" value="${FILE_LOG_THRESHOLD:-TRACE}"/> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
default
is better thanunknown
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree.
unknown_group
aligns with the existingunknown_service
that's used when there's no application name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should defaults to a more meaningful name, for example the default namespace in kubernetes is
default
notunknown
.Most of applications will specify their own
spring.application.name
but leavespring.application.group
absent, they are not equal in nature, I don't think it make sense to align them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid I still disagree. This feature isn't specific to Kubernetes so aligning with its default namespace does not make sense. Furthermore, it isn't a default group but an indication that we do not know the application's group. As such, I think
unknown_group
is more meaningful as it accurately reflects the situation that we're in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service name is supposed to be unique per application. It not being specified means that it is indeed unknown, as there cannot be any sensible default value that actually makes sense. The groups are shared, so it not being specified is a pretty good indicator that it belongs to the (shared) default group, not the shared unknown group.
unknown_group
makes it seem like there is something wrong with the application configuration, whereas you have just opted to not specify an actual group.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the case here.
There's no "the groups" here. As described in #39913, a group can be a company, org, or team, or pretty much whatever else makes sense for grouping a set of applications. There's no concept of a default group as we don't know that such a thing makes sense in any given deployment environment.
"unknown" doesn't imply that something is wrong, all it means is that the group is unknown. I think that accurately reflects the situation as the group really is not known.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO Tag
service.group
shouldn't be added if it'sunknown_group
, It doesn't make sense from observation perspective but increase network packet size.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We only set
service.name
tounknown_application
because it's a required attribute in otel. This isn't the case forservice.group
, so we can just omit it, if it's not set.