-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add addAllAttributes() to ReadWriteLogRecord. (#5825)
- Loading branch information
1 parent
0f6b894
commit 3f47934
Showing
4 changed files
with
109 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Comparing source compatibility of against | ||
No changes. | ||
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.logs.ReadWriteLogRecord (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.logs.ReadWriteLogRecord setAllAttributes(io.opentelemetry.api.common.Attributes) |
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
73 changes: 73 additions & 0 deletions
73
sdk/logs/src/test/java/io/opentelemetry/sdk/logs/ReadWriteLogRecordTest.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,73 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.logs; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.logs.Severity; | ||
import io.opentelemetry.api.trace.SpanContext; | ||
import io.opentelemetry.sdk.common.InstrumentationScopeInfo; | ||
import io.opentelemetry.sdk.internal.AttributesMap; | ||
import io.opentelemetry.sdk.logs.data.Body; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ReadWriteLogRecordTest { | ||
|
||
@Test | ||
void addAllAttributes() { | ||
Attributes newAttributes = Attributes.of(stringKey("foo"), "bar", stringKey("bar"), "buzz"); | ||
SdkReadWriteLogRecord logRecord = buildLogRecord(); | ||
|
||
logRecord.setAllAttributes(newAttributes); | ||
|
||
Attributes result = logRecord.toLogRecordData().getAttributes(); | ||
assertThat(result.get(stringKey("foo"))).isEqualTo("bar"); | ||
assertThat(result.get(stringKey("bar"))).isEqualTo("buzz"); | ||
assertThat(result.get(stringKey("untouched"))).isEqualTo("yes"); | ||
} | ||
|
||
@Test | ||
void addAllHandlesNull() { | ||
SdkReadWriteLogRecord logRecord = buildLogRecord(); | ||
Attributes originalAttributes = logRecord.toLogRecordData().getAttributes(); | ||
ReadWriteLogRecord result = logRecord.setAllAttributes(null); | ||
assertThat(result.toLogRecordData().getAttributes()).isEqualTo(originalAttributes); | ||
} | ||
|
||
@Test | ||
void allHandlesEmpty() { | ||
SdkReadWriteLogRecord logRecord = buildLogRecord(); | ||
Attributes originalAttributes = logRecord.toLogRecordData().getAttributes(); | ||
ReadWriteLogRecord result = logRecord.setAllAttributes(Attributes.empty()); | ||
assertThat(result.toLogRecordData().getAttributes()).isEqualTo(originalAttributes); | ||
} | ||
|
||
SdkReadWriteLogRecord buildLogRecord() { | ||
Body body = Body.string("bod"); | ||
AttributesMap initialAttributes = AttributesMap.create(100, 200); | ||
initialAttributes.put(stringKey("foo"), "aaiosjfjioasdiojfjioasojifja"); | ||
initialAttributes.put(stringKey("untouched"), "yes"); | ||
LogLimits limits = LogLimits.getDefault(); | ||
Resource resource = Resource.empty(); | ||
InstrumentationScopeInfo scope = InstrumentationScopeInfo.create("test"); | ||
SpanContext spanContext = SpanContext.getInvalid(); | ||
|
||
return SdkReadWriteLogRecord.create( | ||
limits, | ||
resource, | ||
scope, | ||
0L, | ||
0L, | ||
spanContext, | ||
Severity.DEBUG, | ||
"buggin", | ||
body, | ||
initialAttributes); | ||
} | ||
} |
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