Skip to content

Commit

Permalink
don't add "<not-provided>" correlation-id to published logs
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Nov 10, 2021
1 parent 3898a92 commit 7b124e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Expand Up @@ -157,6 +157,8 @@ private void emitLogEntry(final ConnectionMonitor.InfoProvider infoProvider, fin

private void emitLogEntry(final LogEntry logEntry) {
if (logLevels.contains(logEntry.getLogLevel())) {
final String correlationId = InfoProviderFactory.FALLBACK_CORRELATION_ID
.equals(logEntry.getCorrelationId()) ? null : logEntry.getCorrelationId();
try {
final Instant timestamp = logEntry.getTimestamp();
final EventTime eventTime = EventTime.fromEpoch(timestamp.getEpochSecond(), timestamp.getNano());
Expand All @@ -166,7 +168,9 @@ private void emitLogEntry(final LogEntry logEntry) {
logMap.put(TAG_LEVEL, logEntry.getLogLevel().toString());
logMap.put(TAG_CATEGORY, logEntry.getLogCategory().toString());
logMap.put(TAG_TYPE, logEntry.getLogType().toString());
logMap.put(TAG_CORRELATION_ID, logEntry.getCorrelationId());
if (null != correlationId) {
logMap.put(TAG_CORRELATION_ID, correlationId);
}
logEntry.getAddress().ifPresent(address -> logMap.put(TAG_ADDRESS, address));
logEntry.getEntityId().ifPresent(entityId -> {
logMap.put(TAG_ENTITY_TYPE, entityId.getEntityType().toString());
Expand All @@ -180,11 +184,11 @@ private void emitLogEntry(final LogEntry logEntry) {

fluencyForwarder.emit(fluentTag, eventTime, logMap);
} catch (final BufferFullException e) {
LOGGER.withCorrelationId(logEntry.getCorrelationId())
LOGGER.withCorrelationId(correlationId)
.error("Got BufferFullException when trying to emit further connection log entries to fluentd: {}",
e.getMessage());
} catch (final IOException e) {
LOGGER.withCorrelationId(logEntry.getCorrelationId())
LOGGER.withCorrelationId(correlationId)
.error("Got IOException when trying to emit further connection log entries to fluentd: <{}>: {}",
e.getClass().getSimpleName(), e.getMessage());
}
Expand Down
Expand Up @@ -34,7 +34,7 @@
*/
public final class InfoProviderFactory {

private static final String FALLBACK_CORRELATION_ID = "<not-provided>";
public static final String FALLBACK_CORRELATION_ID = "<not-provided>";

private InfoProviderFactory() {
throw new AssertionError();
Expand Down

0 comments on commit 7b124e9

Please sign in to comment.