-
-
Notifications
You must be signed in to change notification settings - Fork 452
Improve Log Attributes API #4416
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
adinauer
merged 3 commits into
feat/logs-attributes-in-api
from
feat/better-attributes-api
May 22, 2025
+310
−60
Merged
Changes from all commits
Commits
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
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,57 @@ | ||
package io.sentry; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class SentryAttribute { | ||
|
||
private final @NotNull String name; | ||
private final @Nullable SentryAttributeType type; | ||
private final @Nullable Object value; | ||
|
||
private SentryAttribute( | ||
final @NotNull String name, | ||
final @Nullable SentryAttributeType type, | ||
final @Nullable Object value) { | ||
this.name = name; | ||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
public @NotNull String getName() { | ||
return name; | ||
} | ||
|
||
public @Nullable SentryAttributeType getType() { | ||
return type; | ||
} | ||
|
||
public @Nullable Object getValue() { | ||
return value; | ||
} | ||
|
||
public static @NotNull SentryAttribute named( | ||
final @NotNull String name, final @Nullable Object value) { | ||
return new SentryAttribute(name, null, value); | ||
} | ||
|
||
public static @NotNull SentryAttribute booleanAttribute( | ||
lcian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final @NotNull String name, final @Nullable Boolean value) { | ||
return new SentryAttribute(name, SentryAttributeType.BOOLEAN, value); | ||
} | ||
|
||
public static @NotNull SentryAttribute integerAttribute( | ||
final @NotNull String name, final @Nullable Integer value) { | ||
return new SentryAttribute(name, SentryAttributeType.INTEGER, value); | ||
} | ||
|
||
public static @NotNull SentryAttribute doubleAttribute( | ||
final @NotNull String name, final @Nullable Double value) { | ||
return new SentryAttribute(name, SentryAttributeType.DOUBLE, value); | ||
} | ||
|
||
public static @NotNull SentryAttribute stringAttribute( | ||
final @NotNull String name, final @Nullable String value) { | ||
return new SentryAttribute(name, SentryAttributeType.STRING, value); | ||
} | ||
} |
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,15 @@ | ||
package io.sentry; | ||
|
||
import java.util.Locale; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public enum SentryAttributeType { | ||
STRING, | ||
BOOLEAN, | ||
INTEGER, | ||
DOUBLE; | ||
|
||
public @NotNull String apiName() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
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,54 @@ | ||
package io.sentry; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class SentryAttributes { | ||
|
||
private final @NotNull Map<String, SentryAttribute> attributes; | ||
|
||
private SentryAttributes(final @NotNull Map<String, SentryAttribute> attributes) { | ||
this.attributes = attributes; | ||
} | ||
|
||
public void add(final @Nullable SentryAttribute attribute) { | ||
if (attribute == null) { | ||
return; | ||
} | ||
attributes.put(attribute.getName(), attribute); | ||
} | ||
|
||
public @NotNull Map<String, SentryAttribute> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
public static @NotNull SentryAttributes of(final @Nullable SentryAttribute... attributes) { | ||
if (attributes == null) { | ||
return new SentryAttributes(new ConcurrentHashMap<>()); | ||
} | ||
final @NotNull SentryAttributes sentryAttributes = | ||
new SentryAttributes(new ConcurrentHashMap<>(attributes.length)); | ||
for (SentryAttribute attribute : attributes) { | ||
sentryAttributes.add(attribute); | ||
} | ||
lcian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return sentryAttributes; | ||
} | ||
|
||
public static @NotNull SentryAttributes fromMap(final @Nullable Map<String, Object> attributes) { | ||
if (attributes == null) { | ||
return new SentryAttributes(new ConcurrentHashMap<>()); | ||
} | ||
final @NotNull SentryAttributes sentryAttributes = | ||
new SentryAttributes(new ConcurrentHashMap<>(attributes.size())); | ||
for (Map.Entry<String, Object> attribute : attributes.entrySet()) { | ||
final @Nullable String key = attribute.getKey(); | ||
if (key != null) { | ||
sentryAttributes.add(SentryAttribute.named(key, attribute.getValue())); | ||
} | ||
} | ||
|
||
return sentryAttributes; | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.