public static @Nullable DataSampler create(PipelineOptions options) {
    boolean disableAlwaysOnExceptionSampling =
        ExperimentalOptions.hasExperiment(options, DISABLE_ALWAYS_ON_EXCEPTION_SAMPLING_EXPERIMENT);
    boolean enableAlwaysOnExceptionSampling =
        ExperimentalOptions.hasExperiment(options, ENABLE_ALWAYS_ON_EXCEPTION_SAMPLING_EXPERIMENT);
    boolean enableDataSampling =
        ExperimentalOptions.hasExperiment(options, ENABLE_DATA_SAMPLING_EXPERIMENT);
    // Enable exception sampling, unless the user specifies for it to be disabled.
    enableAlwaysOnExceptionSampling =
        enableAlwaysOnExceptionSampling && !disableAlwaysOnExceptionSampling;

    // If no sampling is enabled, don't create the DataSampler.
    if (enableDataSampling || enableAlwaysOnExceptionSampling) {
      // For performance reasons, sampling all elements should only be done when the user requests
      // it.
      // But, exception sampling doesn't need to worry about performance implications, since the SDK
      // is already in a bad state. Thus, enable only exception sampling when the user does not
      // request for the sampling of all elements.
      boolean onlySampleExceptions = enableAlwaysOnExceptionSampling && !enableDataSampling;
      return new DataSampler(onlySampleExceptions);
    } else {
      return null;
    }
  }
@Test
  public void testDisableAlwaysOnExceptionSampling() throws Exception {
    ExperimentalOptions experimentalOptions = PipelineOptionsFactory.as(ExperimentalOptions.class);
    experimentalOptions.setExperiments(
        ImmutableList.of(
            "enable_always_on_exception_sampling", "disable_always_on_exception_sampling"));
    DataSampler sampler = DataSampler.create(experimentalOptions);
    assertNull(sampler);
  }