Package com.google.apphosting.runtime
Class TraceWriter
- java.lang.Object
-
- com.google.apphosting.runtime.TraceWriter
-
public class TraceWriter extends Object
Stores trace spans for a single request, and flushes them intoRuntimePb.UPResponse.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_TRACEstatic StringMAX_TRACE_PROPERTY
-
Constructor Summary
Constructors Constructor Description TraceWriter(com.google.apphosting.api.CloudTraceContext context, MutableUpResponse upResponse)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStackTrace(com.google.apphosting.api.CloudTraceContext context, StackTraceElement[] stackTrace)Add stack trace into the current span.voidendApiSpan(com.google.apphosting.api.CloudTraceContext context)End the API span.voidendRequestSpan()End the request span.voidendSpan(com.google.apphosting.api.CloudTraceContext context)End the current span.voidflushTrace()Flush collected trace intoRuntimePb.UPResponse.com.google.apphosting.api.CloudTraceContextgetTraceContext()Gets the current trace context.static TraceWritergetTraceWriterForRequest(com.google.apphosting.base.protos.RuntimePb.UPRequest upRequest, MutableUpResponse upResponse)voidsetLabel(com.google.apphosting.api.CloudTraceContext context, String key, String value)Set a label on the current span.com.google.apphosting.api.CloudTraceContextstartApiSpan(com.google.apphosting.api.CloudTraceContext parentContext, String packageName, String methodName)Start a API span as a child of the current span.com.google.apphosting.api.CloudTraceContextstartChildSpan(com.google.apphosting.api.CloudTraceContext parentContext, String name)Start a new span as a child of the given context.voidstartRequestSpan(String name)Start a request span as a child of the current span.
-
-
-
Field Detail
-
DEFAULT_MAX_TRACE
public static final int DEFAULT_MAX_TRACE
- See Also:
- Constant Field Values
-
MAX_TRACE_PROPERTY
public static final String MAX_TRACE_PROPERTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TraceWriter
public TraceWriter(com.google.apphosting.api.CloudTraceContext context, MutableUpResponse upResponse)
-
-
Method Detail
-
getTraceWriterForRequest
@Nullable public static TraceWriter getTraceWriterForRequest(com.google.apphosting.base.protos.RuntimePb.UPRequest upRequest, MutableUpResponse upResponse)
-
getTraceContext
public com.google.apphosting.api.CloudTraceContext getTraceContext()
Gets the current trace context.- Returns:
- the current trace context.
-
startRequestSpan
public void startRequestSpan(String name)
Start a request span as a child of the current span.- Parameters:
name- the name of the request span
-
startApiSpan
public com.google.apphosting.api.CloudTraceContext startApiSpan(@Nullable com.google.apphosting.api.CloudTraceContext parentContext, String packageName, String methodName)
Start a API span as a child of the current span.- Parameters:
parentContext- the parent contextpackageName- the name of the API packagemethodName- the name of the method within the API package- Returns:
- a child
CloudTraceContext
-
startChildSpan
public com.google.apphosting.api.CloudTraceContext startChildSpan(com.google.apphosting.api.CloudTraceContext parentContext, String name)Start a new span as a child of the given context.- Parameters:
parentContext- the parent contextname- the name of the child span- Returns:
- a child
CloudTraceContext
-
setLabel
public void setLabel(com.google.apphosting.api.CloudTraceContext context, String key, String value)Set a label on the current span.- Parameters:
context- the current contextkey- key of the labelvalue- value of the label
-
addStackTrace
public void addStackTrace(com.google.apphosting.api.CloudTraceContext context, StackTraceElement[] stackTrace)Add stack trace into the current span. The stack trace must be scrubbed for security before being passed to this method.- Parameters:
context- the current contextstackTrace- stack trace to be added
-
endSpan
public void endSpan(com.google.apphosting.api.CloudTraceContext context)
End the current span.- Parameters:
context- the current context
-
endApiSpan
public void endApiSpan(com.google.apphosting.api.CloudTraceContext context)
End the API span. TODO: Remove this function which is the same as endSpan.- Parameters:
context- the trace context of the API span
-
endRequestSpan
public void endRequestSpan()
End the request span.
-
flushTrace
public void flushTrace()
Flush collected trace intoRuntimePb.UPResponse.
-
-