Package com.google.apphosting.api
Class CloudTrace
java.lang.Object
com.google.apphosting.api.CloudTrace
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 Summary
ConstructorsConstructorDescriptionCreates a new CloudTrace object and binds it to a given Environment. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidendSpan(ApiProxy.Environment env, CloudTraceContext context, CloudTraceContext parent) Ends the span for the given context.protected abstract voidendSpanImpl(CloudTraceContext context) static @Nullable CloudTraceContextReturns the current trace context for the given environment and the current thread.protected abstract @Nullable CloudTraceContextReturns the default context when a thread-specific one doesn't exist.static voidsetCurrentContext(ApiProxy.Environment env, @Nullable CloudTraceContext context) Sets the current trace context for the current environment and the current thread.static voidsetLabel(ApiProxy.Environment env, CloudTraceContext context, String key, String value) Sets a key:value label on the span for the given context.protected abstract voidsetLabelImpl(CloudTraceContext context, String key, String value) static @Nullable CloudTraceContextstartChildSpan(ApiProxy.Environment env, CloudTraceContext context, String name) Starts a new span as the child of the given context.protected abstract @Nullable CloudTraceContextstartChildSpanImpl(CloudTraceContext context, String name)
-
Constructor Details
-
CloudTrace
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
Returns the current trace context for the given environment and the current thread.- Parameters:
env- the current environment.
-
setCurrentContext
Sets the current trace context for the current environment and the current thread.- Parameters:
env- the current environment.context- the current trace context.
-
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
-
endSpanImpl
-