// Path: promagent-framework/promagent-api/src/main/java/io/promagent/hookcontext/MetricDef.java
// public class MetricDef<T extends Collector> {
// 
//     private final String metricName;
//     private final BiFunction<String, CollectorRegistry, T> producer;
// 
//     /**
//      * See {@link MetricsStore}.
//      * @param metricName Name of the Prometheus metric, like <tt>"http_requests_total"</tt>.
//      * @param producer Function to create a new metric and register it with the registry.
//      *                 This function will only be called once, subsequent calls to {@link MetricsStore#createOrGet(MetricDef)}
//      *                 will return the previously created metric with the specified name.
//      *                 The two parameters are the <i>metricName</i> as specified above,
//      *                 and the Prometheus registry where the new metric should be registered.
//      *                 For an example see JavaDoc for {@link MetricsStore}.
//      */
//     public MetricDef(String metricName, BiFunction<String, CollectorRegistry, T> producer) {
//         this.metricName = metricName;
//         this.producer = producer;
//     }
// 
//     String getMetricName() {
//         return metricName;
//     }
// 
//     BiFunction<String, CollectorRegistry, T> getProducer() {
//         return producer;
//     }
// }
// 
// Path: promagent-framework/promagent-api/src/main/java/io/promagent/hookcontext/MetricsStore.java
// public class MetricsStore {
// 
//     private final CollectorRegistry registry;
//     private final ConcurrentMap<String, Collector> metrics = new ConcurrentHashMap<>();
// 
//     public MetricsStore(CollectorRegistry registry) {
//         this.registry = registry;
//     }
// 
//     /**
//      * See {@link MetricsStore} and {@link MetricDef#MetricDef(String, BiFunction)}.
//      */
//     @SuppressWarnings("unchecked")
//     public <T extends Collector> T createOrGet(MetricDef<T> metricDef) {
//         return (T) metrics.computeIfAbsent(metricDef.getMetricName(), s -> metricDef.getProducer().apply(metricDef.getMetricName(), registry));
//     }
// }
// 
// Path: promagent-example/src/main/java/io/promagent/hooks/HttpContext.java
// static final Key<String> HTTP_METHOD = new Key<>();
// 
// Path: promagent-example/src/main/java/io/promagent/hooks/HttpContext.java
// static final Key<String> HTTP_PATH = new Key<>();


import io.promagent.annotations.After;
import io.promagent.annotations.Before;
import io.promagent.annotations.Hook;
import io.promagent.hookcontext.MetricDef;
import io.promagent.hookcontext.MetricsStore;
import io.prometheus.client.Counter;
import io.prometheus.client.Summary;
import java.util.concurrent.TimeUnit;
import static io.promagent.hooks.HttpContext.HTTP_METHOD;
import static io.promagent.hooks.HttpContext.HTTP_PATH;
// Copyright 2017 The Promagent Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package io.promagent.hooks;




@Hook(instruments = {
        "java.sql.Statement",
        "java.sql.Connection"
})
public class JdbcHook {

    private final Counter sqlQueriesTotal;
    private final Summary sqlQueriesDuration;
    private long startTime = 0;

// Path: promagent-framework/promagent-api/src/main/java/io/promagent/hookcontext/MetricDef.java
// public class MetricDef<T extends Collector> {
// 
//     private final String metricName;
//     private final BiFunction<String, CollectorRegistry, T> producer;
// 
//     /**
//      * See {@link MetricsStore}.
//      * @param metricName Name of the Prometheus metric, like <tt>"http_requests_total"</tt>.
//      * @param producer Function to create a new metric and register it with the registry.
//      *                 This function will only be called once, subsequent calls to {@link MetricsStore#createOrGet(MetricDef)}
//      *                 will return the previously created metric with the specified name.
//      *                 The two parameters are the <i>metricName</i> as specified above,
//      *                 and the Prometheus registry where the new metric should be registered.
//      *                 For an example see JavaDoc for {@link MetricsStore}.
//      */
//     public MetricDef(String metricName, BiFunction<String, CollectorRegistry, T> producer) {
//         this.metricName = metricName;
//         this.producer = producer;
//     }
// 
//     String getMetricName() {
//         return metricName;
//     }
// 
//     BiFunction<String, CollectorRegistry, T> getProducer() {
//         return producer;
//     }
// }
// 
// Path: promagent-framework/promagent-api/src/main/java/io/promagent/hookcontext/MetricsStore.java
// public class MetricsStore {
// 
//     private final CollectorRegistry registry;
//     private final ConcurrentMap<String, Collector> metrics = new ConcurrentHashMap<>();
// 
//     public MetricsStore(CollectorRegistry registry) {
//         this.registry = registry;
//     }
// 
//     /**
//      * See {@link MetricsStore} and {@link MetricDef#MetricDef(String, BiFunction)}.
//      */
//     @SuppressWarnings("unchecked")
//     public <T extends Collector> T createOrGet(MetricDef<T> metricDef) {
//         return (T) metrics.computeIfAbsent(metricDef.getMetricName(), s -> metricDef.getProducer().apply(metricDef.getMetricName(), registry));
//     }
// }
// 
// Path: promagent-example/src/main/java/io/promagent/hooks/HttpContext.java
// static final Key<String> HTTP_METHOD = new Key<>();
// 
// Path: promagent-example/src/main/java/io/promagent/hooks/HttpContext.java
// static final Key<String> HTTP_PATH = new Key<>();


// Path: promagent-example/src/main/java/io/promagent/hooks/JdbcHook.java
import io.promagent.annotations.After;
import io.promagent.annotations.Before;
import io.promagent.annotations.Hook;
import io.promagent.hookcontext.MetricDef;
import io.promagent.hookcontext.MetricsStore;
import io.prometheus.client.Counter;
import io.prometheus.client.Summary;
import java.util.concurrent.TimeUnit;
import static io.promagent.hooks.HttpContext.HTTP_METHOD;
import static io.promagent.hooks.HttpContext.HTTP_PATH;

// Copyright 2017 The Promagent Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package io.promagent.hooks;




@Hook(instruments = {
        "java.sql.Statement",
        "java.sql.Connection"
})
public class JdbcHook {

    private final Counter sqlQueriesTotal;
    private final Summary sqlQueriesDuration;
    private long startTime = 0;

    public JdbcHook(MetricsStore metricsStore) {