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

Update vendored instrumentations to 0.40b0 #31719

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@
"speced",
"pkgutils",
"psycopg",
"reqctx",
"uninstrument",
"uninstrumented"
]
Expand Down
2 changes: 2 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Unpin OTel SDK/API version
([#310](https://github.com/microsoft/ApplicationInsights-Python/pull/310))
- Update vendored instrumentations to 0.40b0
([#31719](https://github.com/Azure/azure-sdk-for-python/pull/31719))

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
SAMPLING_RATIO_ARG,
)
from azure.monitor.opentelemetry._types import ConfigurationValue
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.dependencies import (
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.instrumentation.dependencies import (
get_dependency_conflicts,
)
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.instrumentor import (
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.instrumentation.instrumentor import (
BaseInstrumentor,
)
from azure.monitor.opentelemetry.exporter import ( # pylint: disable=import-error
Expand All @@ -53,7 +53,7 @@
"psycopg2": ("psycopg2 >= 2.7.3.1",),
"requests": ("requests ~= 2.0",),
"urllib": tuple(),
"urllib3": ("urllib3 >= 1.0.0, < 2.0.0",),
"urllib3": ("urllib3 >= 1.0.0, < 3.0.0",),
}


Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
from asgiref.compatibility import guarantee_single_callable

from opentelemetry import context, trace
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.asgi.version import (
__version__
) # noqa
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.propagators import (
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.instrumentation.asgi.version import __version__ # noqa
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.instrumentation.propagators import (
get_global_response_propagator,
)
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.utils import (
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.instrumentation.utils import (
_start_internal_or_server_span,
http_status_to_status_code,
)
Expand All @@ -39,7 +37,7 @@
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import Span, set_span_in_context
from opentelemetry.trace.status import Status, StatusCode
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.util.http import (
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.util.http import (
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE,
Expand Down Expand Up @@ -213,7 +211,7 @@ def collect_custom_response_headers_attributes(message):

def get_host_port_url_tuple(scope):
"""Returns (host, port, full_url) tuple."""
server = scope.get("server") or ["0.0.0.0", 80] # nosec
server = scope.get("server") or ["0.0.0.0", 80]
port = server[1]
server_host = server[0] + (":" + str(port) if str(port) != "80" else "")
full_path = scope.get("root_path", "") + scope.get("path", "")
Expand Down Expand Up @@ -242,18 +240,23 @@ def set_status_code(span, status_code):


def get_default_span_details(scope: dict) -> Tuple[str, dict]:
"""Default implementation for get_default_span_details
"""
Default span name is the HTTP method and URL path, or just the method.
https://github.com/open-telemetry/opentelemetry-specification/pull/3165
https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/#name

Args:
scope: the ASGI scope dictionary
Returns:
a tuple of the span name, and any attributes to attach to the span.
"""
span_name = (
scope.get("path", "").strip()
or f"HTTP {scope.get('method', '').strip()}"
)

return span_name, {}
path = scope.get("path", "").strip()
method = scope.get("method", "").strip()
if method and path: # http
return f"{method} {path}", {}
if path: # websocket
return path, {}
return method, {} # http with no path


def _collect_target_attribute(
Expand Down Expand Up @@ -328,6 +331,16 @@ def __init__(
unit="ms",
description="measures the duration of the inbound HTTP request",
)
self.server_response_size_histogram = self.meter.create_histogram(
name=MetricInstruments.HTTP_SERVER_RESPONSE_SIZE,
unit="By",
description="measures the size of HTTP response messages (compressed).",
)
self.server_request_size_histogram = self.meter.create_histogram(
name=MetricInstruments.HTTP_SERVER_REQUEST_SIZE,
unit="By",
description="Measures the size of HTTP request messages (compressed).",
)
self.active_requests_counter = self.meter.create_up_down_counter(
name=MetricInstruments.HTTP_SERVER_ACTIVE_REQUESTS,
unit="requests",
Expand All @@ -340,6 +353,7 @@ def __init__(
self.server_request_hook = server_request_hook
self.client_request_hook = client_request_hook
self.client_response_hook = client_response_hook
self.content_length_header = None

async def __call__(self, scope, receive, send):
"""The ASGI application
Expand Down Expand Up @@ -415,6 +429,20 @@ async def __call__(self, scope, receive, send):
self.active_requests_counter.add(
-1, active_requests_count_attrs
)
if self.content_length_header:
self.server_response_size_histogram.record(
self.content_length_header, duration_attrs
)
request_size = asgi_getter.get(scope, "content-length")
if request_size:
try:
request_size_amount = int(request_size[0])
except ValueError:
pass
else:
self.server_request_size_histogram.record(
request_size_amount, duration_attrs
)
if token:
context.detach(token)

Expand Down Expand Up @@ -482,6 +510,13 @@ async def otel_send(message):
setter=asgi_setter,
)

content_length = asgi_getter.get(message, "content-length")
if content_length:
try:
self.content_length_header = int(content_length[0])
except ValueError:
pass

await send(message)

return otel_send
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.39b0"
__version__ = "0.40b0"
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

from pkg_resources import iter_entry_points

from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.version import (
__version__
)
from azure.monitor.opentelemetry._vendor.v0_40b0.opentelemetry.instrumentation.version import __version__

_logger = getLogger(__name__)

Expand Down
Loading