-
-
Notifications
You must be signed in to change notification settings - Fork 38
Ref(V3): Add missing integrations / fix breadcrumbs and device context #1047
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aec9f8c
added integrations inboundFiltersIntegration, functionToStringIntegra…
lucas-zimerman 1e5215c
ios changes
lucas-zimerman 68f6a4c
updated tests with new changes
lucas-zimerman 4ea192a
changelog
lucas-zimerman 78f80bf
remove comments
lucas-zimerman 5e9289f
Update ios/Sources/SentryCapacitorPlugin/SentryCapacitorPlugin.swift
lucas-zimerman 2ee5b37
Update ios/Sources/SentryCapacitorPlugin/SentryCapacitorPlugin.swift
lucas-zimerman 68682cd
import breadcrumb tests from react native
lucas-zimerman dcd7e00
Update src/integrations/devicecontext.ts
lucas-zimerman b5b8461
update tests
lucas-zimerman 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
Some comments aren't visible on the classic Files Changed page.
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
140 changes: 140 additions & 0 deletions
140
android/src/main/java/io/sentry/capacitor/CapSentryMapConverter.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,140 @@ | ||
| package io.sentry.capacitor; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.BigInteger; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import com.getcapacitor.JSObject; | ||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
|
|
||
| import io.sentry.ILogger; | ||
| import io.sentry.SentryLevel; | ||
| import io.sentry.android.core.AndroidLogger; | ||
|
|
||
| public final class CapSentryMapConverter { | ||
| public static final String NAME = "CapSentry.MapConverter"; | ||
| private static final ILogger logger = new AndroidLogger(NAME); | ||
|
|
||
| private CapSentryMapConverter() { | ||
| throw new AssertionError("Utility class should not be instantiated"); | ||
| } | ||
|
|
||
| public static Object convertToWritable(Object serialized) { | ||
| if (serialized instanceof List) { | ||
| JSONArray writable = new JSONArray(); | ||
| for (Object item : (List<?>) serialized) { | ||
| addValueToWritableArray(writable, convertToWritable(item)); | ||
| } | ||
| return writable; | ||
| } else if (serialized instanceof Map) { | ||
| JSObject writable = new JSObject(); | ||
| for (Map.Entry<?, ?> entry : ((Map<?, ?>) serialized).entrySet()) { | ||
| Object key = entry.getKey(); | ||
| Object value = entry.getValue(); | ||
|
|
||
| if (key instanceof String) { | ||
| addValueToWritableMap(writable, (String) key, convertToWritable(value)); | ||
| } else { | ||
| logger.log(SentryLevel.ERROR, "Only String keys are supported in Map.", key); | ||
| } | ||
| } | ||
| return writable; | ||
| } else if (serialized instanceof Byte) { | ||
| return Integer.valueOf((Byte) serialized); | ||
| } else if (serialized instanceof Short) { | ||
| return Integer.valueOf((Short) serialized); | ||
| } else if (serialized instanceof Float) { | ||
| return Double.valueOf((Float) serialized); | ||
| } else if (serialized instanceof Long) { | ||
| return Double.valueOf((Long) serialized); | ||
| } else if (serialized instanceof BigInteger) { | ||
| return ((BigInteger) serialized).doubleValue(); | ||
| } else if (serialized instanceof BigDecimal) { | ||
| return ((BigDecimal) serialized).doubleValue(); | ||
| } else if (serialized instanceof Integer | ||
| || serialized instanceof Double | ||
| || serialized instanceof Boolean | ||
| || serialized == null | ||
| || serialized instanceof String) { | ||
| return serialized; | ||
| } else { | ||
| logger.log( | ||
| SentryLevel.ERROR, "Supplied serialized value could not be converted." + serialized); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static void addValueToWritableArray(JSONArray writableArray, Object value) { | ||
| try { | ||
| if (value == null) { | ||
| writableArray.put(JSONObject.NULL); | ||
| } else if (value instanceof Boolean) { | ||
| writableArray.put((Boolean) value); | ||
| } else if (value instanceof Double) { | ||
| writableArray.put((Double) value); | ||
| } else if (value instanceof Float) { | ||
| writableArray.put(((Float) value).doubleValue()); | ||
| } else if (value instanceof Integer) { | ||
| writableArray.put((Integer) value); | ||
| } else if (value instanceof Short) { | ||
| writableArray.put(((Short) value).intValue()); | ||
| } else if (value instanceof Byte) { | ||
| writableArray.put(((Byte) value).intValue()); | ||
| } else if (value instanceof Long) { | ||
| writableArray.put(((Long) value).doubleValue()); | ||
| } else if (value instanceof BigInteger) { | ||
| writableArray.put(((BigInteger) value).doubleValue()); | ||
| } else if (value instanceof BigDecimal) { | ||
| writableArray.put(((BigDecimal) value).doubleValue()); | ||
| } else if (value instanceof String) { | ||
| writableArray.put((String) value); | ||
| } else if (value instanceof JSObject || value instanceof JSONObject) { | ||
| writableArray.put(value instanceof JSObject ? (JSObject) value : (JSONObject) value); | ||
| } else if (value instanceof JSONArray) { | ||
| writableArray.put((JSONArray) value); | ||
| } else { | ||
| logger.log(SentryLevel.ERROR, "Could not convert object: " + value); | ||
| } | ||
| } catch (Exception e) { | ||
| logger.log(SentryLevel.ERROR, "Error adding value to array: " + e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| private static void addValueToWritableMap(JSObject writableMap, String key, Object value) { | ||
| try { | ||
| if (value == null) { | ||
| writableMap.put(key, JSONObject.NULL); | ||
| } else if (value instanceof Boolean) { | ||
| writableMap.put(key, (Boolean) value); | ||
| } else if (value instanceof Double) { | ||
| writableMap.put(key, (Double) value); | ||
| } else if (value instanceof Float) { | ||
| writableMap.put(key, ((Float) value).doubleValue()); | ||
| } else if (value instanceof Integer) { | ||
| writableMap.put(key, (Integer) value); | ||
| } else if (value instanceof Short) { | ||
| writableMap.put(key, ((Short) value).intValue()); | ||
| } else if (value instanceof Byte) { | ||
| writableMap.put(key, ((Byte) value).intValue()); | ||
| } else if (value instanceof Long) { | ||
| writableMap.put(key, ((Long) value).doubleValue()); | ||
| } else if (value instanceof BigInteger) { | ||
| writableMap.put(key, ((BigInteger) value).doubleValue()); | ||
| } else if (value instanceof BigDecimal) { | ||
| writableMap.put(key, ((BigDecimal) value).doubleValue()); | ||
| } else if (value instanceof String) { | ||
| writableMap.put(key, (String) value); | ||
| } else if (value instanceof JSONArray) { | ||
| writableMap.put(key, (JSONArray) value); | ||
| } else if (value instanceof JSObject || value instanceof JSONObject) { | ||
| writableMap.put(key, value instanceof JSObject ? (JSObject) value : (JSONObject) value); | ||
| } else { | ||
| logger.log(SentryLevel.ERROR, "Could not convert object: " + value); | ||
| } | ||
| } catch (Exception e) { | ||
| logger.log(SentryLevel.ERROR, "Error adding value to map: " + e.getMessage(), e); | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,3 +1,42 @@ | ||
| import type { SeverityLevel } from '@sentry/core'; | ||
| import type { Breadcrumb, SeverityLevel } from '@sentry/core'; | ||
| import { severityLevelFromString } from '@sentry/core'; | ||
|
|
||
| export const DEFAULT_BREADCRUMB_LEVEL: SeverityLevel = 'info'; | ||
|
|
||
| type BreadcrumbCandidate = { | ||
| [K in keyof Partial<Breadcrumb>]: unknown; | ||
| }; | ||
|
|
||
| /** | ||
| * Convert plain object to a valid Breadcrumb | ||
| */ | ||
| export function breadcrumbFromObject(candidate: BreadcrumbCandidate): Breadcrumb { | ||
antonis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const breadcrumb: Breadcrumb = {}; | ||
|
|
||
| if (typeof candidate.type === 'string') { | ||
| breadcrumb.type = candidate.type; | ||
| } | ||
| if (typeof candidate.level === 'string') { | ||
| breadcrumb.level = severityLevelFromString(candidate.level); | ||
| } | ||
| if (typeof candidate.event_id === 'string') { | ||
| breadcrumb.event_id = candidate.event_id; | ||
| } | ||
| if (typeof candidate.category === 'string') { | ||
| breadcrumb.category = candidate.category; | ||
| } | ||
| if (typeof candidate.message === 'string') { | ||
| breadcrumb.message = candidate.message; | ||
| } | ||
| if (typeof candidate.data === 'object' && candidate.data !== null) { | ||
| breadcrumb.data = candidate.data; | ||
| } | ||
| if (typeof candidate.timestamp === 'string') { | ||
| const timestampSeconds = Date.parse(candidate.timestamp) / 1000; // breadcrumb timestamp is in seconds | ||
| if (!isNaN(timestampSeconds)) { | ||
| breadcrumb.timestamp = timestampSeconds; | ||
| } | ||
| } | ||
|
|
||
| return breadcrumb; | ||
| } | ||
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.
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.
My understanding it that this is the same code as
RNSentryMapConverter. Correct?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.
correct, with only minor changes since we don't depend on React Native imports.