Skip to content

Commit

Permalink
Merge branch 'main' into optional-send-receive-spans
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Aug 26, 2024
2 parents 6b2490a + 830397e commit 59ef359
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 174 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## Added
### Added

- `opentelemetry-instrumentation-kafka-python` Instrument temporary fork, kafka-python-ng
inside kafka-python's instrumentation
([#2537](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2537))
- `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-fastapi` Add ability to disable internal HTTP send and receive spans
([#2802](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2802))

## Breaking changes
### Breaking changes

- `opentelemetry-bootstrap` Remove `opentelemetry-instrumentation-aws-lambda` from the defaults instrumentations
([#2786](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2786))

## Fixed
### Fixed

- `opentelemetry-instrumentation-httpx` fix handling of async hooks
([#2823](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2823))
- `opentelemetry-instrumentation-system-metrics` fix `process.runtime.cpu.utilization` values to be shown in range of 0 to 1
([2812](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2812))
([#2812](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2812))
- `opentelemetry-instrumentation-fastapi` fix `fastapi` auto-instrumentation by removing `fastapi-slim` support, `fastapi-slim` itself is discontinued from maintainers
([2783](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2783))
([#2783](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2783))
- `opentelemetry-instrumentation-aws-lambda` Avoid exception when a handler is not present.
([#2750](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2750))
- `opentelemetry-instrumentation-django` Fix regression - `http.target` re-added back to old semconv duration metrics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import opentelemetry.instrumentation.asgi as otel_asgi
from opentelemetry.test.asgitestutil import AsgiTestBase
from opentelemetry.test.asgitestutil import AsyncAsgiTestBase
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import SpanKind
from opentelemetry.util.http import (
Expand Down Expand Up @@ -90,7 +104,7 @@ async def websocket_app_with_custom_headers(scope, receive, send):
break


class TestCustomHeaders(AsgiTestBase, TestBase):
class TestCustomHeaders(AsyncAsgiTestBase):
constructor_params = {}
__test__ = False

Expand All @@ -108,7 +122,7 @@ def setUp(self):
**self.constructor_params,
)

def test_http_custom_request_headers_in_span_attributes(self):
async def test_http_custom_request_headers_in_span_attributes(self):
self.scope["headers"].extend(
[
(b"custom-test-header-1", b"test-header-value-1"),
Expand All @@ -119,8 +133,8 @@ def test_http_custom_request_headers_in_span_attributes(self):
]
)
self.seed_app(self.app)
self.send_default_request()
self.get_all_output()
await self.send_default_request()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.request.header.custom_test_header_1": (
Expand All @@ -139,16 +153,16 @@ def test_http_custom_request_headers_in_span_attributes(self):
if span.kind == SpanKind.SERVER:
self.assertSpanHasAttributes(span, expected)

def test_http_repeat_request_headers_in_span_attributes(self):
async def test_http_repeat_request_headers_in_span_attributes(self):
self.scope["headers"].extend(
[
(b"custom-test-header-1", b"test-header-value-1"),
(b"custom-test-header-1", b"test-header-value-2"),
]
)
self.seed_app(self.app)
self.send_default_request()
self.get_all_output()
await self.send_default_request()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.request.header.custom_test_header_1": (
Expand All @@ -159,15 +173,15 @@ def test_http_repeat_request_headers_in_span_attributes(self):
span = next(span for span in span_list if span.kind == SpanKind.SERVER)
self.assertSpanHasAttributes(span, expected)

def test_http_custom_request_headers_not_in_span_attributes(self):
async def test_http_custom_request_headers_not_in_span_attributes(self):
self.scope["headers"].extend(
[
(b"custom-test-header-1", b"test-header-value-1"),
]
)
self.seed_app(self.app)
self.send_default_request()
self.get_all_output()
await self.send_default_request()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.request.header.custom_test_header_1": (
Expand All @@ -185,15 +199,15 @@ def test_http_custom_request_headers_not_in_span_attributes(self):
for key, _ in not_expected.items():
self.assertNotIn(key, span.attributes)

def test_http_custom_response_headers_in_span_attributes(self):
async def test_http_custom_response_headers_in_span_attributes(self):
self.app = otel_asgi.OpenTelemetryMiddleware(
http_app_with_custom_headers,
tracer_provider=self.tracer_provider,
**self.constructor_params,
)
self.seed_app(self.app)
self.send_default_request()
self.get_all_output()
await self.send_default_request()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.response.header.custom_test_header_1": (
Expand All @@ -214,15 +228,15 @@ def test_http_custom_response_headers_in_span_attributes(self):
if span.kind == SpanKind.SERVER:
self.assertSpanHasAttributes(span, expected)

def test_http_repeat_response_headers_in_span_attributes(self):
async def test_http_repeat_response_headers_in_span_attributes(self):
self.app = otel_asgi.OpenTelemetryMiddleware(
http_app_with_repeat_headers,
tracer_provider=self.tracer_provider,
**self.constructor_params,
)
self.seed_app(self.app)
self.send_default_request()
self.get_all_output()
await self.send_default_request()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.response.header.custom_test_header_1": (
Expand All @@ -233,15 +247,15 @@ def test_http_repeat_response_headers_in_span_attributes(self):
span = next(span for span in span_list if span.kind == SpanKind.SERVER)
self.assertSpanHasAttributes(span, expected)

def test_http_custom_response_headers_not_in_span_attributes(self):
async def test_http_custom_response_headers_not_in_span_attributes(self):
self.app = otel_asgi.OpenTelemetryMiddleware(
http_app_with_custom_headers,
tracer_provider=self.tracer_provider,
**self.constructor_params,
)
self.seed_app(self.app)
self.send_default_request()
self.get_all_output()
await self.send_default_request()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
not_expected = {
"http.response.header.custom_test_header_3": (
Expand All @@ -253,7 +267,7 @@ def test_http_custom_response_headers_not_in_span_attributes(self):
for key, _ in not_expected.items():
self.assertNotIn(key, span.attributes)

def test_websocket_custom_request_headers_in_span_attributes(self):
async def test_websocket_custom_request_headers_in_span_attributes(self):
self.scope = {
"type": "websocket",
"http_version": "1.1",
Expand All @@ -271,11 +285,11 @@ def test_websocket_custom_request_headers_in_span_attributes(self):
"server": ("127.0.0.1", 80),
}
self.seed_app(self.app)
self.send_input({"type": "websocket.connect"})
self.send_input({"type": "websocket.receive", "text": "ping"})
self.send_input({"type": "websocket.disconnect"})
await self.send_input({"type": "websocket.connect"})
await self.send_input({"type": "websocket.receive", "text": "ping"})
await self.send_input({"type": "websocket.disconnect"})

self.get_all_output()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.request.header.custom_test_header_1": (
Expand All @@ -294,7 +308,9 @@ def test_websocket_custom_request_headers_in_span_attributes(self):
if span.kind == SpanKind.SERVER:
self.assertSpanHasAttributes(span, expected)

def test_websocket_custom_request_headers_not_in_span_attributes(self):
async def test_websocket_custom_request_headers_not_in_span_attributes(
self,
):
self.scope = {
"type": "websocket",
"http_version": "1.1",
Expand All @@ -309,11 +325,11 @@ def test_websocket_custom_request_headers_not_in_span_attributes(self):
"server": ("127.0.0.1", 80),
}
self.seed_app(self.app)
self.send_input({"type": "websocket.connect"})
self.send_input({"type": "websocket.receive", "text": "ping"})
self.send_input({"type": "websocket.disconnect"})
await self.send_input({"type": "websocket.connect"})
await self.send_input({"type": "websocket.receive", "text": "ping"})
await self.send_input({"type": "websocket.disconnect"})

self.get_all_output()
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
not_expected = {
"http.request.header.custom_test_header_3": (
Expand All @@ -325,7 +341,7 @@ def test_websocket_custom_request_headers_not_in_span_attributes(self):
for key, _ in not_expected.items():
self.assertNotIn(key, span.attributes)

def test_websocket_custom_response_headers_in_span_attributes(self):
async def test_websocket_custom_response_headers_in_span_attributes(self):
self.scope = {
"type": "websocket",
"http_version": "1.1",
Expand All @@ -342,10 +358,10 @@ def test_websocket_custom_response_headers_in_span_attributes(self):
**self.constructor_params,
)
self.seed_app(self.app)
self.send_input({"type": "websocket.connect"})
self.send_input({"type": "websocket.receive", "text": "ping"})
self.send_input({"type": "websocket.disconnect"})
self.get_all_output()
await self.send_input({"type": "websocket.connect"})
await self.send_input({"type": "websocket.receive", "text": "ping"})
await self.send_input({"type": "websocket.disconnect"})
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
expected = {
"http.response.header.custom_test_header_1": (
Expand All @@ -366,7 +382,9 @@ def test_websocket_custom_response_headers_in_span_attributes(self):
if span.kind == SpanKind.SERVER:
self.assertSpanHasAttributes(span, expected)

def test_websocket_custom_response_headers_not_in_span_attributes(self):
async def test_websocket_custom_response_headers_not_in_span_attributes(
self,
):
self.scope = {
"type": "websocket",
"http_version": "1.1",
Expand All @@ -383,10 +401,10 @@ def test_websocket_custom_response_headers_not_in_span_attributes(self):
**self.constructor_params,
)
self.seed_app(self.app)
self.send_input({"type": "websocket.connect"})
self.send_input({"type": "websocket.receive", "text": "ping"})
self.send_input({"type": "websocket.disconnect"})
self.get_all_output()
await self.send_input({"type": "websocket.connect"})
await self.send_input({"type": "websocket.receive", "text": "ping"})
await self.send_input({"type": "websocket.disconnect"})
await self.get_all_output()
span_list = self.exporter.get_finished_spans()
not_expected = {
"http.response.header.custom_test_header_3": (
Expand Down
Loading

0 comments on commit 59ef359

Please sign in to comment.