Skip to content

Commit adedaef

Browse files
authored
Merge pull request #52 from dynatrace-oss/aiohttp-client-support
Add initial support for aiohttp client
2 parents 627a7d6 + d2f6ae9 commit adedaef

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ For most technologies, just import it in your code.
2222

2323
### Technologies supported:
2424

25+
- **aiohttp** (client)
2526
- **celery**
2627
- **concurrent.futures**
2728
- **confluent_kafka**

autodynatrace/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"tornado": True,
4848
"fastapi": True,
4949
"starlette": True,
50+
"aiohttp": True,
5051
}
5152

5253

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .wrapper import instrument
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import aiohttp
2+
import wrapt
3+
4+
from oneagent.common import DYNATRACE_HTTP_HEADER_NAME
5+
from ...log import logger
6+
from ...sdk import sdk
7+
8+
9+
def instrument():
10+
@wrapt.patch_function_wrapper("aiohttp.client", "ClientSession._request")
11+
async def dynatrace_request(wrapped, instance, args, kwargs):
12+
13+
method = args[0]
14+
url = args[1]
15+
headers = dict(kwargs.get("headers", {}))
16+
17+
with sdk.trace_outgoing_web_request(url, method, headers) as tracer:
18+
tag = tracer.outgoing_dynatrace_string_tag.decode()
19+
logger.debug("dynatrace - tracing {} '{}' with tag '{}'".format(method, url, tag))
20+
headers.update({DYNATRACE_HTTP_HEADER_NAME: tag})
21+
kwargs["headers"] = headers
22+
23+
response = await wrapped(*args, **kwargs)
24+
25+
tracer.set_status_code(response.status)
26+
tracer.add_response_headers(dict(response.headers))
27+
28+
return response

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="autodynatrace",
5-
version="1.0.80",
5+
version="1.0.81",
66
packages=find_packages(),
77
package_data={"autodynatrace": ["wrappers/*"]},
88
install_requires=["wrapt>=1.11.2", "oneagent-sdk>=1.3.0", "six>=1.10.0", "autowrapt>=1.0"],

0 commit comments

Comments
 (0)