-
-
Notifications
You must be signed in to change notification settings - Fork 454
Extend Logs API to allow passing in attributes
#4402
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
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ca032d
Extend Logs API to allow passing in attributes
adinauer 4df31f7
update (#4409)
lcian 2aa5b77
Improve Log Attributes API (#4416)
adinauer fa3b562
Merge branch 'main' into feat/logs-attributes-in-api
adinauer f8dab89
changelog
adinauer 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
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import io.sentry.util.Platform; | ||
import io.sentry.util.TracingUtils; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
@@ -65,7 +66,7 @@ public void log( | |
final @NotNull SentryLogLevel level, | ||
final @Nullable String message, | ||
final @Nullable Object... args) { | ||
log(level, null, message, args); | ||
captureLog(null, level, null, message, args); | ||
} | ||
|
||
@Override | ||
|
@@ -74,11 +75,31 @@ public void log( | |
final @Nullable SentryDate timestamp, | ||
final @Nullable String message, | ||
final @Nullable Object... args) { | ||
captureLog(level, timestamp, message, args); | ||
captureLog(null, level, timestamp, message, args); | ||
} | ||
|
||
@Override | ||
public void log( | ||
final @Nullable Map<String, Object> attributes, | ||
final @NotNull SentryLogLevel level, | ||
final @Nullable SentryDate timestamp, | ||
final @Nullable String message, | ||
final @Nullable Object... args) { | ||
captureLog(attributes, level, timestamp, message, args); | ||
} | ||
|
||
@Override | ||
public void log( | ||
final @Nullable Map<String, Object> attributes, | ||
final @NotNull SentryLogLevel level, | ||
final @Nullable String message, | ||
final @Nullable Object... args) { | ||
captureLog(attributes, level, null, message, args); | ||
} | ||
|
||
@SuppressWarnings("AnnotateFormatMethod") | ||
private void captureLog( | ||
final @Nullable Map<String, Object> attributes, | ||
final @NotNull SentryLogLevel level, | ||
final @Nullable SentryDate timestamp, | ||
final @Nullable String message, | ||
|
@@ -119,7 +140,7 @@ private void captureLog( | |
span == null ? propagationContext.getSpanId() : span.getSpanContext().getSpanId(); | ||
final SentryLogEvent logEvent = | ||
new SentryLogEvent(traceId, timestampToUse, messageToUse, level); | ||
logEvent.setAttributes(createAttributes(message, spanId, args)); | ||
logEvent.setAttributes(createAttributes(attributes, message, spanId, args)); | ||
logEvent.setSeverityNumber(level.getSeverityNumber()); | ||
|
||
scopes.getClient().captureLog(logEvent, combinedScope); | ||
|
@@ -146,8 +167,20 @@ private void captureLog( | |
} | ||
|
||
private @NotNull HashMap<String, SentryLogEventAttributeValue> createAttributes( | ||
final @NotNull String message, final @NotNull SpanId spanId, final @Nullable Object... args) { | ||
final @Nullable Map<String, Object> incomingAttributes, | ||
final @NotNull String message, | ||
final @NotNull SpanId spanId, | ||
final @Nullable Object... args) { | ||
final @NotNull HashMap<String, SentryLogEventAttributeValue> attributes = new HashMap<>(); | ||
|
||
if (incomingAttributes != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we create a copy of the attributes (here or in the capture method) to avoid having a map that could be changed while we iterate on it? |
||
for (Map.Entry<String, Object> attributeEntry : incomingAttributes.entrySet()) { | ||
final @Nullable Object value = attributeEntry.getValue(); | ||
final @NotNull String type = getType(value); | ||
attributes.put(attributeEntry.getKey(), new SentryLogEventAttributeValue(type, value)); | ||
} | ||
} | ||
|
||
if (args != null) { | ||
int i = 0; | ||
for (Object arg : args) { | ||
|
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like it too much that it's the first param but I guess it must be like this because of the varargs right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like it more for this to be the last param but I don't think that's possible. Either way it's fine, I would expect most users to not go through this API