-
Notifications
You must be signed in to change notification settings - Fork 900
Add addAllAttributes() to ReadWriteLogRecord. #5825
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
Merged
jack-berg
merged 5 commits into
open-telemetry:main
from
breedx-splk:add_all_attributes_logs
Sep 26, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
63c20dd
add addAllAttributes() to ReadWriteLogRecord.
breedx-splk 0329dd1
add missing javadoc
breedx-splk d8c317b
generate api comparison artifact
breedx-splk 82d3d14
add todo back
breedx-splk b59ed95
add coverage for null and empty
breedx-splk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.