@@ -13,6 +13,7 @@ public final class Attachment {
1313 private @ Nullable String pathname ;
1414 private final @ NotNull String filename ;
1515 private final @ NotNull String contentType ;
16+ private final boolean addToTransactions ;
1617
1718 /**
1819 * We could use Files.probeContentType(path) to determine the content type of the filename. This
@@ -24,7 +25,8 @@ public final class Attachment {
2425 private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream" ;
2526
2627 /**
27- * Initializes an Attachment with bytes and a filename.
28+ * Initializes an Attachment with bytes and a filename. Sets addToTransaction to <code>false
29+ * </code>.
2830 *
2931 * @param bytes The bytes of file.
3032 * @param filename The name of the attachment to display in Sentry.
@@ -34,7 +36,8 @@ public Attachment(final @NotNull byte[] bytes, final @NotNull String filename) {
3436 }
3537
3638 /**
37- * Initializes an Attachment with bytes, filename and content type.
39+ * Initializes an Attachment with bytes, a filename, and a content type. Sets addToTransaction to
40+ * <code>false</code>.
3841 *
3942 * @param bytes The bytes of file.
4043 * @param filename The name of the attachment to display in Sentry.
@@ -44,13 +47,32 @@ public Attachment(
4447 final @ NotNull byte [] bytes ,
4548 final @ NotNull String filename ,
4649 final @ NotNull String contentType ) {
50+ this (bytes , filename , contentType , false );
51+ }
52+
53+ /**
54+ * Initializes an Attachment with bytes, a filename, a content type, and addToTransactions.
55+ *
56+ * @param bytes The bytes of file.
57+ * @param filename The name of the attachment to display in Sentry.
58+ * @param contentType The content type of the attachment.
59+ * @param addToTransactions <code>true</code> if the SDK should add this attachment to every
60+ * {@link ITransaction} or set to <code>false</code> if it shouldn't.
61+ */
62+ public Attachment (
63+ final @ NotNull byte [] bytes ,
64+ final @ NotNull String filename ,
65+ final @ NotNull String contentType ,
66+ final boolean addToTransactions ) {
4767 this .bytes = bytes ;
4868 this .filename = filename ;
4969 this .contentType = contentType ;
70+ this .addToTransactions = addToTransactions ;
5071 }
5172
5273 /**
5374 * Initializes an Attachment with a path. The filename of the file located at the path is used.
75+ * Sets addToTransaction to <code>false</code>.
5476 *
5577 * <p>The file located at the pathname is read lazily when the SDK captures an event or
5678 * transaction not when the attachment is initialized. The pathname string is converted into an
@@ -63,7 +85,8 @@ public Attachment(final @NotNull String pathname) {
6385 }
6486
6587 /**
66- * Initializes an Attachment with a path and a filename.
88+ * Initializes an Attachment with a path and a filename. Sets addToTransaction to <code>false
89+ * </code>.
6790 *
6891 * <p>The file located at the pathname is read lazily when the SDK captures an event or
6992 * transaction not when the attachment is initialized. The pathname string is converted into an
@@ -77,7 +100,8 @@ public Attachment(final @NotNull String pathname, final @NotNull String filename
77100 }
78101
79102 /**
80- * Initializes an Attachment with a path, a filename and a content type.
103+ * Initializes an Attachment with a path, a filename, and a content type. Sets addToTransaction to
104+ * <code>false</code>.
81105 *
82106 * <p>The file located at the pathname is read lazily when the SDK captures an event or
83107 * transaction not when the attachment is initialized. The pathname string is converted into an
@@ -91,9 +115,31 @@ public Attachment(
91115 final @ NotNull String pathname ,
92116 final @ NotNull String filename ,
93117 final @ NotNull String contentType ) {
118+ this (pathname , filename , contentType , false );
119+ }
120+
121+ /**
122+ * Initializes an Attachment with a path, a filename, a content type, and addToTransactions.
123+ *
124+ * <p>The file located at the pathname is read lazily when the SDK captures an event or
125+ * transaction not when the attachment is initialized. The pathname string is converted into an
126+ * abstract pathname before reading the file.
127+ *
128+ * @param pathname The pathname string of the file to upload as an attachment.
129+ * @param filename The name of the attachment to display in Sentry.
130+ * @param contentType The content type of the attachment.
131+ * @param addToTransactions <code>true</code> if the SDK should add this attachment to every
132+ * {@link ITransaction} or set to <code>false</code> if it shouldn't.
133+ */
134+ public Attachment (
135+ final @ NotNull String pathname ,
136+ final @ NotNull String filename ,
137+ final @ NotNull String contentType ,
138+ final boolean addToTransactions ) {
94139 this .pathname = pathname ;
95140 this .filename = filename ;
96141 this .contentType = contentType ;
142+ this .addToTransactions = addToTransactions ;
97143 }
98144
99145 /**
@@ -131,4 +177,14 @@ public Attachment(
131177 public @ NotNull String getContentType () {
132178 return contentType ;
133179 }
180+
181+ /**
182+ * Returns <code>true</code> if the SDK should add this attachment to every {@link ITransaction}
183+ * and <code>false</code> if it shouldn't. Default is <code>false</code>.
184+ *
185+ * @return <code>true</code> if attachment should be added to every {@link ITransaction}.
186+ */
187+ boolean isAddToTransactions () {
188+ return addToTransactions ;
189+ }
134190}
0 commit comments