All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datadoghq.trace.sampling.AbstractSampler Maven / Gradle / Ivy

There is a newer version: 0.2.12
Show newest version
package com.datadoghq.trace.sampling;

import com.datadoghq.trace.DDBaseSpan;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;

public abstract class AbstractSampler implements Sampler {

  /** Sample tags */
  protected Map skipTagsPatterns = new HashMap<>();

  @Override
  public boolean sample(final DDBaseSpan span) {

    // Filter by tag values
    for (final Entry entry : skipTagsPatterns.entrySet()) {
      final Object value = span.getTags().get(entry.getKey());
      if (value != null) {
        final String strValue = String.valueOf(value);
        final Pattern skipPattern = entry.getValue();
        if (skipPattern.matcher(strValue).matches()) {
          return false;
        }
      }
    }

    return doSample(span);
  }

  /**
   * Pattern based skipping of tag values
   *
   * @param tag
   * @param skipPattern
   */
  public void addSkipTagPattern(final String tag, final Pattern skipPattern) {
    skipTagsPatterns.put(tag, skipPattern);
  }

  protected abstract boolean doSample(DDBaseSpan span);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy