Skip to content

Commit 8b22679

Browse files
Mention Cordova SDK name on Native errors (#378)
* finish implementation of iOS * add changelog * Update src/ios/SentryCordova.m * Added sdk names for Android/iOS. iOS still in WIP
1 parent b6c99c2 commit 8b22679

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Fixes
1010

11+
- Set custom SDK names on events to indicate where it was captured ([#378](https://github.com/getsentry/sentry-cordova/pull/378))
1112
- Use a minified and optimized bundle to reduce the SDK size by three times, improving performance and reducing load times ([#371](https://github.com/getsentry/sentry-cordova/pull/371))
1213

1314
### Dependencies

src/android/io/sentry/SentryCordova.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
public class SentryCordova extends CordovaPlugin {
3838
private static final String TAG = "Sentry";
3939

40+
private static final String NATIVE_SDK_NAME = "sentry.native.android.cordova";
41+
private static final String ANDROID_SDK_NAME = "sentry.java.android.cordova";
42+
4043
final static Logger logger = Logger.getLogger("sentry-cordova");
4144

4245
private SentryOptions sentryOptions;
@@ -165,6 +168,13 @@ private void startWithOptions(final JSONObject jsonOptions, final CallbackContex
165168
logger.info(String.format("Starting with DSN: '%s'", dsn));
166169
options.setDsn(dsn);
167170

171+
SdkVersion sdkVersion = options.getSdkVersion();
172+
if (sdkVersion == null) {
173+
sdkVersion = new SdkVersion(ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
174+
} else {
175+
sdkVersion.setName(ANDROID_SDK_NAME);
176+
}
177+
168178
boolean debug = jsonOptions.optBoolean("debug", false);
169179
options.setDebug(debug);
170180

@@ -211,6 +221,8 @@ private void startWithOptions(final JSONObject jsonOptions, final CallbackContex
211221
return event;
212222
});
213223

224+
options.setNativeSdkName(NATIVE_SDK_NAME);
225+
214226
sentryOptions = options;
215227
} catch (JSONException e) {
216228
logger.severe("Error parsing options JSON sent over native bridge.");
@@ -422,20 +434,20 @@ private void setEventOriginTag(SentryEvent event) {
422434
if (sdk != null) {
423435
switch (sdk.getName()) {
424436
// If the event is from cordova js, it gets set there and we do not handle it here.
425-
case "sentry.native":
426-
setEventEnvironmentTag(event, "android", "native");
437+
case NATIVE_SDK_NAME:
438+
setEventEnvironmentTag(event, "native");
427439
break;
428-
case "sentry.java.android":
429-
setEventEnvironmentTag(event, "android", "java");
440+
case ANDROID_SDK_NAME:
441+
setEventEnvironmentTag(event, "java");
430442
break;
431443
default:
432444
break;
433445
}
434446
}
435447
}
436448

437-
private void setEventEnvironmentTag(SentryEvent event, String origin, String environment) {
438-
event.setTag("event.origin", origin);
449+
private void setEventEnvironmentTag(SentryEvent event, String environment) {
450+
event.setTag("event.origin", "android");
439451
event.setTag("event.environment", environment);
440452
}
441453

src/ios/SentryCordova.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ @implementation SentryCordova {
99
bool sentHybridSdkDidBecomeActive;
1010
}
1111

12+
NSString * const nativeSdkName = @"sentry.cocoa.cordova";
13+
1214
- (void)pluginInitialize {
1315
NSLog(@"Sentry Cordova Plugin initialized");
1416
}
1517

1618
- (void)startWithOptions:(CDVInvokedUrlCommand *)command {
1719
NSDictionary *options = [command.arguments objectAtIndex:0];
1820

21+
NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString];
22+
[PrivateSentrySDKOnly setSdkName:nativeSdkName andVersionString:sdkVersion];
23+
1924
SentryBeforeSendEventCallback beforeSend =
2025
^SentryEvent *(SentryEvent *event) {
2126
[self setEventOriginTag:event];
@@ -119,20 +124,19 @@ - (void)setEventOriginTag:(SentryEvent *)event {
119124

120125
// If the event is from cordova js, it gets set there and we do not handle
121126
// it here.
122-
if ([sdkName isEqualToString:@"sentry.cocoa"]) {
123-
[self setEventEnvironmentTag:event origin:@"ios" environment:@"native"];
127+
if ([sdkName isEqualToString:nativeSdkName]) {
128+
[self setEventEnvironmentTag:event environment:@"native"];
124129
}
125130
}
126131
}
127132

128133
- (void)setEventEnvironmentTag:(SentryEvent *)event
129-
origin:(NSString *)origin
130134
environment:(NSString *)environment {
131135
NSMutableDictionary *newTags = [NSMutableDictionary new];
132136
if (nil != event.tags) {
133137
[newTags addEntriesFromDictionary:event.tags];
134138
}
135-
[newTags setValue:origin forKey:@"event.origin"];
139+
[newTags setValue:@"ios" forKey:@"event.origin"];
136140
[newTags setValue:environment forKey:@"event.environment"];
137141
event.tags = newTags;
138142
}

0 commit comments

Comments
 (0)