class MetricsEnvironment {

  public static @Nullable MetricsContainer getCurrentContainer() {
    MetricsContainer container = CONTAINER_FOR_THREAD.get();
    if (container == null && REPORTED_MISSING_CONTAINER.compareAndSet(false, true)) {
      if (isMetricsSupported()) {
        LOG.error(
            "Unable to update metrics on the current thread. "
                + "Most likely caused by using metrics outside the managed work-execution thread.");
      } else {
        LOG.warn("Reporting metrics are not supported in the current execution environment.");
      }
    }
    return container;
  }

}