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

io.opentracing.contrib.jdbi3.ActiveSpanSource Maven / Gradle / Ivy

There is a newer version: 0.6.2
Show newest version
/*
 * Copyright 2016-2018 The OpenTracing 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.opentracing.contrib.jdbi3;

import io.opentracing.Span;
import org.jdbi.v3.core.statement.StatementContext;

/**
 * An abstract API that allows the OpentracingSqlLogger to customize how parent Spans are
 * discovered.
 * 

* For instance, if Spans are stored in a thread-local variable, an ActiveSpanSource could access * them like so: *

Example usage: *

{@code
 * public class SomeClass {
 *     // Thread local variable containing each thread's ID
 *     private static final ThreadLocal activeSpan =
 *         new ThreadLocal() {
 *             protected Integer initialValue() {
 *                 return null;
 *             }
 *         };
 * };
 *
 * ... elsewhere ...
 * ActiveSpanSource spanSource = new ActiveSpanSource() {
 *     public Span activeSpan(StatementContext ctx) {
 *         // (In this example we ignore `ctx` entirely)
 *         return activeSpan.get();
 *     }
 * };
 * OpentracingSqlLogger otColl = new OpentracingSqlLogger(tracer, spanSource);
 * ...
 * }
*/ public interface ActiveSpanSource { /** * Get the active Span (to use as a parent for any Jdbi Spans). Implementations may or may not * need to refer to the StatementContext. * * @param ctx the StatementContext that needs to be collected and traced * @return the currently active Span (for this thread, etc), or null if no such Span could be * found. */ Span activeSpan(StatementContext ctx); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy