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

org.openmetadata.service.util.jdbi.OMSqlLogger Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.service.util.jdbi;

import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.statement.SqlLogger;
import org.jdbi.v3.core.statement.StatementContext;
import org.openmetadata.service.util.MicrometerBundleSingleton;

@Slf4j
public class OMSqlLogger implements SqlLogger {
  @Override
  public void logBeforeExecution(StatementContext context) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("sql {}, parameters {}", context.getRenderedSql(), context.getBinding());
    }
  }

  @Override
  public void logAfterExecution(StatementContext context) {
    long elapsedTime = context.getElapsedTime(ChronoUnit.SECONDS);
    MicrometerBundleSingleton.jdbiRequests.observe(elapsedTime);
    MicrometerBundleSingleton.getJdbiLatencyTimer().record(elapsedTime, TimeUnit.SECONDS);
    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "sql {}, parameters {}, timeTaken {} ms",
          context.getRenderedSql(),
          context.getBinding(),
          context.getElapsedTime(ChronoUnit.MILLIS));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy