Example #1
0
    def __init__(self,
                 trans,
                 strictRead=False,
                 client_types=None,
                 client_type=None):
        """Create a THeaderProtocol instance

        @param transport(TTransport) The underlying transport.
        @param strictRead(bool) Turn on strictRead if using TBinaryProtocol
        @param client_types([CLIENT_TYPE.HEADER, ...])
                   List of client types to support.  Defaults to
                   CLIENT_TYPE.HEADER only.
        """

        if isinstance(trans, THeaderTransport):
            trans._THeaderTransport__supported_client_types = set(
                client_types or (CLIENT_TYPE.HEADER, ))
            if client_type is not None:
                trans._THeaderTransport__client_type = client_type
            htrans = trans
        else:
            htrans = THeaderTransport(trans, client_types, client_type)
        TProtocolBase.__init__(self, htrans)
        self.strictRead = strictRead
        self.reset_protocol()
 def __init__(self, trans, spec=None):
     TProtocolBase.__init__(self, trans)
     # Used as stack for contexts.
     self.contexts = [TJSONContext(protocol=self)]
     self.context = TJSONContext(protocol=self)
     self.pair_context_class = TJSONPairContext
     self.list_context_class = TJSONListContext
     self.reader = LookaheadReader(self)
     self.specs = []
     self.spec = StructSpec(spec)
Example #3
0
        def call_processor_with_span_context(self: Any, seqid: int,
                                             iprot: TProtocolBase,
                                             oprot: TProtocolBase) -> Any:
            context = baseplate.make_context_object()

            # Allow case-insensitivity for THeader headers
            headers: Mapping[bytes,
                             bytes] = CaseInsensitiveDict(  # type: ignore
                                 data=iprot.get_headers())

            trace_info: Optional[TraceInfo]
            try:
                sampled = bool(headers.get(b"Sampled") == b"1")
                flags = headers.get(b"Flags", None)
                trace_info = TraceInfo.from_upstream(
                    headers[b"Trace"].decode(),
                    headers[b"Parent"].decode(),
                    headers[b"Span"].decode(),
                    sampled,
                    int(flags) if flags is not None else None,
                )
            except (KeyError, ValueError):
                trace_info = None

            edge_payload = headers.get(b"Edge-Request", None)
            context.raw_edge_context = edge_payload
            if edge_context_factory:
                context.edge_context = edge_context_factory.from_upstream(
                    edge_payload)

            try:
                raw_deadline_budget = headers[b"Deadline-Budget"].decode()
                context.deadline_budget = float(raw_deadline_budget) / 1000
            except (KeyError, ValueError):
                context.deadline_budget = None

            span = baseplate.make_server_span(context,
                                              name=fn_name,
                                              trace_info=trace_info)

            try:
                service_name = headers[b"User-Agent"].decode()
            except (KeyError, UnicodeDecodeError):
                pass
            else:
                span.set_tag("peer.service", service_name)

            context.headers = headers

            handler = processor._handler
            context_aware_handler = _ContextAwareHandler(
                handler, context, logger)
            context_aware_processor = processor.__class__(
                context_aware_handler)
            return processor_fn(context_aware_processor, seqid, iprot, oprot)
Example #4
0
        def call_processor_with_span_context(self: Any, seqid: int,
                                             iprot: TProtocolBase,
                                             oprot: TProtocolBase) -> Any:
            context = baseplate.make_context_object()

            # Allow case-insensitivity for THeader headers
            headers: Mapping[bytes,
                             bytes] = CaseInsensitiveDict(  # type: ignore
                                 data=iprot.get_headers())

            trace_info: Optional[TraceInfo]
            try:
                sampled = bool(headers.get(b"Sampled") == b"1")
                flags = headers.get(b"Flags", None)
                trace_info = TraceInfo.from_upstream(
                    int(headers[b"Trace"]),
                    int(headers[b"Parent"]),
                    int(headers[b"Span"]),
                    sampled,
                    int(flags) if flags is not None else None,
                )
            except (KeyError, ValueError):
                trace_info = None

            edge_payload = headers.get(b"Edge-Request", None)
            if edge_context_factory:
                edge_context = edge_context_factory.from_upstream(edge_payload)
                edge_context.attach_context(context)
            else:
                # just attach the raw context so it gets passed on
                # downstream even if we don't know how to handle it.
                context.raw_request_context = edge_payload

            baseplate.make_server_span(context,
                                       name=fn_name,
                                       trace_info=trace_info)

            context.headers = headers

            handler = processor._handler
            context_aware_handler = _ContextAwareHandler(
                handler, context, logger)
            context_aware_processor = processor.__class__(
                context_aware_handler)
            return processor_fn(context_aware_processor, seqid, iprot, oprot)
Example #5
0
 def __init__(self, protocol):
     TProtocolBase(protocol)
     self.protocol = protocol
 def __init__(self, trans):
   TProtocolBase.__init__(self, trans)
   self.resetWriteContext()
   self.resetReadContext()
Example #7
0
 def __init__(self, trans, validJSON=True):
     TProtocolBase.__init__(self, trans)
     self.validJSON = validJSON
     self.resetWriteContext()
     self.resetReadContext()
 def __init__(self, trans):
     TProtocolBase.__init__(self, trans)
     self.resetWriteContext()
     self.resetReadContext()