mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 14:11:50 +08:00
Bump black to 24.3.0 (#2452)
This commit is contained in:

committed by
GitHub

parent
1cd8ccb28a
commit
a0c3211c4f
4
.flake8
4
.flake8
@ -12,6 +12,10 @@ ignore =
|
||||
# allow whitespace before ':' (https://github.com/psf/black#slices)
|
||||
E203
|
||||
|
||||
# conflicts with black
|
||||
E701
|
||||
E704
|
||||
|
||||
exclude =
|
||||
.bzr
|
||||
.git
|
||||
|
@ -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
|
||||
|
@ -34,13 +34,13 @@ if _descriptor._USE_C_DESCRIPTORS == False:
|
||||
DESCRIPTOR._options = None
|
||||
DESCRIPTOR._serialized_options = b"Z\006prompb"
|
||||
_WRITEREQUEST.fields_by_name["timeseries"]._options = None
|
||||
_WRITEREQUEST.fields_by_name[
|
||||
"timeseries"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_WRITEREQUEST.fields_by_name["timeseries"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_WRITEREQUEST.fields_by_name["metadata"]._options = None
|
||||
_WRITEREQUEST.fields_by_name[
|
||||
"metadata"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_WRITEREQUEST.fields_by_name["metadata"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_WRITEREQUEST._serialized_start = 216
|
||||
_WRITEREQUEST._serialized_end = 338
|
||||
_READREQUEST._serialized_start = 341
|
||||
|
@ -31,31 +31,31 @@ if _descriptor._USE_C_DESCRIPTORS == False:
|
||||
DESCRIPTOR._options = None
|
||||
DESCRIPTOR._serialized_options = b"Z\006prompb"
|
||||
_EXEMPLAR.fields_by_name["labels"]._options = None
|
||||
_EXEMPLAR.fields_by_name[
|
||||
"labels"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_EXEMPLAR.fields_by_name["labels"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_TIMESERIES.fields_by_name["labels"]._options = None
|
||||
_TIMESERIES.fields_by_name[
|
||||
"labels"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_TIMESERIES.fields_by_name["labels"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_TIMESERIES.fields_by_name["samples"]._options = None
|
||||
_TIMESERIES.fields_by_name[
|
||||
"samples"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_TIMESERIES.fields_by_name["samples"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_TIMESERIES.fields_by_name["exemplars"]._options = None
|
||||
_TIMESERIES.fields_by_name[
|
||||
"exemplars"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_TIMESERIES.fields_by_name["exemplars"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_LABELS.fields_by_name["labels"]._options = None
|
||||
_LABELS.fields_by_name["labels"]._serialized_options = b"\310\336\037\000"
|
||||
_CHUNKEDSERIES.fields_by_name["labels"]._options = None
|
||||
_CHUNKEDSERIES.fields_by_name[
|
||||
"labels"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_CHUNKEDSERIES.fields_by_name["labels"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_CHUNKEDSERIES.fields_by_name["chunks"]._options = None
|
||||
_CHUNKEDSERIES.fields_by_name[
|
||||
"chunks"
|
||||
]._serialized_options = b"\310\336\037\000"
|
||||
_CHUNKEDSERIES.fields_by_name["chunks"]._serialized_options = (
|
||||
b"\310\336\037\000"
|
||||
)
|
||||
_METRICMETADATA._serialized_start = 152
|
||||
_METRICMETADATA._serialized_end = 400
|
||||
_METRICMETADATA_METRICTYPE._serialized_start = 279
|
||||
|
@ -695,9 +695,9 @@ class OpenTelemetryMiddleware:
|
||||
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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -62,9 +62,9 @@ class _OpInvoke(_LambdaOperation):
|
||||
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
|
||||
|
@ -76,9 +76,9 @@ class _OpPublish(_SnsOperation):
|
||||
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
|
||||
|
@ -35,9 +35,9 @@ class _SqsExtension(_AwsSdkExtension):
|
||||
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'",
|
||||
|
@ -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):
|
||||
@ -229,9 +229,9 @@ class _DjangoMiddleware(MiddlewareMixin):
|
||||
)
|
||||
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():
|
||||
@ -336,9 +336,9 @@ class _DjangoMiddleware(MiddlewareMixin):
|
||||
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:
|
||||
|
@ -83,20 +83,26 @@ class _QueryWrapper:
|
||||
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.
|
||||
|
@ -155,9 +155,11 @@ class TestMiddleware(WsgiTestBase):
|
||||
|
||||
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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -247,9 +247,9 @@ def _wrap_perform_request(
|
||||
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:
|
||||
|
@ -382,9 +382,9 @@ class _InstrumentedFalconAPI(getattr(falcon, _instrument_app)):
|
||||
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)
|
||||
|
@ -334,9 +334,9 @@ def _rewrapped_app(
|
||||
)
|
||||
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
|
||||
@ -641,9 +641,9 @@ class FlaskInstrumentor(BaseInstrumentor):
|
||||
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)
|
||||
|
@ -76,15 +76,15 @@ class InstrumentationTest:
|
||||
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
|
||||
|
||||
|
@ -142,7 +142,7 @@ Request = _reflection.GeneratedProtocolMessageType(
|
||||
(_message.Message,),
|
||||
{
|
||||
"DESCRIPTOR": _REQUEST,
|
||||
"__module__": "test_server_pb2"
|
||||
"__module__": "test_server_pb2",
|
||||
# @@protoc_insertion_point(class_scope:Request)
|
||||
},
|
||||
)
|
||||
@ -153,7 +153,7 @@ Response = _reflection.GeneratedProtocolMessageType(
|
||||
(_message.Message,),
|
||||
{
|
||||
"DESCRIPTOR": _RESPONSE,
|
||||
"__module__": "test_server_pb2"
|
||||
"__module__": "test_server_pb2",
|
||||
# @@protoc_insertion_point(class_scope:Response)
|
||||
},
|
||||
)
|
||||
|
@ -433,9 +433,7 @@ class AsyncOpenTelemetryTransport(httpx.AsyncBaseTransport):
|
||||
) -> None:
|
||||
await self._transport.__aexit__(exc_type, exc_value, traceback)
|
||||
|
||||
async def handle_async_request(
|
||||
self, *args, **kwargs
|
||||
) -> typing.Union[
|
||||
async def handle_async_request(self, *args, **kwargs) -> typing.Union[
|
||||
typing.Tuple[int, "Headers", httpx.AsyncByteStream, dict],
|
||||
httpx.Response,
|
||||
]:
|
||||
|
@ -156,9 +156,9 @@ class PikaInstrumentor(BaseInstrumentor): # type: ignore
|
||||
callback_attr = PikaInstrumentor.CONSUMER_CALLBACK_ATTR
|
||||
consumer_callback = getattr(client_info, callback_attr, None)
|
||||
if hasattr(consumer_callback, "_original_callback"):
|
||||
channel._consumer_infos[
|
||||
consumers_tag
|
||||
] = consumer_callback._original_callback
|
||||
channel._consumer_infos[consumers_tag] = (
|
||||
consumer_callback._original_callback
|
||||
)
|
||||
PikaInstrumentor._uninstrument_channel_functions(channel)
|
||||
|
||||
def _decorate_channel_function(
|
||||
|
@ -38,8 +38,7 @@ _pika_getter = _PikaGetter()
|
||||
HookT = Callable[[Span, bytes, BasicProperties], None]
|
||||
|
||||
|
||||
def dummy_callback(span: Span, body: bytes, properties: BasicProperties):
|
||||
...
|
||||
def dummy_callback(span: Span, body: bytes, properties: BasicProperties): ...
|
||||
|
||||
|
||||
def _decorate_callback(
|
||||
@ -66,9 +65,9 @@ def _decorate_callback(
|
||||
tracer,
|
||||
channel,
|
||||
properties,
|
||||
destination=method.exchange
|
||||
if method.exchange
|
||||
else method.routing_key,
|
||||
destination=(
|
||||
method.exchange if method.exchange else method.routing_key
|
||||
),
|
||||
span_kind=SpanKind.CONSUMER,
|
||||
task_name=task_name,
|
||||
operation=MessagingOperationValues.RECEIVE,
|
||||
@ -243,9 +242,11 @@ class ReadyMessagesDequeProxy(ObjectProxy):
|
||||
self._self_tracer,
|
||||
None,
|
||||
properties,
|
||||
destination=method.exchange
|
||||
if method.exchange
|
||||
else method.routing_key,
|
||||
destination=(
|
||||
method.exchange
|
||||
if method.exchange
|
||||
else method.routing_key
|
||||
),
|
||||
span_kind=SpanKind.CONSUMER,
|
||||
task_name=self._self_queue_consumer_generator.consumer_tag,
|
||||
operation=MessagingOperationValues.RECEIVE,
|
||||
|
@ -162,14 +162,14 @@ def _get_address_attributes(instance):
|
||||
host, port = instance.server
|
||||
address_attributes[SpanAttributes.NET_PEER_NAME] = host
|
||||
address_attributes[SpanAttributes.NET_PEER_PORT] = port
|
||||
address_attributes[
|
||||
SpanAttributes.NET_TRANSPORT
|
||||
] = NetTransportValues.IP_TCP.value
|
||||
address_attributes[SpanAttributes.NET_TRANSPORT] = (
|
||||
NetTransportValues.IP_TCP.value
|
||||
)
|
||||
elif isinstance(instance.server, str):
|
||||
address_attributes[SpanAttributes.NET_PEER_NAME] = instance.server
|
||||
address_attributes[
|
||||
SpanAttributes.NET_TRANSPORT
|
||||
] = NetTransportValues.OTHER.value
|
||||
address_attributes[SpanAttributes.NET_TRANSPORT] = (
|
||||
NetTransportValues.OTHER.value
|
||||
)
|
||||
|
||||
return address_attributes
|
||||
|
||||
|
@ -98,8 +98,7 @@ ResponseHookT = Callable[[Span, monitoring.CommandSucceededEvent], None]
|
||||
FailedHookT = Callable[[Span, monitoring.CommandFailedEvent], None]
|
||||
|
||||
|
||||
def dummy_callback(span, event):
|
||||
...
|
||||
def dummy_callback(span, event): ...
|
||||
|
||||
|
||||
class CommandTracer(monitoring.CommandListener):
|
||||
|
@ -106,9 +106,9 @@ def _before_traversal(event):
|
||||
if span.is_recording():
|
||||
attributes = otel_wsgi.collect_request_attributes(request_environ)
|
||||
if request.matched_route:
|
||||
attributes[
|
||||
SpanAttributes.HTTP_ROUTE
|
||||
] = request.matched_route.pattern
|
||||
attributes[SpanAttributes.HTTP_ROUTE] = (
|
||||
request.matched_route.pattern
|
||||
)
|
||||
for key, value in attributes.items():
|
||||
span.set_attribute(key, value)
|
||||
if span.kind == trace.SpanKind.SERVER:
|
||||
@ -201,9 +201,9 @@ def trace_tween_factory(handler, registry):
|
||||
status = getattr(response, "status", status)
|
||||
status_code = otel_wsgi._parse_status_code(status)
|
||||
if status_code is not None:
|
||||
duration_attrs[
|
||||
SpanAttributes.HTTP_STATUS_CODE
|
||||
] = otel_wsgi._parse_status_code(status)
|
||||
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
|
||||
otel_wsgi._parse_status_code(status)
|
||||
)
|
||||
duration_histogram.record(duration, duration_attrs)
|
||||
active_requests_counter.add(-1, active_requests_count_attrs)
|
||||
span = request.environ.get(_ENVIRON_SPAN_KEY)
|
||||
|
@ -36,14 +36,14 @@ def _extract_conn_attributes(conn_kwargs):
|
||||
attributes[SpanAttributes.NET_PEER_PORT] = conn_kwargs.get(
|
||||
"port", 6379
|
||||
)
|
||||
attributes[
|
||||
SpanAttributes.NET_TRANSPORT
|
||||
] = NetTransportValues.IP_TCP.value
|
||||
attributes[SpanAttributes.NET_TRANSPORT] = (
|
||||
NetTransportValues.IP_TCP.value
|
||||
)
|
||||
except KeyError:
|
||||
attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get("path", "")
|
||||
attributes[
|
||||
SpanAttributes.NET_TRANSPORT
|
||||
] = NetTransportValues.OTHER.value
|
||||
attributes[SpanAttributes.NET_TRANSPORT] = (
|
||||
NetTransportValues.OTHER.value
|
||||
)
|
||||
|
||||
return attributes
|
||||
|
||||
|
@ -189,9 +189,9 @@ def _instrument(
|
||||
sem_conv_opt_in_mode,
|
||||
)
|
||||
# Use semconv library when available
|
||||
span_attributes[
|
||||
_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS
|
||||
] = parsed_url.hostname
|
||||
span_attributes[_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS] = (
|
||||
parsed_url.hostname
|
||||
)
|
||||
if parsed_url.port:
|
||||
_set_http_peer_port_client(
|
||||
metric_labels, parsed_url.port, sem_conv_opt_in_mode
|
||||
@ -201,9 +201,9 @@ def _instrument(
|
||||
span_attributes, parsed_url.port, sem_conv_opt_in_mode
|
||||
)
|
||||
# Use semconv library when available
|
||||
span_attributes[
|
||||
_SPAN_ATTRIBUTES_NETWORK_PEER_PORT
|
||||
] = parsed_url.port
|
||||
span_attributes[_SPAN_ATTRIBUTES_NETWORK_PEER_PORT] = (
|
||||
parsed_url.port
|
||||
)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@ -413,9 +413,11 @@ class RequestsInstrumentor(BaseInstrumentor):
|
||||
duration_histogram_new,
|
||||
request_hook=kwargs.get("request_hook"),
|
||||
response_hook=kwargs.get("response_hook"),
|
||||
excluded_urls=_excluded_urls_from_env
|
||||
if excluded_urls is None
|
||||
else parse_excluded_urls(excluded_urls),
|
||||
excluded_urls=(
|
||||
_excluded_urls_from_env
|
||||
if excluded_urls is None
|
||||
else parse_excluded_urls(excluded_urls)
|
||||
),
|
||||
sem_conv_opt_in_mode=semconv_opt_in_mode,
|
||||
)
|
||||
|
||||
|
@ -296,18 +296,18 @@ def _get_attributes_from_cursor(vendor, cursor, attrs):
|
||||
is_unix_socket = info.host and info.host.startswith("/")
|
||||
|
||||
if is_unix_socket:
|
||||
attrs[
|
||||
SpanAttributes.NET_TRANSPORT
|
||||
] = NetTransportValues.OTHER.value
|
||||
attrs[SpanAttributes.NET_TRANSPORT] = (
|
||||
NetTransportValues.OTHER.value
|
||||
)
|
||||
if info.port:
|
||||
# postgresql enforces this pattern on all socket names
|
||||
attrs[SpanAttributes.NET_PEER_NAME] = os.path.join(
|
||||
info.host, f".s.PGSQL.{info.port}"
|
||||
)
|
||||
else:
|
||||
attrs[
|
||||
SpanAttributes.NET_TRANSPORT
|
||||
] = NetTransportValues.IP_TCP.value
|
||||
attrs[SpanAttributes.NET_TRANSPORT] = (
|
||||
NetTransportValues.IP_TCP.value
|
||||
)
|
||||
attrs[SpanAttributes.NET_PEER_NAME] = info.host
|
||||
if info.port:
|
||||
attrs[SpanAttributes.NET_PEER_PORT] = int(info.port)
|
||||
|
@ -481,9 +481,11 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
||||
if hasattr(system_swap, metric):
|
||||
self._system_swap_utilization_labels["state"] = metric
|
||||
yield Observation(
|
||||
getattr(system_swap, metric) / system_swap.total
|
||||
if system_swap.total
|
||||
else 0,
|
||||
(
|
||||
getattr(system_swap, metric) / system_swap.total
|
||||
if system_swap.total
|
||||
else 0
|
||||
),
|
||||
self._system_swap_utilization_labels.copy(),
|
||||
)
|
||||
|
||||
@ -556,9 +558,9 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
||||
for metric in self._config["system.network.dropped.packets"]:
|
||||
in_out = {"receive": "in", "transmit": "out"}[metric]
|
||||
if hasattr(counters, f"drop{in_out}"):
|
||||
self._system_network_dropped_packets_labels[
|
||||
"device"
|
||||
] = device
|
||||
self._system_network_dropped_packets_labels["device"] = (
|
||||
device
|
||||
)
|
||||
self._system_network_dropped_packets_labels[
|
||||
"direction"
|
||||
] = metric
|
||||
@ -629,9 +631,9 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
||||
1: "tcp",
|
||||
2: "udp",
|
||||
}[net_connection.type.value]
|
||||
self._system_network_connections_labels[
|
||||
"state"
|
||||
] = net_connection.status
|
||||
self._system_network_connections_labels["state"] = (
|
||||
net_connection.status
|
||||
)
|
||||
self._system_network_connections_labels[metric] = getattr(
|
||||
net_connection, metric
|
||||
)
|
||||
|
@ -455,9 +455,9 @@ def _get_attributes_from_request(request):
|
||||
if hasattr(request.connection, "context") and getattr(
|
||||
request.connection.context, "_orig_remote_ip", None
|
||||
):
|
||||
attrs[
|
||||
SpanAttributes.NET_PEER_IP
|
||||
] = request.connection.context._orig_remote_ip
|
||||
attrs[SpanAttributes.NET_PEER_IP] = (
|
||||
request.connection.context._orig_remote_ip
|
||||
)
|
||||
|
||||
return extract_attributes_from_object(
|
||||
request, _traced_request_attrs, attrs
|
||||
|
@ -229,17 +229,17 @@ class TortoiseORMInstrumentor(BaseInstrumentor):
|
||||
capabilities = getattr(connection, "capabilities", None)
|
||||
if capabilities is not None:
|
||||
if capabilities.dialect == "sqlite":
|
||||
span_attributes[
|
||||
SpanAttributes.DB_SYSTEM
|
||||
] = DbSystemValues.SQLITE.value
|
||||
span_attributes[SpanAttributes.DB_SYSTEM] = (
|
||||
DbSystemValues.SQLITE.value
|
||||
)
|
||||
elif capabilities.dialect == "postgres":
|
||||
span_attributes[
|
||||
SpanAttributes.DB_SYSTEM
|
||||
] = DbSystemValues.POSTGRESQL.value
|
||||
span_attributes[SpanAttributes.DB_SYSTEM] = (
|
||||
DbSystemValues.POSTGRESQL.value
|
||||
)
|
||||
elif capabilities.dialect == "mysql":
|
||||
span_attributes[
|
||||
SpanAttributes.DB_SYSTEM
|
||||
] = DbSystemValues.MYSQL.value
|
||||
span_attributes[SpanAttributes.DB_SYSTEM] = (
|
||||
DbSystemValues.MYSQL.value
|
||||
)
|
||||
dbname = getattr(connection, "filename", None)
|
||||
if dbname:
|
||||
span_attributes[SpanAttributes.DB_NAME] = dbname
|
||||
|
@ -156,9 +156,11 @@ class URLLibInstrumentor(BaseInstrumentor):
|
||||
histograms,
|
||||
request_hook=kwargs.get("request_hook"),
|
||||
response_hook=kwargs.get("response_hook"),
|
||||
excluded_urls=_excluded_urls_from_env
|
||||
if excluded_urls is None
|
||||
else parse_excluded_urls(excluded_urls),
|
||||
excluded_urls=(
|
||||
_excluded_urls_from_env
|
||||
if excluded_urls is None
|
||||
else parse_excluded_urls(excluded_urls)
|
||||
),
|
||||
)
|
||||
|
||||
def _uninstrument(self, **kwargs):
|
||||
@ -251,9 +253,9 @@ def _instrument(
|
||||
|
||||
ver_ = str(getattr(result, "version", ""))
|
||||
if ver_:
|
||||
labels[
|
||||
SpanAttributes.HTTP_FLAVOR
|
||||
] = f"{ver_[:1]}.{ver_[:-1]}"
|
||||
labels[SpanAttributes.HTTP_FLAVOR] = (
|
||||
f"{ver_[:1]}.{ver_[:-1]}"
|
||||
)
|
||||
|
||||
_record_histograms(
|
||||
histograms, labels, request, result, elapsed_time
|
||||
|
@ -200,9 +200,11 @@ class URLLib3Instrumentor(BaseInstrumentor):
|
||||
request_hook=kwargs.get("request_hook"),
|
||||
response_hook=kwargs.get("response_hook"),
|
||||
url_filter=kwargs.get("url_filter"),
|
||||
excluded_urls=_excluded_urls_from_env
|
||||
if excluded_urls is None
|
||||
else parse_excluded_urls(excluded_urls),
|
||||
excluded_urls=(
|
||||
_excluded_urls_from_env
|
||||
if excluded_urls is None
|
||||
else parse_excluded_urls(excluded_urls)
|
||||
),
|
||||
)
|
||||
|
||||
def _uninstrument(self, **kwargs):
|
||||
|
@ -252,9 +252,9 @@ class TestWsgiApplication(WsgiTestBase):
|
||||
if old_sem_conv:
|
||||
expected_attributes[SpanAttributes.HTTP_METHOD] = http_method
|
||||
if new_sem_conv:
|
||||
expected_attributes[
|
||||
SpanAttributes.HTTP_REQUEST_METHOD
|
||||
] = http_method
|
||||
expected_attributes[SpanAttributes.HTTP_REQUEST_METHOD] = (
|
||||
http_method
|
||||
)
|
||||
self.assertEqual(span_list[0].attributes, expected_attributes)
|
||||
|
||||
def test_basic_wsgi_call(self):
|
||||
@ -562,9 +562,9 @@ class TestWsgiAttributes(unittest.TestCase):
|
||||
parts.path, 1
|
||||
)[1]
|
||||
if parts.query:
|
||||
expected_new[
|
||||
SpanAttributes.URL_QUERY
|
||||
] = expected_url.split(parts.query, 1)[1]
|
||||
expected_new[SpanAttributes.URL_QUERY] = (
|
||||
expected_url.split(parts.query, 1)[1]
|
||||
)
|
||||
else:
|
||||
expected_new[SpanAttributes.HTTP_URL] = expected_url
|
||||
if has_host:
|
||||
@ -710,9 +710,9 @@ class TestWsgiAttributes(unittest.TestCase):
|
||||
def test_request_attributes_with_full_request_uri(self):
|
||||
self.environ["HTTP_HOST"] = "127.0.0.1:8080"
|
||||
self.environ["REQUEST_METHOD"] = "CONNECT"
|
||||
self.environ[
|
||||
"REQUEST_URI"
|
||||
] = "http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#url-parsing" # Might happen in a CONNECT request
|
||||
self.environ["REQUEST_URI"] = (
|
||||
"http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#url-parsing" # Might happen in a CONNECT request
|
||||
)
|
||||
expected_old = {
|
||||
SpanAttributes.HTTP_HOST: "127.0.0.1:8080",
|
||||
SpanAttributes.HTTP_TARGET: "http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#url-parsing",
|
||||
|
@ -368,16 +368,16 @@ def _set_status(
|
||||
span.set_attribute(
|
||||
SpanAttributes.HTTP_RESPONSE_STATUS_CODE, status_code
|
||||
)
|
||||
metrics_attributes[
|
||||
SpanAttributes.HTTP_RESPONSE_STATUS_CODE
|
||||
] = status_code
|
||||
metrics_attributes[SpanAttributes.HTTP_RESPONSE_STATUS_CODE] = (
|
||||
status_code
|
||||
)
|
||||
if status == StatusCode.ERROR:
|
||||
span.set_attribute(
|
||||
_SPAN_ATTRIBUTES_ERROR_TYPE, status_code_str
|
||||
)
|
||||
metrics_attributes[
|
||||
_SPAN_ATTRIBUTES_ERROR_TYPE
|
||||
] = status_code_str
|
||||
metrics_attributes[_SPAN_ATTRIBUTES_ERROR_TYPE] = (
|
||||
status_code_str
|
||||
)
|
||||
span.set_status(Status(status))
|
||||
|
||||
|
||||
|
@ -98,9 +98,9 @@ class OTTracePropagator(TextMapPropagator):
|
||||
if not key.startswith(OT_BAGGAGE_PREFIX):
|
||||
continue
|
||||
|
||||
baggage[
|
||||
key[len(OT_BAGGAGE_PREFIX) :]
|
||||
] = _extract_first_element(getter.get(carrier, key))
|
||||
baggage[key[len(OT_BAGGAGE_PREFIX) :]] = (
|
||||
_extract_first_element(getter.get(carrier, key))
|
||||
)
|
||||
|
||||
for key, value in baggage.items():
|
||||
context = set_baggage(key, value, context)
|
||||
|
@ -47,19 +47,19 @@ class AzureAppServiceResourceDetector(ResourceDetector):
|
||||
website_site_name = environ.get(_WEBSITE_SITE_NAME)
|
||||
if website_site_name:
|
||||
attributes[ResourceAttributes.SERVICE_NAME] = website_site_name
|
||||
attributes[
|
||||
ResourceAttributes.CLOUD_PROVIDER
|
||||
] = CloudProviderValues.AZURE.value
|
||||
attributes[
|
||||
ResourceAttributes.CLOUD_PLATFORM
|
||||
] = CloudPlatformValues.AZURE_APP_SERVICE.value
|
||||
attributes[ResourceAttributes.CLOUD_PROVIDER] = (
|
||||
CloudProviderValues.AZURE.value
|
||||
)
|
||||
attributes[ResourceAttributes.CLOUD_PLATFORM] = (
|
||||
CloudPlatformValues.AZURE_APP_SERVICE.value
|
||||
)
|
||||
|
||||
azure_resource_uri = _get_azure_resource_uri(website_site_name)
|
||||
if azure_resource_uri:
|
||||
attributes[
|
||||
ResourceAttributes.CLOUD_RESOURCE_ID
|
||||
] = azure_resource_uri
|
||||
for (key, env_var) in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items():
|
||||
attributes[ResourceAttributes.CLOUD_RESOURCE_ID] = (
|
||||
azure_resource_uri
|
||||
)
|
||||
for key, env_var in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items():
|
||||
value = environ.get(env_var)
|
||||
if value:
|
||||
attributes[key] = value
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Test script to check given paths for valid README.rst files."""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
Reference in New Issue
Block a user