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

Feat: instrument aiohttp with trace_configs argument #1079

Merged
merged 18 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d96cbb3
feat(aiohttp-trace-configs): support trace_configs as an argument for…
nemoshlag Apr 28, 2022
24150c9
Merge branch 'open-telemetry:main' into feat/aiohttp-trace-configs
nemoshlag May 1, 2022
898bc7f
feat(aiohttp-trace-configs): test added trace config
nemoshlag May 1, 2022
e2c68c6
Merge remote-tracking branch 'origin/feat/aiohttp-trace-configs' into…
nemoshlag May 1, 2022
c25c53f
feat(aiohttp-trace-configs): add in code documentation
nemoshlag May 1, 2022
92c901c
feat(aiohttp-trace-configs): typo fix
nemoshlag May 1, 2022
855f270
Merge branch 'main' into feat/aiohttp-trace-configs
nemoshlag May 8, 2022
de86d90
feat(aiohttp-trace-configs): Add changelog entry
nemoshlag May 8, 2022
56fe090
feat(aiohttp-trace-configs): lint fix
nemoshlag May 8, 2022
a9da45a
feat(aiohttp-trace-configs): py backward computability fix
nemoshlag May 9, 2022
89b2b1d
feat(aiohttp-trace-configs): cr fixes
nemoshlag May 10, 2022
6ba255d
feat(aiohttp-trace-configs): cr fix
nemoshlag May 31, 2022
4a4c946
Merge branch 'main' into feat/aiohttp-trace-configs
nemoshlag May 31, 2022
18e0e79
Merge branch 'main' of github.com:epsagon/opentelemetry-python-contri…
nemoshlag Jun 19, 2022
29787c1
feat(aiohttp-trace-configs): test fix
nemoshlag Jun 25, 2022
b21a39e
Merge branch 'main' into feat/aiohttp-trace-configs
nemoshlag Jun 25, 2022
8bc6483
feat(aiohttp-trace-configs): cr fix
nemoshlag Jun 26, 2022
1deab73
Merge remote-tracking branch 'origin/feat/aiohttp-trace-configs' into…
nemoshlag Jun 26, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD)

### Added
- `opentelemetry-instrumentation-aiohttp-client` Add support for optional custom trace_configs argument.
([1079](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1079))
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved

### Fixed
- `opentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler
([1072](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1072))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def _instrument(
url_filter: _UrlFilterT = None,
request_hook: _RequestHookT = None,
response_hook: _ResponseHookT = None,
trace_configs: list = (),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value here is tuple, not list

):
"""Enables tracing of all ClientSessions

Expand All @@ -273,8 +274,6 @@ def instrumented_init(wrapped, instance, args, kwargs):
if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
return wrapped(*args, **kwargs)

trace_configs = list(kwargs.get("trace_configs") or ())
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved

trace_config = create_trace_config(
url_filter=url_filter,
request_hook=request_hook,
Expand Down Expand Up @@ -328,12 +327,15 @@ def _instrument(self, **kwargs):
such as API keys or user personal information.
``request_hook``: An optional callback that is invoked right after a span is created.
``response_hook``: An optional callback which is invoked right before the span is finished processing a response.
``trace_configs``: An optional list of aiohttp.TraceConfig items, allowing customize enrichment of spans
based on aiohttp events (see specification: https://docs.aiohttp.org/en/stable/tracing_reference.html)
"""
_instrument(
tracer_provider=kwargs.get("tracer_provider"),
url_filter=kwargs.get("url_filter"),
request_hook=kwargs.get("request_hook"),
response_hook=kwargs.get("response_hook"),
trace_configs=list(kwargs.get("trace_configs")),
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
)

def _uninstrument(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,19 @@ async def create_session(server: aiohttp.test_utils.TestServer):
run_with_test_server(create_session, self.URL, self.default_handler)
self.assert_spans(1)

def test_instrument_with_custom_trace_config(self):
AioHttpClientInstrumentor().uninstrument()
self.assert_spans(0)
AioHttpClientInstrumentor().instrument(
trace_config=aiohttp_client.create_trace_config()
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
)

run_with_test_server(
self.get_default_request(), self.URL, self.default_handler
)

self.assert_spans(2)

def test_uninstrument(self):
AioHttpClientInstrumentor().uninstrument()
run_with_test_server(
Expand Down