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

io.opentelemetry.contrib.interceptor.api.Interceptor Maven / Gradle / Ivy

/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.contrib.interceptor.api;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;

/**
 * Intercepts a signal before it gets exported. The signal can get updated and/or filtered out based
 * on each interceptor implementation.
 */
public interface Interceptor {

  /**
   * Intercepts a signal.
   *
   * @param item The signal object.
   * @return The received signal modified (or null for excluding this signal from getting exported).
   *     If there's no operation needed to be done for a specific signal, it should be returned as
   *     is.
   */
  @Nullable
  T intercept(T item);

  /** Intercepts a collection of signals. */
  default Collection interceptAll(Collection items) {
    List result = new ArrayList<>();

    for (T item : items) {
      T intercepted = intercept(item);
      if (intercepted != null) {
        result.add(intercepted);
      }
    }

    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy