@@ -55,6 +55,7 @@ public final class ExternalOptions {
5555
5656 private @ Nullable Boolean sendModules ;
5757 private @ Nullable Boolean sendDefaultPii ;
58+ private @ Nullable DataCollection dataCollection ;
5859 private @ Nullable Boolean enableBackpressureHandling ;
5960 private @ Nullable Boolean enableDatabaseTransactionTracing ;
6061 private @ Nullable Boolean enableCacheTracing ;
@@ -157,6 +158,7 @@ public final class ExternalOptions {
157158
158159 options .setSendModules (propertiesProvider .getBooleanProperty ("send-modules" ));
159160 options .setSendDefaultPii (propertiesProvider .getBooleanProperty ("send-default-pii" ));
161+ options .setDataCollection (parseDataCollection (propertiesProvider ));
160162
161163 options .setIgnoredCheckIns (propertiesProvider .getListOrNull ("ignored-checkins" ));
162164 options .setIgnoredTransactions (propertiesProvider .getListOrNull ("ignored-transactions" ));
@@ -246,6 +248,101 @@ public final class ExternalOptions {
246248 return options ;
247249 }
248250
251+ private static @ Nullable DataCollection parseDataCollection (
252+ final @ NotNull PropertiesProvider propertiesProvider ) {
253+ final DataCollection dataCollection = new DataCollection (false );
254+
255+ final Boolean userInfo = propertiesProvider .getBooleanProperty ("data-collection.user-info" );
256+ if (userInfo != null ) {
257+ dataCollection .setUserInfo (userInfo );
258+ }
259+
260+ final Set <HttpBodyType > httpBodies = parseHttpBodies (propertiesProvider );
261+ if (httpBodies != null ) {
262+ dataCollection .setHttpBodies (httpBodies );
263+ }
264+
265+ final KeyValueCollectionBehavior cookies =
266+ parseKeyValueCollectionBehavior (propertiesProvider , "data-collection.cookies" );
267+ if (cookies != null ) {
268+ dataCollection .setCookies (cookies );
269+ }
270+
271+ final KeyValueCollectionBehavior requestHeaders =
272+ parseKeyValueCollectionBehavior (propertiesProvider , "data-collection.http-headers.request" );
273+ if (requestHeaders != null ) {
274+ dataCollection .getHttpHeaders ().setRequest (requestHeaders );
275+ }
276+
277+ final KeyValueCollectionBehavior responseHeaders =
278+ parseKeyValueCollectionBehavior (
279+ propertiesProvider , "data-collection.http-headers.response" );
280+ if (responseHeaders != null ) {
281+ dataCollection .getHttpHeaders ().setResponse (responseHeaders );
282+ }
283+
284+ final KeyValueCollectionBehavior queryParams =
285+ parseKeyValueCollectionBehavior (propertiesProvider , "data-collection.url-query-params" );
286+ if (queryParams != null ) {
287+ dataCollection .setUrlQueryParams (queryParams );
288+ }
289+
290+ final Boolean graphqlDocument =
291+ propertiesProvider .getBooleanProperty ("data-collection.graphql.document" );
292+ if (graphqlDocument != null ) {
293+ dataCollection .getGraphql ().setDocument (graphqlDocument );
294+ }
295+
296+ final Boolean graphqlVariables =
297+ propertiesProvider .getBooleanProperty ("data-collection.graphql.variables" );
298+ if (graphqlVariables != null ) {
299+ dataCollection .getGraphql ().setVariables (graphqlVariables );
300+ }
301+
302+ final Boolean databaseQueryData =
303+ propertiesProvider .getBooleanProperty ("data-collection.database-query-data" );
304+ if (databaseQueryData != null ) {
305+ dataCollection .setDatabaseQueryData (databaseQueryData );
306+ }
307+
308+ return dataCollection .isExplicitlyConfigured () ? dataCollection : null ;
309+ }
310+
311+ private static @ Nullable Set <HttpBodyType > parseHttpBodies (
312+ final @ NotNull PropertiesProvider propertiesProvider ) {
313+ final List <String > bodyTypes = propertiesProvider .getListOrNull ("data-collection.http-bodies" );
314+ if (bodyTypes == null ) {
315+ return null ;
316+ }
317+ if (bodyTypes .size () == 1 && bodyTypes .get (0 ).isEmpty ()) {
318+ return Collections .emptySet ();
319+ }
320+
321+ final Set <HttpBodyType > httpBodies = EnumSet .noneOf (HttpBodyType .class );
322+ for (final String bodyType : bodyTypes ) {
323+ httpBodies .add (HttpBodyType .valueOf (bodyType .toUpperCase (Locale .ROOT )));
324+ }
325+ return httpBodies ;
326+ }
327+
328+ private static @ Nullable KeyValueCollectionBehavior parseKeyValueCollectionBehavior (
329+ final @ NotNull PropertiesProvider propertiesProvider , final @ NotNull String property ) {
330+ final String modeValue = propertiesProvider .getProperty (property + ".mode" );
331+ final List <String > terms = propertiesProvider .getListOrNull (property + ".terms" );
332+ if (modeValue == null && terms == null ) {
333+ return null ;
334+ }
335+
336+ final KeyValueCollectionBehavior behavior = new KeyValueCollectionBehavior ();
337+ if (modeValue != null ) {
338+ behavior .setMode (KeyValueCollectionBehavior .Mode .valueOf (modeValue .toUpperCase (Locale .ROOT )));
339+ }
340+ if (terms != null ) {
341+ behavior .setTerms (terms );
342+ }
343+ return behavior ;
344+ }
345+
249346 public @ Nullable String getDsn () {
250347 return dsn ;
251348 }
@@ -501,6 +598,14 @@ public void setSendDefaultPii(final @Nullable Boolean sendDefaultPii) {
501598 this .sendDefaultPii = sendDefaultPii ;
502599 }
503600
601+ public @ Nullable DataCollection getDataCollection () {
602+ return dataCollection ;
603+ }
604+
605+ public void setDataCollection (final @ Nullable DataCollection dataCollection ) {
606+ this .dataCollection = dataCollection ;
607+ }
608+
504609 public void setIgnoredCheckIns (final @ Nullable List <String > ignoredCheckIns ) {
505610 this .ignoredCheckIns = ignoredCheckIns ;
506611 }
0 commit comments