Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiohttp: Implement a list of ignored url/patterns #39

Closed
asyd opened this issue Nov 24, 2017 · 5 comments
Closed

aiohttp: Implement a list of ignored url/patterns #39

asyd opened this issue Nov 24, 2017 · 5 comments

Comments

@asyd
Copy link
Contributor

asyd commented Nov 24, 2017

Hi,

i'm wondering if you're agree to provide an optional argument to aiohttp_helpers to define a list of url/patterns that should be ignored by the middleware? I use aiozipkin in APIs that provide healtcheck and I don't want to have trace for each healthcheck call (but I want a sample_rate set to 1)

Thanks

@jettify
Copy link
Member

jettify commented Nov 25, 2017 via email

@asyd
Copy link
Contributor Author

asyd commented Nov 27, 2017

Sure.

@jettify
Copy link
Member

jettify commented Jan 20, 2018

Feature implemented in #79

@asyd
Copy link
Contributor Author

asyd commented Jan 21, 2018

Ohh thanks to you @jettify !

@jettify
Copy link
Member

jettify commented Jan 21, 2018

You are welcome! Just in case here is complete example how to use this feature:

import asyncio
import aiozipkin as az
from aiohttp import web
async def handle(request):
tracer = az.get_tracer(request.app)
span = az.request_span(request)
with tracer.new_child(span.context) as child_span:
child_span.name('mysql:select')
# call to external service like https://python.org
# or database query
await asyncio.sleep(0.01)
text = """
<html lang="en">
<head>
<title>aiohttp simple example</title>
</head>
<body>
<h3>This page was traced by aiozipkin</h3>
<p><a href="http://127.0.0.1:9001/status">Go to not traced page</a></p>
</body>
</html>
"""
return web.Response(text=text, content_type='text/html')
async def not_traced_handle(request):
text = """
<html lang="en">
<head>
<title>aiohttp simple example</title>
</head>
<body>
<h3>This page was NOT traced by aiozipkin></h3>
<p><a href="http://127.0.0.1:9001">Go to traced page</a></p>
</body>
</html>
"""
return web.Response(text=text, content_type='text/html')
async def make_app(host, port):
app = web.Application()
app.router.add_get('/', handle)
# here we aquire reference to route, so later we can command
# aiozipkin not to trace it
skip_route = app.router.add_get('/status', not_traced_handle)
endpoint = az.create_endpoint(
'aiohttp_server', ipv4=host, port=port)
zipkin_address = 'http://127.0.0.1:9411'
tracer = az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer, skip_routes=[skip_route])
return app
def run():
host = '127.0.0.1'
port = 9001
loop = asyncio.get_event_loop()
app = loop.run_until_complete(make_app(host, port))
web.run_app(app, host=host, port=port)
if __name__ == '__main__':
run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants