Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test():
with async_tracer.start_active_span('test'):
msg = asynqp.Message({'hello': 'world'}, content_type='application/json')
self.exchange.publish(msg, 'routing.key')
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
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)
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()
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:
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])
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)
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
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
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")