|
1 | 1 | package io.sentry.android.ndk; |
2 | 2 |
|
| 3 | +import io.sentry.Attachment; |
3 | 4 | import io.sentry.Breadcrumb; |
4 | 5 | import io.sentry.DateUtils; |
5 | 6 | import io.sentry.IScope; |
@@ -145,4 +146,41 @@ public void setTrace(@Nullable SpanContext spanContext, @NotNull IScope scope) { |
145 | 146 | options.getLogger().log(SentryLevel.ERROR, e, "Scope sync setTrace failed."); |
146 | 147 | } |
147 | 148 | } |
| 149 | + |
| 150 | + @Override |
| 151 | + public void addAttachment(final @NotNull Attachment attachment) { |
| 152 | + final String pathname = attachment.getPathname(); |
| 153 | + if (pathname != null) { |
| 154 | + try { |
| 155 | + options.getExecutorService().submit(() -> nativeScope.addAttachment(pathname)); |
| 156 | + } catch (Throwable e) { |
| 157 | + options.getLogger().log(SentryLevel.ERROR, e, "Scope sync addAttachment has an error."); |
| 158 | + } |
| 159 | + return; |
| 160 | + } |
| 161 | + |
| 162 | + final byte[] bytes = attachment.getBytes(); |
| 163 | + if (bytes != null) { |
| 164 | + final String filename = attachment.getFilename(); |
| 165 | + try { |
| 166 | + options.getExecutorService().submit(() -> nativeScope.addAttachmentBytes(bytes, filename)); |
| 167 | + } catch (Throwable e) { |
| 168 | + options.getLogger().log(SentryLevel.ERROR, e, "Scope sync addAttachment has an error."); |
| 169 | + } |
| 170 | + return; |
| 171 | + } |
| 172 | + |
| 173 | + options |
| 174 | + .getLogger() |
| 175 | + .log(SentryLevel.DEBUG, "Scope sync addAttachment skips attachment without path or bytes."); |
| 176 | + } |
| 177 | + |
| 178 | + @Override |
| 179 | + public void clearAttachments() { |
| 180 | + try { |
| 181 | + options.getExecutorService().submit(() -> nativeScope.clearAttachments()); |
| 182 | + } catch (Throwable e) { |
| 183 | + options.getLogger().log(SentryLevel.ERROR, e, "Scope sync clearAttachments has an error."); |
| 184 | + } |
| 185 | + } |
148 | 186 | } |
0 commit comments