Skip to content

Commit 3c834cf

Browse files
committed
Sync scope attributes to native
1 parent 06cc302 commit 3c834cf

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

packages/core/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,25 @@ public void setTag(String key, String value) {
933933
});
934934
}
935935

936+
public void setAttribute(String key, String value) {
937+
Sentry.configureScope(
938+
scope -> {
939+
scope.setAttribute(key, value);
940+
});
941+
}
942+
943+
public void setAttributes(ReadableMap attributes) {
944+
Sentry.configureScope(
945+
scope -> {
946+
final ReadableMapKeySetIterator iterator = attributes.keySetIterator();
947+
while (iterator.hasNextKey()) {
948+
final String key = iterator.nextKey();
949+
final String value = attributes.getString(key);
950+
scope.setAttribute(key, value);
951+
}
952+
});
953+
}
954+
936955
public void closeNativeSdk(Promise promise) {
937956
Sentry.close();
938957

packages/core/android/src/newarch/java/io/sentry/react/RNSentryModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ public void setTag(String key, String value) {
112112
this.impl.setTag(key, value);
113113
}
114114

115+
@Override
116+
public void setAttribute(String key, String value) {
117+
this.impl.setAttribute(key, value);
118+
}
119+
120+
@Override
121+
public void setAttributes(ReadableMap attributes) {
122+
this.impl.setAttributes(attributes);
123+
}
124+
115125
@Override
116126
public void closeNativeSdk(Promise promise) {
117127
this.impl.closeNativeSdk(promise);

packages/core/android/src/oldarch/java/io/sentry/react/RNSentryModule.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ public void setTag(String key, String value) {
112112
this.impl.setTag(key, value);
113113
}
114114

115+
@ReactMethod
116+
public void setAttribute(String key, String value) {
117+
this.impl.setAttribute(key, value);
118+
}
119+
120+
@ReactMethod
121+
public void setAttributes(ReadableMap attributes) {
122+
this.impl.setAttributes(attributes);
123+
}
124+
115125
@ReactMethod
116126
public void closeNativeSdk(Promise promise) {
117127
this.impl.closeNativeSdk(promise);
@@ -132,6 +142,11 @@ public void fetchNativeDeviceContexts(Promise promise) {
132142
this.impl.fetchNativeDeviceContexts(promise);
133143
}
134144

145+
@ReactMethod
146+
public void fetchNativeLogAttributes(Promise promise) {
147+
this.impl.fetchNativeLogAttributes(promise);
148+
}
149+
135150
@ReactMethod
136151
public void fetchNativeSdkInfo(Promise promise) {
137152
this.impl.fetchNativeSdkInfo(promise);

packages/core/ios/RNSentry.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,20 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
723723
configureScope:^(SentryScope *_Nonnull scope) { [scope setTagValue:value forKey:key]; }];
724724
}
725725

726+
RCT_EXPORT_METHOD(setAttribute : (NSString *)key value : (NSString *)value)
727+
{
728+
[SentrySDKWrapper
729+
configureScope:^(SentryScope *_Nonnull scope) { [scope setAttribute:value forKey:key]; }];
730+
}
731+
732+
RCT_EXPORT_METHOD(setAttributes : (NSDictionary *)attributes)
733+
{
734+
[SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) {
735+
[attributes enumerateKeysAndObjectsUsingBlock:^(
736+
NSString *key, NSString *value, BOOL *stop) { [scope setAttribute:value forKey:key]; }];
737+
}];
738+
}
739+
726740
RCT_EXPORT_METHOD(crash) { [SentrySDKWrapper crash]; }
727741

728742
RCT_EXPORT_METHOD(

0 commit comments

Comments
 (0)