Skip to content

Commit

Permalink
imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Jun 20, 2024
1 parent 6df07da commit a666968
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
)
from opentelemetry.instrumentation._semconv import (
_get_schema_url,
_HTTPStabilityMode,
_OpenTelemetrySemanticConventionStability,
_OpenTelemetryStabilitySignalType,
_report_new,
Expand All @@ -228,10 +229,19 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
create_http_server_response_body_size,
)
from opentelemetry.semconv.metrics import MetricInstruments
from opentelemetry.semconv.attributes.client_attributes import CLIENT_PORT
from opentelemetry.semconv.metrics.http_metrics import (
HTTP_SERVER_REQUEST_DURATION,
)
from opentelemetry.semconv.attributes.client_attributes import (
CLIENT_ADDRESS,
CLIENT_PORT,
)
from opentelemetry.semconv.attributes.http_attributes import (
HTTP_REQUEST_METHOD,
)
from opentelemetry.semconv.attributes.network_attributes import (
NETWORK_PROTOCOL_VERSION
)
from opentelemetry.semconv.attributes.server_attributes import (
SERVER_ADDRESS,
SERVER_PORT,
Expand All @@ -240,6 +250,9 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
URL_FULL,
URL_SCHEME,
)
from opentelemetry.semconv.attributes.user_agent_attributes import (
USER_AGENT_ORIGINAL,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import set_span_in_context
from opentelemetry.trace.status import Status, StatusCode
Expand Down Expand Up @@ -319,7 +332,7 @@ def set(
asgi_setter = ASGISetter()


def collect_request_attributes(scope, sem_conv_opt_in_mode):
def collect_request_attributes(scope, sem_conv_opt_in_mode=_HTTPStabilityMode.DEFAULT):
"""Collects HTTP request attributes from the ASGI scope and returns a
dictionary to be used as span creation attributes."""
server_host, port, http_url = get_host_port_url_tuple(scope)
Expand Down Expand Up @@ -371,7 +384,7 @@ def collect_request_attributes(scope, sem_conv_opt_in_mode):
result[SpanAttributes.NET_PEER_IP] = scope.get("client")[0]
result[SpanAttributes.NET_PEER_PORT] = scope.get("client")[1]
if _report_new(sem_conv_opt_in_mode):
result[CLIENT_SOCKET_ADDRESS] = scope.get("client")[0]
result[CLIENT_ADDRESS] = scope.get("client")[0]
result[CLIENT_PORT] = scope.get("client")[1]

# remove None values
Expand Down

0 comments on commit a666968

Please sign in to comment.