Skip to content

Commit

Permalink
Rebase and apply @owais comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adamantike committed Sep 21, 2021
1 parent d204f39 commit cae7e53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `opentelemetry-instrumentation-elasticsearch` Added `response_hook` and `request_hook` callbacks
([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670))
- `opentelemetry-instrumentation-django` Add ASGI support
([#391](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/391))

### Added
- `opentelemetry-instrumentation-redis` added request_hook and response_hook callbacks passed as arguments to the instrument method.
Expand All @@ -33,10 +35,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `opentelemetry-sdk-extension-aws` Add AWS resource detectors to extension package
([#586](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/586))
- `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-aiohttp-client`, `openetelemetry-instrumentation-fastapi`,
`opentelemetry-instrumentation-starlette`, `opentelemetry-instrumentation-urllib`, `opentelemetry-instrumentation-urllib3` Added `request_hook` and `response_hook` callbacks
- `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-aiohttp-client`, `openetelemetry-instrumentation-fastapi`,
`opentelemetry-instrumentation-starlette`, `opentelemetry-instrumentation-urllib`, `opentelemetry-instrumentation-urllib3` Added `request_hook` and `response_hook` callbacks
([#576](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/576))

### Changed

- `opentelemetry-instrumentation-fastapi` Allow instrumentation of newer FastAPI versions.
Expand Down Expand Up @@ -100,8 +102,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `opentelemetry-instrumentation-httpx` Add `httpx` instrumentation
([#461](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/461))
- `opentelemetry-instrumentation-django` Add ASGI support
([#391](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/391))

## [0.22b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.3.0-0.22b0) - 2021-06-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ install_requires =

[options.extras_require]
asgi =
opentelemetry-instrumentation-asgi == 0.23.dev0
opentelemetry-instrumentation-asgi == 0.24b0
test =
opentelemetry-test == 0.24b0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __call__(self, request):
else:
ASGIRequest = None

# try/except block exclusive for optional ASGI imports.
try:
from opentelemetry.instrumentation.asgi import asgi_getter
from opentelemetry.instrumentation.asgi import (
Expand Down Expand Up @@ -166,7 +167,7 @@ def process_request(self, request):
return

is_asgi_request = _is_asgi_request(request)
if is_asgi_request and not _is_asgi_supported:
if not _is_asgi_supported and is_asgi_request:
return

# pylint:disable=W0212
Expand All @@ -175,9 +176,11 @@ def process_request(self, request):
request_meta = request.META

if is_asgi_request:
carrier = request.scope
carrier_getter = asgi_getter
collect_request_attributes = asgi_collect_request_attributes
else:
carrier = request_meta
carrier_getter = wsgi_getter
collect_request_attributes = wsgi_collect_request_attributes

Expand All @@ -191,36 +194,25 @@ def process_request(self, request):
),
)

if is_asgi_request:
attributes = collect_request_attributes(request.scope)
else:
attributes = collect_request_attributes(request_meta)
attributes = collect_request_attributes(carrier)

if span.is_recording():
attributes = extract_attributes_from_object(
request, self._traced_request_attrs, attributes
)
if is_asgi_request:
# ASGI requests include extra attributes in request.scope.headers. For this reason,
# we need to build an object with the union of `request` and `request.scope.headers`
# contents, for the extract_attributes_from_object function to be able to retrieve
# attributes from it.
# ASGI requests include extra attributes in request.scope.headers.
attributes = extract_attributes_from_object(
types.SimpleNamespace(
**{
**request.__dict__,
**{
name.decode("latin1"): value.decode("latin1")
for name, value in request.scope.get(
"headers", []
)
},
name.decode("latin1"): value.decode("latin1")
for name, value in request.scope.get("headers", [])
}
),
self._traced_request_attrs,
attributes,
)
else:
attributes = extract_attributes_from_object(
request, self._traced_request_attrs, attributes
)

for key, value in attributes.items():
span.set_attribute(key, value)

Expand Down Expand Up @@ -268,7 +260,7 @@ def process_response(self, request, response):
return response

is_asgi_request = _is_asgi_request(request)
if is_asgi_request and not _is_asgi_supported:
if not _is_asgi_supported and is_asgi_request:
return response

activation = request.META.pop(self._environ_activation_key, None)
Expand Down

0 comments on commit cae7e53

Please sign in to comment.