-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow logs to be mutated by LogProcessor (#4643)
* Allow logs to be mutated by LogProcessor * wip * Improve test coverage
- Loading branch information
Showing
23 changed files
with
433 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogRecordBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.logs; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.logs.data.Severity; | ||
import java.time.Instant; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Used to construct and emit logs from a {@link LogEmitter}. | ||
* | ||
* <p>Obtain a {@link LogEmitter#logRecordBuilder()}, add properties using the setters, and emit the | ||
* log to downstream {@link LogProcessor}(s) by calling {@link #emit()}. | ||
*/ | ||
public interface LogRecordBuilder { | ||
|
||
/** Set the epoch timestamp using the timestamp and unit. */ | ||
LogRecordBuilder setEpoch(long timestamp, TimeUnit unit); | ||
|
||
/** Set the epoch timestamp using the instant. */ | ||
LogRecordBuilder setEpoch(Instant instant); | ||
|
||
/** Set the context. */ | ||
LogRecordBuilder setContext(Context context); | ||
|
||
/** Set the severity. */ | ||
LogRecordBuilder setSeverity(Severity severity); | ||
|
||
/** Set the severity text. */ | ||
LogRecordBuilder setSeverityText(String severityText); | ||
|
||
/** Set the body string. */ | ||
LogRecordBuilder setBody(String body); | ||
|
||
/** | ||
* Sets attributes. If the {@link LogRecordBuilder} previously contained a mapping for any of the | ||
* keys, the old values are replaced by the specified values. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
default LogRecordBuilder setAllAttributes(Attributes attributes) { | ||
if (attributes == null || attributes.isEmpty()) { | ||
return this; | ||
} | ||
attributes.forEach( | ||
(attributeKey, value) -> setAttribute((AttributeKey<Object>) attributeKey, value)); | ||
return this; | ||
} | ||
|
||
/** Sets an attribute. */ | ||
<T> LogRecordBuilder setAttribute(AttributeKey<T> key, T value); | ||
|
||
/** Emit the log to downstream {@link LogProcessor}(s). */ | ||
void emit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ReadWriteLogRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.logs; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.sdk.logs.data.LogData; | ||
|
||
/** A log record that can be read from and written to. */ | ||
public interface ReadWriteLogRecord { | ||
|
||
/** | ||
* Sets an attribute on the log record. If the log record previously contained a mapping for the | ||
* key, the old value is replaced by the specified value. | ||
* | ||
* <p>Note: the behavior of null values is undefined, and hence strongly discouraged. | ||
*/ | ||
<T> ReadWriteLogRecord setAttribute(AttributeKey<T> key, T value); | ||
|
||
// TODO: add additional setters | ||
|
||
/** Return an immutable {@link LogData} instance representing this log record. */ | ||
LogData toLogData(); | ||
|
||
// TODO: add additional log record accessors. Currently, all fields can be accessed indirectly via | ||
// #toLogData() with at the expense of additional allocations. | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.