Class TraceWriter


  • public class TraceWriter
    extends Object
    Stores trace spans for a single request, and flushes them into RuntimePb.UPResponse.
    • 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 context
        packageName - the name of the API package
        methodName - 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 context
        name - 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 context
        key - key of the label
        value - 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 context
        stackTrace - 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 into RuntimePb.UPResponse.