Skip to content

Commit c6b179f

Browse files
committed
fix: Do not add execution_id field if logging is disabled
Fix logger to not add field if logging is disabled.
1 parent 701e6cd commit c6b179f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

invoker/core/src/main/java/com/google/cloud/functions/invoker/gcf/JsonLogHandler.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
public final class JsonLogHandler extends Handler {
1919
private static final String SOURCE_LOCATION_KEY = "\"logging.googleapis.com/sourceLocation\": ";
20+
private static final String LOG_EXECUTION_ID_ENV_NAME = "LOG_EXECUTION_ID";
2021

2122
private static final String DEBUG = "DEBUG";
2223
private static final String INFO = "INFO";
@@ -108,9 +109,11 @@ private static void appendSourceLocation(StringBuilder json, LogRecord record) {
108109
}
109110

110111
private void appendExecutionId(StringBuilder json, LogRecord record) {
111-
json.append("\"execution_id\": \"")
112-
.append(executionIdByThreadMap.get(Integer.toString(record.getThreadID())))
113-
.append("\", ");
112+
if (executionIdLoggingEnabled()) {
113+
json.append("\"execution_id\": \"")
114+
.append(executionIdByThreadMap.get(Integer.toString(record.getThreadID())))
115+
.append("\", ");
116+
}
114117
}
115118

116119
private static String escapeString(String s) {
@@ -142,4 +145,8 @@ public void addExecutionId(long threadId, String executionId) {
142145
public void removeExecutionId(long threadId) {
143146
executionIdByThreadMap.remove(Long.toString(threadId));
144147
}
148+
149+
private boolean executionIdLoggingEnabled() {
150+
return Boolean.parseBoolean(System.getenv().getOrDefault(LOG_EXECUTION_ID_ENV_NAME, "false"));
151+
}
145152
}

0 commit comments

Comments
 (0)