AbstractTracerContext.java 3.4 KB
Newer Older
1 2
package org.skywalking.apm.agent.core.context;

3
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
wu-sheng's avatar
wu-sheng 已提交
4 5 6
import org.skywalking.apm.agent.core.context.trace.EntrySpan;
import org.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.skywalking.apm.agent.core.context.trace.LocalSpan;
7 8 9 10 11 12 13

/**
 * The <code>AbstractTracerContext</code> represents the tracer context manager.
 *
 * @author wusheng
 */
public interface AbstractTracerContext {
wu-sheng's avatar
wu-sheng 已提交
14 15 16 17 18 19 20
    /**
     * Prepare for the cross-process propagation.
     * How to initialize the carrier, depends on the implementation.
     *
     * @param carrier to carry the context for crossing process.
     * @see {@link TracingContext} and {@link IgnoredTracerContext}
     */
21 22
    void inject(ContextCarrier carrier);

wu-sheng's avatar
wu-sheng 已提交
23 24 25 26 27 28 29
    /**
     * Build the reference between this segment and a cross-process segment.
     * How to build, depends on the implementation.
     *
     * @param carrier carried the context from a cross-process segment.
     * @see {@link TracingContext} and {@link IgnoredTracerContext}
     */
30 31
    void extract(ContextCarrier carrier);

wu-sheng's avatar
wu-sheng 已提交
32 33 34 35 36 37 38 39
    /**
     * Capture a snapshot for cross-thread propagation.
     * It's a similar concept with ActiveSpan.Continuation in OpenTracing-java
     * How to build, depends on the implementation.
     *
     * @return the {@link ContextSnapshot} , which includes the reference context.
     * @see {@link TracingContext} and {@link IgnoredTracerContext}
     */
wu-sheng's avatar
wu-sheng 已提交
40 41
    ContextSnapshot capture();

wu-sheng's avatar
wu-sheng 已提交
42 43 44 45 46 47 48
    /**
     * Build the reference between this segment and a cross-thread segment.
     * How to build, depends on the implementation.
     *
     * @param snapshot from {@link #capture()} in the parent thread.
     * @see {@link TracingContext} and {@link IgnoredTracerContext}
     */
wu-sheng's avatar
wu-sheng 已提交
49 50
    void continued(ContextSnapshot snapshot);

wu-sheng's avatar
wu-sheng 已提交
51 52 53 54 55 56 57
    /**
     * Get the global trace id, if exist.
     * How to build, depends on the implementation.
     *
     * @return the string represents the id.
     * @see {@link TracingContext} and {@link IgnoredTracerContext}
     */
58 59
    String getGlobalTraceId();

wu-sheng's avatar
wu-sheng 已提交
60 61 62 63 64 65 66
    /**
     * Create an entry span
     *
     * @param operationName most likely a service name
     * @return the span represents an entry point of this segment.
     * @see {@link EntrySpan} if the implementation is {@link TracingContext}
     */
wu-sheng's avatar
wu-sheng 已提交
67
    AbstractSpan createEntrySpan(String operationName);
68

wu-sheng's avatar
wu-sheng 已提交
69 70 71 72 73 74 75
    /**
     * Create a local span
     *
     * @param operationName most likely a local method signature, or business name.
     * @return the span represents a local logic block.
     * @see {@link LocalSpan} if the implementation is {@link TracingContext}
     */
wu-sheng's avatar
wu-sheng 已提交
76 77
    AbstractSpan createLocalSpan(String operationName);

wu-sheng's avatar
wu-sheng 已提交
78 79 80 81 82 83 84 85
    /**
     * Create an exit span
     *
     * @param operationName most likely a service name of remote
     * @param remotePeer the network id(ip:port, hostname:port or ip1:port1,ip2,port, etc.)
     * @return the span represent an exit point of this segment.
     * @see {@link ExitSpan} if the implementation is {@link TracingContext}
     */
wu-sheng's avatar
wu-sheng 已提交
86
    AbstractSpan createExitSpan(String operationName, String remotePeer);
87

wu-sheng's avatar
wu-sheng 已提交
88 89 90
    /**
     * @return the active span of current tracing context(stack)
     */
91
    AbstractSpan activeSpan();
92

wu-sheng's avatar
wu-sheng 已提交
93 94 95 96 97
    /**
     * Finish the given span, and the given span should be the active span of current tracing context(stack)
     *
     * @param span to finish
     */
98
    void stopSpan(AbstractSpan span);
99
}