Class CloudTrace

java.lang.Object
com.google.apphosting.api.CloudTrace

public abstract class CloudTrace extends Object
Holds the current trace context visible to user code. If present, this object will be stored under the KEY-variable in an Environment's property. This class is used to share the current trace context between run time and user code. It is not responsible for managing contexts. It only keeps the most current context for a given thread.
  • Constructor Details

    • CloudTrace

      public CloudTrace(ApiProxy.Environment env)
      Creates a new CloudTrace object and binds it to a given Environment.
      Parameters:
      env - the environment object to bind this object to.
  • Method Details

    • getCurrentContext

      public static @Nullable CloudTraceContext getCurrentContext(ApiProxy.Environment env)
      Returns the current trace context for the given environment and the current thread.
      Parameters:
      env - the current environment.
    • setCurrentContext

      public static void setCurrentContext(ApiProxy.Environment env, @Nullable CloudTraceContext context)
      Sets the current trace context for the current environment and the current thread.
      Parameters:
      env - the current environment.
      context - the current trace context.
    • getDefaultContext

      protected abstract @Nullable CloudTraceContext getDefaultContext()
      Returns the default context when a thread-specific one doesn't exist.
    • startChildSpan

      public static @Nullable CloudTraceContext startChildSpan(ApiProxy.Environment env, CloudTraceContext context, String name)
      Starts a new span as the child of the given context. The given context must match the current context in the environment. After the call, the returned context becomes current.
      Parameters:
      env - the environment object to get the current context from.
      context - parent context of the child span. Must match the current context.
      name - name of the child span.
      Returns:
      context of the child span or null if the environment does not have trace context.
    • setLabel

      public static void setLabel(ApiProxy.Environment env, CloudTraceContext context, String key, String value)
      Sets a key:value label on the span for the given context. The given context must match the current context in the environment.
      Parameters:
      env - the environment object to get the current context.
      context - context of the span. Must match the current context.
      key - key of the label.
      value - value of the label.
    • endSpan

      public static void endSpan(ApiProxy.Environment env, CloudTraceContext context, CloudTraceContext parent)
      Ends the span for the given context. The given context must match the current context in the environment. After the call, the parent context becomes current.
      Parameters:
      env - the environment object to get the current context.
      context - context of the span. Must match the current context.
      parent - parent context of the span. It becomes the current context after the call.
    • startChildSpanImpl

      protected abstract @Nullable CloudTraceContext startChildSpanImpl(CloudTraceContext context, String name)
    • setLabelImpl

      protected abstract void setLabelImpl(CloudTraceContext context, String key, String value)
    • endSpanImpl

      protected abstract void endSpanImpl(CloudTraceContext context)