How to use the instana.singletons.async_tracer function in instana

To help you get started, we’ve selected a few instana examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github instana / python-sensor / tests / clients / test_asynqp.py View on Github external
def test():
            with async_tracer.start_active_span('test'):
                msg = asynqp.Message({'hello': 'world'}, content_type='application/json')
                self.exchange.publish(msg, 'routing.key')
github instana / python-sensor / tests / frameworks / test_asyncio.py View on Github external
def setUp(self):
        """ Clear all spans before a test run """
        self.recorder = async_tracer.recorder
        self.recorder.clear_spans()

        # New event loop for every test
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)

        # Restore default
        config['asyncio_task_context_propagation']['enabled'] = False
github instana / python-sensor / tests / frameworks / test_aiohttp.py View on Github external
def setUp(self):
        """ Clear all spans before a test run """
        self.recorder = async_tracer.recorder
        self.recorder.clear_spans()

        # New event loop for every test
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
github instana / python-sensor / tests / frameworks / test_tornado_server.py View on Github external
def setUp(self):
        """ Clear all spans before a test run """
        self.recorder = async_tracer.recorder
        self.recorder.clear_spans()

        # New event loop for every test
        # self.loop = tornado.ioloop.IOLoop.current()
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)

        self.http_client = AsyncHTTPClient()
github instana / python-sensor / instana / instrumentation / aiohttp / server.py View on Github external
async def stan_middleware(request, handler):
        try:
            ctx = async_tracer.extract(opentracing.Format.HTTP_HEADERS, request.headers)
            request['scope'] = async_tracer.start_active_span('aiohttp-server', child_of=ctx)
            scope = request['scope']

            # Query param scrubbing
            url = str(request.url)
            parts = url.split('?')
            if len(parts) > 1:
                cleaned_qp = strip_secrets(parts[1], agent.secrets_matcher, agent.secrets_list)
                scope.span.set_tag("http.params", cleaned_qp)

            scope.span.set_tag("http.url", parts[0])
            scope.span.set_tag("http.method", request.method)

            # Custom header tracking support
            if hasattr(agent, 'extra_headers') and agent.extra_headers is not None:
                for custom_header in agent.extra_headers:
                    if custom_header in request.headers:
github instana / python-sensor / instana / instrumentation / aiohttp / client.py View on Github external
async def stan_request_start(session, trace_config_ctx, params):
        try:
            parent_span = async_tracer.active_span

            # If we're not tracing, just return
            if parent_span is None:
                trace_config_ctx.scope = None
                return

            scope = async_tracer.start_active_span("aiohttp-client", child_of=parent_span)
            trace_config_ctx.scope = scope

            async_tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, params.headers)

            parts = str(params.url).split('?')
            if len(parts) > 1:
                cleaned_qp = strip_secrets(parts[1], agent.secrets_matcher, agent.secrets_list)
                scope.span.set_tag("http.params", cleaned_qp)
            scope.span.set_tag("http.url", parts[0])
github instana / python-sensor / example / asyncio / aioclient.py View on Github external
async def test():
    while True:
        await asyncio.sleep(2)
        with async_tracer.start_active_span('JobRunner'):
            async with aiohttp.ClientSession() as session:
                    # aioserver exposes /, /401, /500 & /publish (via asynqp)
                    async with session.get("http://localhost:5102/publish?secret=iloveyou") as response:
                        print(response.status)
github instana / python-sensor / instana / instrumentation / asynqp.py View on Github external
def get_with_instana(wrapped, instance, argv, kwargs):
        parent_span = async_tracer.active_span

        # If we're not tracing, just return
        if parent_span is None:
            return wrapped(*argv, **kwargs)

        with async_tracer.start_active_span("rabbitmq", child_of=parent_span) as scope:
            host, port = instance.sender.protocol.transport._sock.getsockname()

            scope.span.set_tag("sort", "consume")
            scope.span.set_tag("address", host + ":" + str(port) )

            msg = yield from wrapped(*argv, **kwargs)

            if msg is not None:
                scope.span.set_tag("queue", instance.name)
                scope.span.set_tag("key", msg.routing_key)

            return msg
github instana / python-sensor / instana / instrumentation / asynqp.py View on Github external
def callback_with_instana(*argv, **kwargs):
                ctx = None
                msg = argv[0]
                if msg.headers is not None:
                    ctx = async_tracer.extract(opentracing.Format.TEXT_MAP, dict(msg.headers))

                with async_tracer.start_active_span("rabbitmq", child_of=ctx) as scope:
                    host, port = msg.sender.protocol.transport._sock.getsockname()

                    try:
                        scope.span.set_tag("exchange", msg.exchange_name)
                        scope.span.set_tag("sort", "consume")
                        scope.span.set_tag("address", host + ":" + str(port) )
                        scope.span.set_tag("key", msg.routing_key)

                        original_callback(*argv, **kwargs)
                    except Exception as e:
                        scope.span.mark_as_errored({'message': e})
                        raise
github instana / python-sensor / instana / instrumentation / asynqp.py View on Github external
def publish_with_instana(wrapped, instance, argv, kwargs):
        parent_span = async_tracer.active_span

        # If we're not tracing, just return
        if parent_span is None:
            return wrapped(*argv, **kwargs)

        with async_tracer.start_active_span("rabbitmq", child_of=parent_span) as scope:
            host, port = instance.sender.protocol.transport._sock.getsockname()

            msg = argv[0]
            if msg.headers is None:
                msg.headers = {}
            async_tracer.inject(scope.span.context, opentracing.Format.TEXT_MAP, msg.headers)

            try:
                scope.span.set_tag("exchange", instance.name)
                scope.span.set_tag("sort", "publish")