Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

fix: breacrumb.data to string,object, Add LOG level #264

Merged
merged 7 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public void log(SentryLevel level, Throwable throwable, String message, Object..
public void log(SentryLevel level, String message, Throwable throwable) {

switch (level) {
case DEBUG:
Log.d(tag, message, throwable);
break;
case INFO:
Log.i(tag, message, throwable);
break;
Expand All @@ -39,39 +36,26 @@ public void log(SentryLevel level, String message, Throwable throwable) {
case FATAL:
Log.wtf(tag, message, throwable);
break;
}
}

SentryLevel toSentryLevel(int logcatLevel) {
switch (logcatLevel) {
case Log.VERBOSE:
case Log.DEBUG:
return SentryLevel.DEBUG;
case Log.INFO:
return SentryLevel.INFO;
case Log.WARN:
return SentryLevel.WARNING;
case Log.ERROR:
return SentryLevel.ERROR;
case Log.ASSERT:
case LOG:
case DEBUG:
default:
return SentryLevel.FATAL;
Log.d(tag, message, throwable);
break;
}
}

private int toLogcatLevel(SentryLevel sentryLevel) {
switch (sentryLevel) {
case DEBUG:
return Log.DEBUG;
case INFO:
return Log.INFO;
case WARNING:
return Log.WARN;
case FATAL:
return Log.ASSERT;
case ERROR:
case LOG:
case DEBUG:
default:
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
return Log.ERROR;
return Log.DEBUG;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ class AndroidSerializerTest {
assertEquals(SentryLevel.DEBUG, actual.level)
}

@Test
fun `when deserializing a event with breadcrumbs containing data, it should become have breadcrumbs`() {
val jsonEvent = FileFromResources.invoke("event_breadcrumb_data.json")

val actual = serializer.deserializeEvent(StringReader(jsonEvent))

assertEquals(2, actual.breadcrumbs.size)
}

@Test
fun `when theres a null value, gson wont blow up`() {
val json = FileFromResources.invoke("event.json")
Expand Down
65 changes: 65 additions & 0 deletions sentry-android-core/src/test/resources/event_breadcrumb_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"message": {
"message": "test"
},
"level": "info",
"event_id": "286eecc053ea4c05879273226b51764c",
"platform": "node",
"sdk": {
"name": "sentry.javascript.react-native",
"packages": [
{
"name": "npm:@sentry/react-native",
"version": "1.2.2"
}
],
"version": "1.2.2",
"integrations": [
"ReactNativeErrorHandlers",
"Release",
"InboundFilters",
"FunctionToString",
"LinkedErrors",
"UserAgent",
"Breadcrumbs",
"DebugSymbolicator",
"RewriteFrames",
"DeviceContext"
]
},
"tags": {
"hermes": "true"
},
"breadcrumbs": [
{
"timestamp": 1581420865.987,
"category": "console",
"data": {
"arguments": [
"console .log test"
],
"logger": "console"
},
"level": "log",
"message": "console .log test"
},
{
"timestamp": 1581420866.014,
"category": "console",
"data": {
"arguments": [
"Running \"hermes\" with {\"rootTag\":1}"
],
"logger": "console"
},
"level": "log",
"message": "Running \"hermes\" with {\"rootTag\":1}"
}
],
"release": "com.hermes@1.0+1",
"dist": "1",
"extra": {
"componentStack": "[undefined]",
"jsEngine": "[undefined]"
}
}
12 changes: 6 additions & 6 deletions sentry-core/src/main/java/io/sentry/core/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class Breadcrumb implements Cloneable, IUnknownPropertiesConsumer {
private @Nullable String type;

/** Data associated with this breadcrumb. */
private @NotNull Map<String, String> data = new ConcurrentHashMap<>();
private @NotNull Map<String, Object> data = new ConcurrentHashMap<>();

/** Dotted strings that indicate what the crumb is or where it comes from. */
private @Nullable String category;
Expand Down Expand Up @@ -109,7 +109,7 @@ public void setType(@Nullable String type) {
* @return the data map
*/
@NotNull
Map<String, String> getData() {
Map<String, Object> getData() {
return data;
}

Expand All @@ -119,7 +119,7 @@ Map<String, String> getData() {
* @param key the key
* @param value the value
*/
public void setData(@NotNull String key, @NotNull String value) {
public void setData(@NotNull String key, @NotNull Object value) {
data.put(key, value);
}

Expand Down Expand Up @@ -200,11 +200,11 @@ Map<String, Object> getUnknown() {
public @NotNull Breadcrumb clone() throws CloneNotSupportedException {
final Breadcrumb clone = (Breadcrumb) super.clone();

final Map<String, String> dataRef = data;
final Map<String, Object> dataRef = data;
if (dataRef != null) {
final Map<String, String> dataClone = new ConcurrentHashMap<>();
final Map<String, Object> dataClone = new ConcurrentHashMap<>();

for (Map.Entry<String, String> item : dataRef.entrySet()) {
for (Map.Entry<String, Object> item : dataRef.entrySet()) {
if (item != null) {
dataClone.put(item.getKey(), item.getValue()); // shallow copy
}
Expand Down
2 changes: 2 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/SentryLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/** the SentryLevel */
public enum SentryLevel {
/** LOG is used as a level in breadcrumbs from console.log in JS */
LOG,
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
DEBUG,
INFO,
WARNING,
Expand Down