def __init__( self, endpoint=DEFAULT_ENDPOINT, service_name=None, host_name=None, client=None, ): self.endpoint = endpoint if client is None: self.channel = grpc.insecure_channel(self.endpoint) self.client = trace_service_pb2_grpc.TraceServiceStub( channel=self.channel) else: self.client = client self.node = utils.get_node(service_name, host_name)
def __init__( self, endpoint: str = DEFAULT_ENDPOINT, service_name: str = None, host_name: str = None, client: metrics_service_pb2_grpc.MetricsServiceStub = None, ): self.endpoint = endpoint if client is None: channel = grpc.insecure_channel(self.endpoint) self.client = metrics_service_pb2_grpc.MetricsServiceStub( channel=channel) else: self.client = client self.node = utils.get_node(service_name, host_name)
def __init__( self, endpoint=DEFAULT_ENDPOINT, host_name=None, client=None, ): tracer_provider = trace.get_tracer_provider() service_name = (tracer_provider.resource.attributes[SERVICE_NAME] if getattr(tracer_provider, "resource", None) else Resource.create().attributes.get(SERVICE_NAME)) self.endpoint = endpoint if client is None: self.channel = grpc.insecure_channel(self.endpoint) self.client = trace_service_pb2_grpc.TraceServiceStub( channel=self.channel) else: self.client = client self.node = utils.get_node(service_name, host_name)
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult: # Populate service_name from first span # We restrict any SpanProcessor to be only associated with a single # TracerProvider, so it is safe to assume that all Spans in a single # batch all originate from one TracerProvider (and in turn have all # the same service_name) if spans: service_name = spans[0].resource.attributes.get(SERVICE_NAME) if service_name: self.node = utils.get_node(service_name, self.host_name) try: responses = self.client.Export(self.generate_span_requests(spans)) # Read response for _ in responses: pass except grpc.RpcError: return SpanExportResult.FAILURE return SpanExportResult.SUCCESS