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 2.x+ client tracing support #294

Closed
Closed
Changes from 1 commit
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
907a086
Merge remote-tracking branch 'DataDog/master'
thehesiod Apr 12, 2017
ca55ba4
work on adding support for aiopg + aiobotocore + context patching
thehesiod Apr 12, 2017
26b708b
work on adding unittests
thehesiod Apr 12, 2017
cd7e57f
fix aiopg patching
thehesiod Apr 12, 2017
1bb231a
flake fixes
thehesiod Apr 12, 2017
837e8c2
fix comments
thehesiod Apr 12, 2017
4ebcc16
add distributed tracing support
thehesiod Apr 13, 2017
ad585cd
asyncio fixes
thehesiod Apr 13, 2017
79d71be
set span.error
thehesiod Apr 13, 2017
a7da295
add support for minimum response status to be considered an error
thehesiod Apr 13, 2017
e715c9f
add support for distributed aiobotocore spans
thehesiod Apr 13, 2017
7649d89
move to helpers
thehesiod Apr 13, 2017
c0ab3df
add ability to specify tracer and pep fixes
thehesiod Apr 14, 2017
d5562e1
wrap read method
thehesiod Apr 14, 2017
7b82dfc
populate read span's info
thehesiod Apr 14, 2017
8cc236e
add support for truncating arg values
thehesiod Apr 14, 2017
2b7c8f1
attempt to fix tests
thehesiod Apr 14, 2017
ca15385
bugfix
thehesiod Apr 14, 2017
ef9a5a0
fix unittests
thehesiod Apr 15, 2017
2c4fe87
fix unittest
thehesiod Apr 15, 2017
da5dc97
fix unittests
thehesiod Apr 15, 2017
9a5508e
flake fix
thehesiod Apr 15, 2017
df29727
fix tests
thehesiod Apr 15, 2017
13f8536
fix tests
thehesiod Apr 15, 2017
8c29099
fix aiopg unittests
thehesiod Apr 15, 2017
93c13a7
bugfix
thehesiod Apr 15, 2017
98480dd
remove await syntax support
thehesiod Apr 15, 2017
d3e49be
add flask dep
thehesiod Apr 15, 2017
0ce4b56
fix unittests
thehesiod Apr 15, 2017
b9ade72
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod May 4, 2017
28c67b6
Merge remote-tracking branch 'DataDog/master'
thehesiod May 4, 2017
64e71aa
aiohttp enhancements
thehesiod May 4, 2017
90b65e3
Merge remote-tracking branch 'DataDog/master'
thehesiod May 15, 2017
950d65c
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod May 15, 2017
064e4d4
add support for base parent span IDs
thehesiod May 15, 2017
5afcdc0
better asyncio task chaining
thehesiod May 16, 2017
b1257cc
add support for patterns
thehesiod May 16, 2017
78445de
add support for patterns
thehesiod May 16, 2017
69d59a9
set_traceback already sets this
thehesiod May 16, 2017
34bb4c9
set_traceback already sets this
thehesiod May 16, 2017
f82f666
bugfix
thehesiod May 17, 2017
8ec719d
bugfix
thehesiod May 17, 2017
f385deb
remove unused code
thehesiod May 19, 2017
79ed2e0
remove unused code
thehesiod May 19, 2017
e21d3ae
remove bad change
thehesiod May 19, 2017
c58b95b
remove bad change
thehesiod May 19, 2017
0107224
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp
thehesiod May 19, 2017
ecd49de
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod May 19, 2017
517d0be
Merge remote-tracking branch 'DataDog/master'
thehesiod May 25, 2017
2f1085e
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod May 25, 2017
3f7aa11
updates
thehesiod May 25, 2017
14823c3
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod May 31, 2017
8402096
Merge remote-tracking branch 'DataDog/master'
thehesiod May 31, 2017
4b29d60
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod Jun 7, 2017
77fdcc5
fix merge change
thehesiod Jun 7, 2017
3b7ce2f
Merge remote-tracking branch 'DataDog/master'
thehesiod Jun 8, 2017
efb5e08
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp
thehesiod Jun 8, 2017
766609a
Merge remote-tracking branch 'DataDog/master'
thehesiod Jun 14, 2017
a74ff3d
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp
thehesiod Jun 14, 2017
2285b98
Merge remote-tracking branch 'DataDog/master'
thehesiod Jun 20, 2017
c54c031
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp
thehesiod Jun 20, 2017
421e88d
changes based on slack chat w/ manu
thehesiod Jun 21, 2017
45b3f1b
remove whitespace
thehesiod Jun 21, 2017
2885f9b
Merge branch 'thehesiod-aiohttp' into thehesiod-aiohttp-client
thehesiod Jun 21, 2017
984eb96
add aiohttp client tracing support
thehesiod Jun 22, 2017
cb0e6a7
Merge remote-tracking branch 'DataDog/master' into thehesiod-aio-utils
thehesiod Jun 22, 2017
e977aa1
add aiohttp client tracing support
thehesiod Jun 22, 2017
260e54b
fix unittests
thehesiod Jun 22, 2017
f212020
fix unittests
thehesiod Jun 22, 2017
4eadc04
Merge branch 'thehesiod-aio-utils' into thehesiod-aiohttp
thehesiod Jun 22, 2017
249eea4
Revert "Merge branch 'thehesiod-aio-utils' into thehesiod-aiohttp"
thehesiod Jun 22, 2017
378c404
fix unittests
thehesiod Jun 23, 2017
1f71ae9
avoid unnecessary stringification
thehesiod Jun 23, 2017
caf025e
Merge branch 'thehesiod-aiohttp' into thehesiod-aiohttp-client
thehesiod Jun 23, 2017
71511f3
updates
thehesiod Jun 23, 2017
2e86f11
fix spacing
thehesiod Jun 23, 2017
e5924e7
we have to manually set the service
thehesiod Jun 24, 2017
5a39ced
add length
thehesiod Jun 24, 2017
eb046ce
ensure trace_headers applies to retries
thehesiod Jun 26, 2017
d1eca92
fix check
thehesiod Jun 26, 2017
e285168
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Jul 2, 2017
e572209
revert changes
thehesiod Jul 2, 2017
e9d8056
revert more changes
thehesiod Jul 2, 2017
d823662
Merge remote-tracking branch 'DataDog/master'
thehesiod Jul 2, 2017
dd47c2c
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Jul 3, 2017
8a7ce47
fix
thehesiod Jul 3, 2017
a019984
add parity with middleware
thehesiod Jul 3, 2017
c3b2cd9
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Jul 6, 2017
ea3ba40
fix for parent spans
thehesiod Jul 6, 2017
c0ede6e
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Nov 14, 2017
69739aa
switch to new mechanism
thehesiod Nov 20, 2017
0c0f379
cleanup
thehesiod Nov 20, 2017
aa03185
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Jan 8, 2018
8ebd4a2
changes based on review
thehesiod Jan 8, 2018
5d747ba
update based on review
thehesiod Jan 8, 2018
be038a9
fix bug and unittests
thehesiod Jan 9, 2018
8b8c769
Merge remote-tracking branch 'DataDog/master'
thehesiod Jan 9, 2018
0f8e82c
ver bump
thehesiod Jan 9, 2018
58f78db
add short-circuit ability
thehesiod Jan 9, 2018
f3845d6
set error code on error like httplib
thehesiod Jan 9, 2018
09813da
missed a spot
thehesiod Jan 9, 2018
534d553
add missing aenter/aexit
thehesiod Jan 16, 2018
839e5dd
bugfix
thehesiod Jan 16, 2018
a6ab0c9
Merge remote-tracking branch 'DataDog/master'
thehesiod Jan 23, 2018
5af9b51
Merge remote-tracking branch 'DataDog/master'
thehesiod Feb 3, 2018
af07ff9
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Feb 3, 2018
3f53e27
add connector tracing
thehesiod Feb 3, 2018
99fb053
fix port
thehesiod Feb 8, 2018
d3bc98e
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Mar 10, 2018
ae9521c
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Jun 14, 2018
2232332
bugfix
thehesiod Aug 10, 2018
e90a0a8
fix warnings
thehesiod Sep 19, 2018
d3b687d
flake fixes
thehesiod Oct 13, 2018
3aca41e
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Oct 13, 2018
4e4e7e3
revert change
thehesiod Oct 13, 2018
50c487a
pull in changes from aio-utils
thehesiod Oct 13, 2018
6619697
add missing change
thehesiod Oct 13, 2018
3021151
tweak
thehesiod Oct 13, 2018
e13fb26
flake fixes
thehesiod Oct 13, 2018
d776869
Merge branch 'master' of https://github.com/DataDog/dd-trace-py
thehesiod Apr 4, 2019
550b804
Merge branch 'master' into thehesiod-aiohttp-client
thehesiod Apr 4, 2019
f2beee9
cherry pick 3982991dd8b8eaa4a537c3026e73c64e0463574c
thehesiod Apr 4, 2019
528bac5
fix merge
thehesiod Apr 4, 2019
3f169fa
flake fix
thehesiod Apr 4, 2019
ffeb9d3
fix flake
thehesiod Apr 4, 2019
ce78aad
fix tests
thehesiod Apr 4, 2019
51979e8
bugfix
thehesiod Apr 4, 2019
689c708
revert change
thehesiod Apr 8, 2019
304c40a
Merge branch 'master' of https://github.com/DataDog/dd-trace-py
thehesiod Apr 27, 2019
e8d93c4
Merge branch 'master' into thehesiod-aiohttp-client
thehesiod Apr 27, 2019
ed8996d
fix patch
thehesiod Jun 14, 2019
14a266f
Merge remote-tracking branch 'DataDog/master' into thehesiod-aiohttp-…
thehesiod Feb 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cherry pick 3982991
thehesiod committed Apr 4, 2019

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit f2beee9d8fffb16894553f3200518a7621460ea9
10 changes: 6 additions & 4 deletions ddtrace/context.py
Original file line number Diff line number Diff line change
@@ -193,10 +193,12 @@ def get(self):
# clean the current state
self._trace = []
self._finished_spans = 0
self._parent_trace_id = None
self._parent_span_id = None
self._sampling_priority = None
self._sampled = True

# Don't clear out the parent trace IDs as this may be a cloned
# context in a new thread/task without a outer span
if not self._parent_trace_id:
self._sampling_priority = None
self._sampled = True
return trace, sampled

elif self._partial_flush_enabled and self._finished_spans >= self._partial_flush_min_spans:
2 changes: 1 addition & 1 deletion ddtrace/contrib/aiohttp/patch.py
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ def __init__(self, obj, pin, trace_headers):
self._self_parent_span_id = parent_span.span_id
else:
self._self_parent_trace_id, self._self_parent_span_id = \
ctx._get_parent_span_ids()
ctx.trace_id, ctx.span_id

self._self_trace_headers = trace_headers

Empty file.
90 changes: 90 additions & 0 deletions tests/contrib/aiohttp/py35/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import asyncio

from nose.tools import eq_
import aiohttp
from aiohttp.test_utils import unittest_run_loop

from ddtrace.contrib.asyncio.patch import patch as aio_patch, \
unpatch as aio_unpatch
from ddtrace.contrib.aiohttp.patch import patch, unpatch

from contrib.aiohttp.utils import TraceTestCase


class AIOHttpTest(TraceTestCase):
"""Botocore integration testsuite"""

def setUp(self):
super(AIOHttpTest, self).setUp()
patch(self.tracer, enable_distributed=True)

def tearDown(self):
super(TraceTestCase, self).tearDown()
unpatch()
self.tracer = None

@unittest_run_loop
async def test_wait_for_full_request(self):
aio_patch()

session = aiohttp.ClientSession()
url = self.client.make_url('/')

try:
with self.tracer.trace("foo"):
async def doit():
async with session.get(url) as request:
eq_(200, request.status)
await request.text()
# the trace is created

await asyncio.wait_for(doit(), 20)

traces = self.tracer.writer.pop_traces()
eq_(2, len(traces))

# outer span
eq_(1, len(traces[1]))
root_span = traces[1][0]
root_span_id = root_span.span_id

eq_(None, root_span.parent_id)
eq_(None, root_span.service)
eq_('foo', root_span.name)
eq_('foo', root_span.resource)

eq_(4, len(traces[0]))
client_request_span = traces[0][0]
eq_(root_span_id, client_request_span.parent_id)
eq_('aiohttp.client', client_request_span.service)
eq_('ClientSession.request', client_request_span.name)
eq_('/', client_request_span.resource)

# TCPConnector.connect
connector_connect_span = traces[0][1]
eq_(client_request_span.span_id, connector_connect_span.parent_id)
eq_(client_request_span.trace_id, connector_connect_span.trace_id)
eq_('aiohttp.client', connector_connect_span.service)
eq_('TCPConnector.connect', connector_connect_span.name)
eq_('/', connector_connect_span.resource)

# TCPConnector._create_connection
connector_create_connection_span = traces[0][2]
eq_(connector_connect_span.span_id,
connector_create_connection_span.parent_id)
eq_(connector_connect_span.trace_id,
connector_create_connection_span.trace_id)
eq_('aiohttp.client', connector_create_connection_span.service)
eq_('TCPConnector._create_connection',
connector_create_connection_span.name)
eq_('/', connector_create_connection_span.resource)

# client start span
client_start_span = traces[0][3]
eq_(client_request_span.span_id, client_start_span.parent_id)
eq_(client_request_span.trace_id, client_start_span.trace_id)
eq_('aiohttp.client', client_start_span.service)
eq_('ClientResponse.start', client_start_span.name)
eq_('/', client_start_span.resource)
finally:
aio_unpatch()
1 change: 0 additions & 1 deletion tests/contrib/aiohttp/test_request.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
from aiohttp.test_utils import unittest_run_loop

from ddtrace.pin import Pin
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.contrib.aiohttp.patch import patch, unpatch
from ddtrace.contrib.aiohttp.middlewares import trace_app

4 changes: 2 additions & 2 deletions tests/contrib/aiohttp/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import asyncio

from aiohttp.test_utils import AioHTTPTestCase

from .app.web import setup_app
from ddtrace.contrib.asyncio import context_provider
from ...base import BaseTracerTestCase


@@ -32,5 +31,6 @@ def get_app(self, loop=None):
# create the app with the testing loop
self.app = setup_app(loop)
# trace the app
self.tracer.configure(context_provider=context_provider)
self.enable_tracing()
return self.app