Skip to content

Commit

Permalink
Merge branch 'main' into fix-issue-2399
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrobologna authored Apr 23, 2024
2 parents eaad671 + a0c3211 commit 4cf1194
Show file tree
Hide file tree
Showing 38 changed files with 224 additions and 210 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ ignore =
# allow whitespace before ':' (https://github.com/psf/black#slices)
E203

# conflicts with black
E701
E704

exclude =
.bzr
.git
Expand Down
15 changes: 5 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Use sqlalchemy version in sqlalchemy commenter instead of opentelemetry library version
([#2404](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2404))

### Added

- `opentelemetry-instrumentation-pika` Instrumentation for `channel.consume()` (supported
only for global, non channel specific instrumentation)
([#2397](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2397)))


### Breaking changes

- Rename `type` attribute to `asgi.event.type` in `opentelemetry-instrumentation-asgi`
Expand All @@ -35,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2425](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2425))
- `opentelemetry-instrumentation-threading` Initial release for threading
([#2253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2253))
- `opentelemetry-instrumentation-pika` Instrumentation for `channel.consume()` (supported
only for global, non channel specific instrumentation)
([#2397](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2397)))

### Fixed

Expand All @@ -53,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2425](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2425))
- `opentelemetry-instrumentation-threading` Initial release for threading
([#2253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2253))
- Use sqlalchemy version in sqlalchemy commenter instead of opentelemetry library version
([#2404](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2404))

## Version 1.24.0/0.45b0 (2024-03-28)

Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pylint==3.0.2
flake8==6.1.0
isort==5.12.0
black==22.3.0
black==24.3.0
httpretty==1.1.4
mypy==0.931
sphinx==7.1.2
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ async def otel_send(message: dict[str, Any]):
if send_span.is_recording():
if message["type"] == "http.response.start":
status_code = message["status"]
duration_attrs[
SpanAttributes.HTTP_STATUS_CODE
] = status_code
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
status_code
)
set_status_code(server_span, status_code)
set_status_code(send_span, status_code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:
if isinstance(addr, tuple):
span_attributes[SpanAttributes.NET_PEER_NAME] = addr[0]
span_attributes[SpanAttributes.NET_PEER_PORT] = addr[1]
span_attributes[
SpanAttributes.NET_TRANSPORT
] = NetTransportValues.IP_TCP.value
span_attributes[SpanAttributes.NET_TRANSPORT] = (
NetTransportValues.IP_TCP.value
)
elif isinstance(addr, str):
span_attributes[SpanAttributes.NET_PEER_NAME] = addr
span_attributes[
SpanAttributes.NET_TRANSPORT
] = NetTransportValues.OTHER.value
span_attributes[SpanAttributes.NET_TRANSPORT] = (
NetTransportValues.OTHER.value
)

if query is not None:
span_attributes[SpanAttributes.DB_STATEMENT] = query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def extract_attributes(
cls, call_context: _AwsSdkCallContext, attributes: _AttributeMapT
):
attributes[SpanAttributes.FAAS_INVOKED_PROVIDER] = "aws"
attributes[
SpanAttributes.FAAS_INVOKED_NAME
] = cls._parse_function_name(call_context)
attributes[SpanAttributes.FAAS_INVOKED_NAME] = (
cls._parse_function_name(call_context)
)
attributes[SpanAttributes.FAAS_INVOKED_REGION] = call_context.region

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def extract_attributes(
destination_name, is_phone_number = cls._extract_destination_name(
call_context
)
attributes[
SpanAttributes.MESSAGING_DESTINATION_KIND
] = MessagingDestinationKindValues.TOPIC.value
attributes[SpanAttributes.MESSAGING_DESTINATION_KIND] = (
MessagingDestinationKindValues.TOPIC.value
)
attributes[SpanAttributes.MESSAGING_DESTINATION] = destination_name

# TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when opentelemetry-semantic-conventions 0.42b0 is released
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def extract_attributes(self, attributes: _AttributeMapT):
attributes[SpanAttributes.MESSAGING_SYSTEM] = "aws.sqs"
attributes[SpanAttributes.MESSAGING_URL] = queue_url
try:
attributes[
SpanAttributes.MESSAGING_DESTINATION
] = queue_url.split("/")[-1]
attributes[SpanAttributes.MESSAGING_DESTINATION] = (
queue_url.split("/")[-1]
)
except IndexError:
_logger.error(
"Could not extract messaging destination from '%s'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ class _DjangoMiddleware(MiddlewareMixin):
_active_request_counter = None

_otel_request_hook: Callable[[Span, HttpRequest], None] = None
_otel_response_hook: Callable[
[Span, HttpRequest, HttpResponse], None
] = None
_otel_response_hook: Callable[[Span, HttpRequest, HttpResponse], None] = (
None
)

@staticmethod
def _get_span_name(request):
Expand Down Expand Up @@ -229,9 +229,9 @@ def process_request(self, request):
)
duration_attrs = _parse_duration_attrs(attributes)

request.META[
self._environ_active_request_attr_key
] = active_requests_count_attrs
request.META[self._environ_active_request_attr_key] = (
active_requests_count_attrs
)
request.META[self._environ_duration_attr_key] = duration_attrs
self._active_request_counter.add(1, active_requests_count_attrs)
if span.is_recording():
Expand Down Expand Up @@ -336,9 +336,9 @@ def process_response(self, request, response):
self._environ_duration_attr_key, None
)
if duration_attrs:
duration_attrs[
SpanAttributes.HTTP_STATUS_CODE
] = response.status_code
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
response.status_code
)
request_start_time = request.META.pop(self._environ_timer_key, None)

if activation and span:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,26 @@ def __call__(self, execute: Type[T], sql, params, many, context) -> T:
sql = _add_sql_comment(
sql,
# Information about the controller.
controller=resolver_match.view_name
if resolver_match and with_controller
else None,
controller=(
resolver_match.view_name
if resolver_match and with_controller
else None
),
# route is the pattern that matched a request with a controller i.e. the regex
# See https://docs.djangoproject.com/en/stable/ref/urlresolvers/#django.urls.ResolverMatch.route
# getattr() because the attribute doesn't exist in Django < 2.2.
route=getattr(resolver_match, "route", None)
if resolver_match and with_route
else None,
route=(
getattr(resolver_match, "route", None)
if resolver_match and with_route
else None
),
# app_name is the application namespace for the URL pattern that matches the URL.
# See https://docs.djangoproject.com/en/stable/ref/urlresolvers/#django.urls.ResolverMatch.app_name
app_name=(resolver_match.app_name or None)
if resolver_match and with_app_name
else None,
app_name=(
(resolver_match.app_name or None)
if resolver_match and with_app_name
else None
),
# Framework centric information.
framework=f"django:{_django_version}" if with_framework else None,
# Information about the database and driver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ def test_templated_route_get(self):

self.assertEqual(
span.name,
"GET ^route/(?P<year>[0-9]{4})/template/$"
if DJANGO_2_2
else "GET",
(
"GET ^route/(?P<year>[0-9]{4})/template/$"
if DJANGO_2_2
else "GET"
),
)
self.assertEqual(span.kind, SpanKind.SERVER)
self.assertEqual(span.status.status_code, StatusCode.UNSET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def response_with_custom_header(request):
response = HttpResponse()
response["custom-test-header-1"] = "test-header-value-1"
response["custom-test-header-2"] = "test-header-value-2"
response[
"my-custom-regex-header-1"
] = "my-custom-regex-value-1,my-custom-regex-value-2"
response[
"my-custom-regex-header-2"
] = "my-custom-regex-value-3,my-custom-regex-value-4"
response["my-custom-regex-header-1"] = (
"my-custom-regex-value-1,my-custom-regex-value-2"
)
response["my-custom-regex-header-2"] = (
"my-custom-regex-value-3,my-custom-regex-value-4"
)
response["my-secret-header"] = "my-secret-value"
return response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ def wrapper(wrapped, _, args, kwargs):
if body:
# Don't set db.statement for bulk requests, as it can be very large
if isinstance(body, dict):
attributes[
SpanAttributes.DB_STATEMENT
] = sanitize_body(body)
attributes[SpanAttributes.DB_STATEMENT] = (
sanitize_body(body)
)
if params:
attributes["elasticsearch.params"] = str(params)
if doc_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ def _start_response(status, response_headers, *args, **kwargs):
raise
finally:
if span.is_recording():
duration_attrs[
SpanAttributes.HTTP_STATUS_CODE
] = span.attributes.get(SpanAttributes.HTTP_STATUS_CODE)
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
span.attributes.get(SpanAttributes.HTTP_STATUS_CODE)
)
duration = max(round((default_timer() - start) * 1000), 0)
self.duration_histogram.record(duration, duration_attrs)
self.active_requests_counter.add(-1, active_requests_count_attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ def _start_response(status, response_headers, *args, **kwargs):
)
status_code = otel_wsgi._parse_status_code(status)
if status_code is not None:
duration_attrs[
SpanAttributes.HTTP_STATUS_CODE
] = status_code
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
status_code
)
if (
span.is_recording()
and span.kind == trace.SpanKind.SERVER
Expand Down Expand Up @@ -641,9 +641,9 @@ def instrument_app(
tracer,
excluded_urls=excluded_urls,
enable_commenter=enable_commenter,
commenter_options=commenter_options
if commenter_options
else {},
commenter_options=(
commenter_options if commenter_options else {}
),
)
app._before_request = _before_request
app.before_request(_before_request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def _custom_response_headers():
resp = flask.Response("test response")
resp.headers["content-type"] = "text/plain; charset=utf-8"
resp.headers["content-length"] = "13"
resp.headers[
"my-custom-header"
] = "my-custom-value-1,my-custom-header-2"
resp.headers[
"my-custom-regex-header-1"
] = "my-custom-regex-value-1,my-custom-regex-value-2"
resp.headers[
"My-Custom-Regex-Header-2"
] = "my-custom-regex-value-3,my-custom-regex-value-4"
resp.headers["my-custom-header"] = (
"my-custom-value-1,my-custom-header-2"
)
resp.headers["my-custom-regex-header-1"] = (
"my-custom-regex-value-1,my-custom-regex-value-2"
)
resp.headers["My-Custom-Regex-Header-2"] = (
"my-custom-regex-value-3,my-custom-regex-value-4"
)
resp.headers["my-secret-header"] = "my-secret-value"
return resp

Expand Down
Loading

0 comments on commit 4cf1194

Please sign in to comment.