Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adds breadcrumb origin field
  • Loading branch information
antonis committed Sep 27, 2024
commit 71e9334af98251abcb807f61174cb5513c5abd69
42 changes: 41 additions & 1 deletion sentry/src/main/java/io/sentry/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public final class Breadcrumb implements JsonUnknown, JsonSerializable {
/** Dotted strings that indicate what the crumb is or where it comes from. */
private @Nullable String category;

/**
* Origin of the breadcrumb that is used to identify source of the breadcrumb. For example hybrid
* SDKs can identify native breadcrumbs from JS or Flutter.
*/
private @Nullable String origin;

/** The level of the event. */
private @Nullable SentryLevel level;

Expand All @@ -54,6 +60,7 @@ public Breadcrumb(final @NotNull Date timestamp) {
this.message = breadcrumb.message;
this.type = breadcrumb.type;
this.category = breadcrumb.category;
this.origin = breadcrumb.origin;
final Map<String, Object> dataClone = CollectionUtils.newConcurrentHashMap(breadcrumb.data);
if (dataClone != null) {
this.data = dataClone;
Expand All @@ -78,6 +85,7 @@ public static Breadcrumb fromMap(
String type = null;
@NotNull Map<String, Object> data = new ConcurrentHashMap<>();
String category = null;
String origin = null;
SentryLevel level = null;
Map<String, Object> unknown = null;

Expand Down Expand Up @@ -116,6 +124,9 @@ public static Breadcrumb fromMap(
case JsonKeys.CATEGORY:
category = (value instanceof String) ? (String) value : null;
break;
case JsonKeys.ORIGIN:
origin = (value instanceof String) ? (String) value : null;
break;
case JsonKeys.LEVEL:
String levelString = (value instanceof String) ? (String) value : null;
if (levelString != null) {
Expand All @@ -140,6 +151,7 @@ public static Breadcrumb fromMap(
breadcrumb.type = type;
breadcrumb.data = data;
breadcrumb.category = category;
breadcrumb.origin = origin;
breadcrumb.level = level;

breadcrumb.setUnknown(unknown);
Expand Down Expand Up @@ -610,6 +622,24 @@ public void setCategory(@Nullable String category) {
this.category = category;
}

/**
* Returns the origin
*
* @return the origin
*/
public @Nullable String getOrigin() {
return origin;
}

/**
* Sets the origin
*
* @param origin the origin
*/
public void setOrigin(@Nullable String origin) {
this.origin = origin;
}

/**
* Returns the SentryLevel
*
Expand Down Expand Up @@ -638,12 +668,13 @@ public boolean equals(Object o) {
&& Objects.equals(message, that.message)
&& Objects.equals(type, that.type)
&& Objects.equals(category, that.category)
&& Objects.equals(origin, that.origin)
&& level == that.level;
}

@Override
public int hashCode() {
return Objects.hash(timestamp, message, type, category, level);
return Objects.hash(timestamp, message, type, category, origin, level);
}

// region json
Expand All @@ -665,6 +696,7 @@ public static final class JsonKeys {
public static final String TYPE = "type";
public static final String DATA = "data";
public static final String CATEGORY = "category";
public static final String ORIGIN = "origin";
public static final String LEVEL = "level";
}

Expand All @@ -683,6 +715,9 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
if (category != null) {
writer.name(JsonKeys.CATEGORY).value(category);
}
if (origin != null) {
writer.name(JsonKeys.ORIGIN).value(origin);
}
if (level != null) {
writer.name(JsonKeys.LEVEL).value(logger, level);
}
Expand All @@ -707,6 +742,7 @@ public static final class Deserializer implements JsonDeserializer<Breadcrumb> {
String type = null;
@NotNull Map<String, Object> data = new ConcurrentHashMap<>();
String category = null;
String origin = null;
SentryLevel level = null;

Map<String, Object> unknown = null;
Expand Down Expand Up @@ -736,6 +772,9 @@ public static final class Deserializer implements JsonDeserializer<Breadcrumb> {
case JsonKeys.CATEGORY:
category = reader.nextStringOrNull();
break;
case JsonKeys.ORIGIN:
origin = reader.nextStringOrNull();
break;
case JsonKeys.LEVEL:
try {
level = new SentryLevel.Deserializer().deserialize(reader, logger);
Expand All @@ -757,6 +796,7 @@ public static final class Deserializer implements JsonDeserializer<Breadcrumb> {
breadcrumb.type = type;
breadcrumb.data = data;
breadcrumb.category = category;
breadcrumb.origin = origin;
breadcrumb.level = level;

breadcrumb.setUnknown(unknown);
Expand Down