Python opentracing.ext.tags.SPAN_KIND_RPC_CLIENT Examples

The following are 30 code examples of opentracing.ext.tags.SPAN_KIND_RPC_CLIENT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module opentracing.ext.tags , or try the search function .
Example #1
Source File: test_asyncio.py    From opentracing-python with Apache License 2.0 6 votes vote down vote up
def test_two_callbacks(self):
        res_future1 = self.loop.create_task(self.client.send('message1'))
        res_future2 = self.loop.create_task(self.client.send('message2'))

        stop_loop_when(self.loop,
                       lambda: len(self.tracer.finished_spans()) >= 2)
        self.loop.run_forever()

        self.assertEquals('message1::response', res_future1.result())
        self.assertEquals('message2::response', res_future2.result())

        spans = self.tracer.finished_spans()
        self.assertEquals(len(spans), 2)

        for span in spans:
            self.assertEquals(span.tags.get(tags.SPAN_KIND, None),
                              tags.SPAN_KIND_RPC_CLIENT)

        self.assertNotSameTrace(spans[0], spans[1])
        self.assertIsNone(spans[0].parent_id)
        self.assertIsNone(spans[1].parent_id) 
Example #2
Source File: test_contextvars.py    From opentracing-python with Apache License 2.0 6 votes vote down vote up
def test(self):
        client = Client(self.tracer, self.queue)
        self.loop.create_task(self.server.run())
        self.loop.create_task(client.send())

        stop_loop_when(self.loop,
                       lambda: len(self.tracer.finished_spans()) >= 2)
        self.loop.run_forever()

        spans = self.tracer.finished_spans()
        self.assertIsNotNone(get_one_by_tag(spans,
                                            tags.SPAN_KIND,
                                            tags.SPAN_KIND_RPC_SERVER))
        self.assertIsNotNone(get_one_by_tag(spans,
                                            tags.SPAN_KIND,
                                            tags.SPAN_KIND_RPC_CLIENT)) 
Example #3
Source File: _dbapi2.py    From opentracing-python-instrumentation with MIT License 6 votes vote down vote up
def __call__(self, *args, **kwargs):
        safe_kwargs = kwargs
        if 'passwd' in kwargs or 'password' in kwargs or 'conv' in kwargs:
            safe_kwargs = dict(kwargs)
            if 'passwd' in safe_kwargs:
                del safe_kwargs['passwd']
            if 'password' in safe_kwargs:
                del safe_kwargs['password']
            if 'conv' in safe_kwargs:  # don't log conversion functions
                del safe_kwargs['conv']
        connect_params = (args, safe_kwargs) if args or safe_kwargs else None
        tags = {ext_tags.SPAN_KIND: ext_tags.SPAN_KIND_RPC_CLIENT}
        with func_span(self._connect_func_name, tags=tags):
            return self._wrapper_ctor(
                connection=self._connect_func(*args, **kwargs),
                module_name=self._module_name,
                connect_params=connect_params,
                cursor_wrapper=self._cursor_wrapper) 
Example #4
Source File: test_tornado.py    From opentracing-python with Apache License 2.0 6 votes vote down vote up
def test(self):
        client = Client(self.tracer, self.queue)
        with tracer_stack_context():
            self.loop.add_callback(self.server.run)
            self.loop.add_callback(client.send)

        stop_loop_when(self.loop,
                       lambda: len(self.tracer.finished_spans()) >= 2)
        self.loop.start()

        spans = self.tracer.finished_spans()
        self.assertIsNotNone(get_one_by_tag(spans,
                                            tags.SPAN_KIND,
                                            tags.SPAN_KIND_RPC_SERVER))
        self.assertIsNotNone(get_one_by_tag(spans,
                                            tags.SPAN_KIND,
                                            tags.SPAN_KIND_RPC_CLIENT)) 
Example #5
Source File: boto3.py    From opentracing-python-instrumentation with MIT License 6 votes vote down vote up
def perform_call(self, original_func, kind, service_name, operation_name,
                     *args, **kwargs):
        span = utils.start_child_span(
            operation_name='boto3:{}:{}:{}'.format(
                kind, service_name, operation_name
            ),
            parent=get_current_span()
        )

        span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        span.set_tag(tags.COMPONENT, 'boto3')
        span.set_tag('boto3.service_name', service_name)

        with span, span_in_stack_context(span):
            try:
                response = original_func(*args, **kwargs)
            except ClientError as error:
                self.set_request_id_tag(span, error.response)
                raise
            else:
                if isinstance(response, dict):
                    self.set_request_id_tag(span, response)

        return response 
Example #6
Source File: app_django.py    From python-sensor with MIT License 6 votes vote down vote up
def complex(request):
    with opentracing.tracer.start_active_span('asteroid') as pscope:
        pscope.span.set_tag(ext.COMPONENT, "Python simple example app")
        pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER)
        pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
        pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one")
        pscope.span.set_tag(ext.HTTP_METHOD, "GET")
        pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
        pscope.span.log_kv({"foo": "bar"})
        time.sleep(.2)

        with opentracing.tracer.start_active_span('spacedust', child_of=pscope.span) as cscope:
            cscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT)
            cscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
            cscope.span.set_tag(ext.HTTP_URL, "/python/simple/two")
            cscope.span.set_tag(ext.HTTP_METHOD, "POST")
            cscope.span.set_tag(ext.HTTP_STATUS_CODE, 204)
            cscope.span.set_baggage_item("someBaggage", "someValue")
            time.sleep(.1)

    return HttpResponse('Stan wuz here!') 
Example #7
Source File: test_asyncio.py    From opentelemetry-python with Apache License 2.0 6 votes vote down vote up
def test(self):
        client = Client(self.tracer, self.queue)
        self.loop.create_task(self.server.run())
        self.loop.create_task(client.send())

        stop_loop_when(
            self.loop,
            lambda: len(self.tracer.finished_spans()) >= 2,
            timeout=5.0,
        )
        self.loop.run_forever()

        spans = self.tracer.finished_spans()
        self.assertIsNotNone(
            get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
        )
        self.assertIsNotNone(
            get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        ) 
Example #8
Source File: test_threads.py    From opentelemetry-python with Apache License 2.0 6 votes vote down vote up
def test_two_callbacks(self):
        response_future1 = self.client.send("message1")
        response_future2 = self.client.send("message2")

        self.assertEqual("message1::response", response_future1.result(5.0))
        self.assertEqual("message2::response", response_future2.result(5.0))

        spans = self.tracer.finished_spans()
        self.assertEqual(len(spans), 2)

        for span in spans:
            self.assertEqual(
                span.attributes.get(tags.SPAN_KIND, None),
                tags.SPAN_KIND_RPC_CLIENT,
            )

        self.assertNotSameTrace(spans[0], spans[1])
        self.assertIsNone(spans[0].parent)
        self.assertIsNone(spans[1].parent) 
Example #9
Source File: test_span.py    From jaeger-client-python with Apache License 2.0 6 votes vote down vote up
def test_is_rpc():
    mock_tracer = mock.MagicMock()
    mock_tracer.max_tag_value_length = 100
    ctx = SpanContext(trace_id=1, span_id=2, parent_id=None, flags=1)

    span = Span(context=ctx, operation_name='x', tracer=mock_tracer)
    assert span.is_rpc() is False
    assert span.is_rpc_client() is False

    span = Span(context=ctx, operation_name='x', tracer=mock_tracer)
    span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_SERVER)
    assert span.is_rpc() is True
    assert span.is_rpc_client() is False

    span = Span(context=ctx, operation_name='x', tracer=mock_tracer)
    span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_CLIENT)
    assert span.is_rpc() is True
    assert span.is_rpc_client() is True 
Example #10
Source File: test_tracer.py    From jaeger-client-python with Apache License 2.0 6 votes vote down vote up
def test_child_span(tracer):
    span = tracer.start_span('test')
    child = tracer.start_span('child', references=child_of(span.context))
    child.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_CLIENT)
    child.set_tag('bender', 'is great')
    child.log_event('kiss-my-shiny-metal-...')
    child.finish()
    span.finish()
    tracer.reporter.report_span.assert_called_once()
    assert len(span.logs) == 0, 'Parent span is Local, must not have events'
    assert len(child.logs) == 1, 'Child must have one events'

    tracer.sampler = ConstSampler(False)
    span = tracer.start_span('test')
    child = tracer.start_span('child', references=child_of(span.context))
    child.set_tag('bender', 'is great')
    child.log_event('kiss-my-shiny-metal-...')
    child.finish()
    span.finish()
    assert len(child.logs) == 0, 'Must have no events, not sampled'
    assert len(child.tags) == 0, 'Must have no attributes, not sampled'
    tracer.close() 
Example #11
Source File: test_threads.py    From opentracing-python with Apache License 2.0 6 votes vote down vote up
def test_two_callbacks(self):
        response_future1 = self.client.send('message1')
        response_future2 = self.client.send('message2')

        self.assertEquals('message1::response', response_future1.result(5.0))
        self.assertEquals('message2::response', response_future2.result(5.0))

        spans = self.tracer.finished_spans()
        self.assertEquals(len(spans), 2)

        for span in spans:
            self.assertEquals(span.tags.get(tags.SPAN_KIND, None),
                              tags.SPAN_KIND_RPC_CLIENT)

        self.assertNotSameTrace(spans[0], spans[1])
        self.assertIsNone(spans[0].parent_id)
        self.assertIsNone(spans[1].parent_id) 
Example #12
Source File: test_contextvars.py    From opentracing-python with Apache License 2.0 6 votes vote down vote up
def test_two_callbacks(self):
        res_future1 = self.loop.create_task(self.client.send('message1'))
        res_future2 = self.loop.create_task(self.client.send('message2'))

        stop_loop_when(self.loop,
                       lambda: len(self.tracer.finished_spans()) >= 2)
        self.loop.run_forever()

        self.assertEqual('message1::response', res_future1.result())
        self.assertEqual('message2::response', res_future2.result())

        spans = self.tracer.finished_spans()
        self.assertEqual(len(spans), 2)

        for span in spans:
            self.assertEqual(span.tags.get(tags.SPAN_KIND, None),
                             tags.SPAN_KIND_RPC_CLIENT)

        self.assertNotSameTrace(spans[0], spans[1])
        self.assertIsNone(spans[0].parent_id)
        self.assertIsNone(spans[1].parent_id) 
Example #13
Source File: test_tornado.py    From opentracing-python with Apache License 2.0 6 votes vote down vote up
def test_two_callbacks(self):
        res_future1 = self.client.send('message1')
        res_future2 = self.client.send('message2')

        stop_loop_when(self.loop,
                       lambda: len(self.tracer.finished_spans()) >= 2)
        self.loop.start()

        self.assertEquals('message1::response', res_future1.result())
        self.assertEquals('message2::response', res_future2.result())

        spans = self.tracer.finished_spans()
        self.assertEquals(len(spans), 2)

        for span in spans:
            self.assertEquals(span.tags.get(tags.SPAN_KIND, None),
                              tags.SPAN_KIND_RPC_CLIENT)

        self.assertNotSameTrace(spans[0], spans[1])
        self.assertIsNone(spans[0].parent_id)
        self.assertIsNone(spans[1].parent_id) 
Example #14
Source File: test_celery.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def _test_with_instrumented_client(celery, tracer, task_error):
    result = _test_foo_task(celery, task_error)

    span_server, span_client = tracer.recorder.get_spans()
    assert span_client.parent_id is None
    assert span_client.context.trace_id == span_server.context.trace_id
    assert span_client.context.span_id == span_server.parent_id

    assert_span(span_client, result, 'apply_async', tags.SPAN_KIND_RPC_CLIENT)
    assert_span(span_server, result, 'run', tags.SPAN_KIND_RPC_SERVER) 
Example #15
Source File: test_asyncio.py    From opentelemetry-python with Apache License 2.0 5 votes vote down vote up
def send(self):
        with self.tracer.start_active_span("send") as scope:
            scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)

            message = {}
            self.tracer.inject(
                scope.span.context, opentracing.Format.TEXT_MAP, message
            )
            await self.queue.put(message)

        logger.info("Sent message from client") 
Example #16
Source File: test_threads.py    From opentelemetry-python with Apache License 2.0 5 votes vote down vote up
def send(self):
        with self.tracer.start_active_span("send") as scope:
            scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)

            message = {}
            self.tracer.inject(
                scope.span.context, opentracing.Format.TEXT_MAP, message
            )
            self.queue.put(message)

        logger.info("Sent message from client") 
Example #17
Source File: test_threads.py    From opentelemetry-python with Apache License 2.0 5 votes vote down vote up
def test(self):
        client = Client(self.tracer, self.queue)
        client.send()

        await_until(lambda: len(self.tracer.finished_spans()) >= 2)

        spans = self.tracer.finished_spans()
        self.assertIsNotNone(
            get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
        )
        self.assertIsNotNone(
            get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        ) 
Example #18
Source File: celery.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def task_apply_async_wrapper(task, args=None, kwargs=None, **other_kwargs):
    operation_name = 'Celery:apply_async:{}'.format(task.name)
    span = opentracing.tracer.start_span(operation_name=operation_name,
                                         child_of=get_current_span())
    set_common_tags(span, task, tags.SPAN_KIND_RPC_CLIENT)

    with span_in_context(span), span:
        result = _task_apply_async(task, args, kwargs, **other_kwargs)
        span.set_tag('celery.task_id', result.task_id)
        return result 
Example #19
Source File: test_threads.py    From opentelemetry-python with Apache License 2.0 5 votes vote down vote up
def test_main(self):
        client = Client(self.tracer)
        res = client.send_sync("message")
        self.assertEqual(res, "message::response")

        spans = self.tracer.finished_spans()
        self.assertEqual(len(spans), 1)

        span = get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        self.assertIsNotNone(span) 
Example #20
Source File: test_redis.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def check_span(span, key):
    assert span.tags['redis.key'] == key
    assert span.tags[tags.SPAN_KIND] == tags.SPAN_KIND_RPC_CLIENT
    assert span.tags[tags.PEER_SERVICE] == 'redis' 
Example #21
Source File: request_handler.py    From opentelemetry-python with Apache License 2.0 5 votes vote down vote up
def before_request(self, request, request_context):
        logger.info("Before request %s", request)

        # If we should ignore the active Span, use any passed SpanContext
        # as the parent. Else, use the active one.
        if self.ignore_active_span:
            span = self.tracer.start_span(
                "send", child_of=self.context, ignore_active_span=True
            )
        else:
            span = self.tracer.start_span("send")

        span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)

        request_context["span"] = span 
Example #22
Source File: test_boto3.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def assert_last_span(kind, service_name, operation, tracer, response=None):
    span = tracer.recorder.get_spans()[-1]
    request_id = response and response['ResponseMetadata'].get('RequestId')
    assert span.operation_name == 'boto3:{}:{}:{}'.format(
        kind, service_name, operation
    )
    assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT
    assert span.tags.get(tags.COMPONENT) == 'boto3'
    assert span.tags.get('boto3.service_name') == service_name
    if request_id:
        assert span.tags.get('aws.request_id') == request_id 
Example #23
Source File: test_sqlalchemy.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def assert_span(span, operation):
    assert span.operation_name == 'SQL ' + operation
    assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT
    assert span.tags.get(tags.DATABASE_TYPE) == 'sqlite'
    assert span.tags.get(tags.DATABASE_INSTANCE) == 'sqlite://'
    assert span.tags.get(tags.COMPONENT) == 'sqlalchemy' 
Example #24
Source File: test_mysqldb.py    From opentracing-python-instrumentation with MIT License 5 votes vote down vote up
def assert_span(span, operation, parent=None):
    assert span.operation_name == 'MySQLdb:' + operation
    assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT
    if parent:
        assert span.parent_id == parent.context.span_id
        assert span.context.trace_id == parent.context.trace_id
    else:
        assert span.parent_id is None 
Example #25
Source File: app.py    From microservices-in-action with MIT License 5 votes vote down vote up
def get_user_settings(uuid):
    logger.info("getting user settings", extra={"uuid": uuid})
    settings_url = urljoin("http://settings:5000/settings/", "{}".format(uuid))

    span = get_current_span()
    span.set_tag(tags.HTTP_METHOD, 'GET')
    span.set_tag(tags.HTTP_URL, settings_url)
    span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
    span.set_tag('uuid', uuid)
    headers = {}
    tracer.inject(span, Format.HTTP_HEADERS, headers)

    r = requests.get(settings_url, headers=headers)
    return r.json() 
Example #26
Source File: span.py    From jaeger-client-python with Apache License 2.0 5 votes vote down vote up
def is_rpc(self):
        for tag in self.tags:
            if tag.key == ext_tags.SPAN_KIND:
                return tag.vStr == ext_tags.SPAN_KIND_RPC_CLIENT or \
                    tag.vStr == ext_tags.SPAN_KIND_RPC_SERVER
        return False 
Example #27
Source File: span.py    From jaeger-client-python with Apache License 2.0 5 votes vote down vote up
def is_rpc_client(self):
        for tag in self.tags:
            if tag.key == ext_tags.SPAN_KIND:
                return tag.vStr == ext_tags.SPAN_KIND_RPC_CLIENT
        return False 
Example #28
Source File: test_tracer.py    From jaeger-client-python with Apache License 2.0 5 votes vote down vote up
def test_one_span_per_rpc(tracer, one_span_per_rpc):
    tracer.one_span_per_rpc = one_span_per_rpc
    span = tracer.start_span('client')
    span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_CLIENT)
    child = tracer.start_span(
        'server',
        references=child_of(span.context),
        tags={ext_tags.SPAN_KIND: ext_tags.SPAN_KIND_RPC_SERVER},
    )
    assert span.trace_id == child.trace_id, 'Must have the same trace ids'
    if one_span_per_rpc:
        assert span.span_id == child.span_id, 'Must have the same span ids'
    else:
        assert span.span_id != child.span_id, 'Must have different span ids' 
Example #29
Source File: tracing.py    From tchannel-python with MIT License 5 votes vote down vote up
def start_span(self, service, endpoint, headers=None,
                   hostport=None, encoding=None):
        parent_span = self.channel.context_provider.get_current_span()
        parent_ctx = parent_span.context if parent_span else None
        span = self.channel.tracer.start_span(
            operation_name=endpoint,
            child_of=parent_ctx
        )
        span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        span.set_tag(tags.PEER_SERVICE, service)
        set_peer_host_port(span, hostport)
        if encoding:
            span.set_tag('as', encoding)

        if headers is None:
            headers = {}
        if isinstance(headers, dict):
            # noinspection PyBroadException
            try:
                tracing_headers = {}
                self.channel.tracer.inject(
                    span.context, opentracing.Format.TEXT_MAP, tracing_headers)
                for k, v in six.iteritems(tracing_headers):
                    headers[TRACING_KEY_PREFIX + k] = v
            except:
                log.exception('Failed to inject tracing span into headers')

        return span, headers 
Example #30
Source File: test_asyncio.py    From opentracing-python with Apache License 2.0 5 votes vote down vote up
def send(self):
        with self.tracer.start_active_span('send') as scope:
            scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)

            message = {}
            self.tracer.inject(scope.span.context,
                               opentracing.Format.TEXT_MAP,
                               message)
            await self.queue.put(message)

        logger.info('Sent message from client')