Skip to content

Commit 52ab589

Browse files
authored
Merge branch 'main' into tnorth/fix
2 parents 63c21c7 + 77170ea commit 52ab589

File tree

6 files changed

+81
-10
lines changed

6 files changed

+81
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- `opentelemetry-instrumentation-django`: improve docs for response_hook with examples of providing attributes from middlewares
3535
([#3923](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3923))
3636
- Update for Log SDK breaking changes. Rename InMemoryLogExporter to InMemoryLogRecordExporter in several tests
37-
([#3850](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3589))
37+
([#3589](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3589))
38+
- opentelemetry-instrumentation: allow to skip all instrumentations loading with a wildcard
39+
([#3967](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3967))
40+
- `opentelemetry-instrumentation-redis`: add missing copyright header for opentelemetry-instrumentation-redis
41+
([#3976](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3976))
3842

3943
### Fixed
4044

instrumentation-genai/opentelemetry-instrumentation-google-genai/tests/generate_content/nonstreaming_base.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from google.genai.types import GenerateContentConfig
2121
from pydantic import BaseModel, Field
2222

23-
from opentelemetry._events import Event
2423
from opentelemetry.instrumentation._semconv import (
2524
_OpenTelemetrySemanticConventionStability,
2625
_OpenTelemetryStabilitySignalType,
@@ -324,7 +323,7 @@ def test_new_semconv_record_completion_as_log(self):
324323
event.attributes,
325324
)
326325
else:
327-
attrs = {
326+
expected_event_attributes = {
328327
gen_ai_attributes.GEN_AI_INPUT_MESSAGES: (
329328
{
330329
"role": "user",
@@ -346,31 +345,27 @@ def test_new_semconv_record_completion_as_log(self):
346345
{"content": sys_instr, "type": "text"},
347346
),
348347
}
349-
expected_event = Event(
350-
"gen_ai.client.inference.operation.details",
351-
attributes=attrs,
352-
)
353348
self.assertEqual(
354349
event.attributes[
355350
gen_ai_attributes.GEN_AI_INPUT_MESSAGES
356351
],
357-
expected_event.attributes[
352+
expected_event_attributes[
358353
gen_ai_attributes.GEN_AI_INPUT_MESSAGES
359354
],
360355
)
361356
self.assertEqual(
362357
event.attributes[
363358
gen_ai_attributes.GEN_AI_OUTPUT_MESSAGES
364359
],
365-
expected_event.attributes[
360+
expected_event_attributes[
366361
gen_ai_attributes.GEN_AI_OUTPUT_MESSAGES
367362
],
368363
)
369364
self.assertEqual(
370365
event.attributes[
371366
gen_ai_attributes.GEN_AI_SYSTEM_INSTRUCTIONS
372367
],
373-
expected_event.attributes[
368+
expected_event_attributes[
374369
gen_ai_attributes.GEN_AI_SYSTEM_INSTRUCTIONS
375370
],
376371
)

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/custom_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
from __future__ import annotations
216

317
from typing import Any, Callable, TypeVar

opentelemetry-instrumentation/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#in
106106
If set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations.
107107
e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS="requests,django"
108108

109+
If the variables contains ``*`` as member no instrumentation will be enabled.
110+
109111
* ``OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH``
110112

111113
If set by the user to `patch_all` , opentelemetry instrument will call the gevent monkeypatching method ``patch_all``.

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/_load.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
_logger = getLogger(__name__)
3737

38+
SKIPPED_INSTRUMENTATIONS_WILDCARD = "*"
39+
3840

3941
class _EntryPointDistFinder:
4042
@cached_property
@@ -94,6 +96,9 @@ def _load_instrumentors(distro):
9496
entry_point.load()()
9597

9698
for entry_point in entry_points(group="opentelemetry_instrumentor"):
99+
if SKIPPED_INSTRUMENTATIONS_WILDCARD in package_to_exclude:
100+
break
101+
97102
if entry_point.name in package_to_exclude:
98103
_logger.debug(
99104
"Instrumentation skipped for library %s", entry_point.name

opentelemetry-instrumentation/tests/auto_instrumentation/test_load.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,54 @@ def test_entry_point_dist_finder(self):
492492
)
493493
# dist are not comparable, being truthy is enough
494494
self.assertTrue(new_entry_point_dist)
495+
496+
@patch.dict(
497+
"os.environ",
498+
{OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: "*"},
499+
)
500+
@patch(
501+
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
502+
)
503+
@patch(
504+
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
505+
)
506+
def test_no_instrumentor_called_with_wildcard(self, iter_mock, mock_dep):
507+
# Mock opentelemetry_pre_instrument entry points
508+
# pylint: disable=too-many-locals
509+
pre_ep_mock1 = Mock()
510+
pre_ep_mock1.name = "pre1"
511+
pre_mock1 = Mock()
512+
pre_ep_mock1.load.return_value = pre_mock1
513+
514+
# Mock opentelemetry_instrumentor entry points
515+
ep_mock1 = Mock()
516+
ep_mock1.name = "instr1"
517+
518+
# Mock opentelemetry_instrumentor entry points
519+
post_ep_mock1 = Mock()
520+
post_ep_mock1.name = "post1"
521+
post_mock1 = Mock()
522+
post_ep_mock1.load.return_value = post_mock1
523+
524+
distro_mock = Mock()
525+
526+
# Mock entry points in order
527+
iter_mock.side_effect = [
528+
(pre_ep_mock1,),
529+
(ep_mock1,),
530+
(post_ep_mock1,),
531+
]
532+
_load._load_instrumentors(distro_mock)
533+
534+
self.assertEqual(iter_mock.call_count, 3)
535+
536+
# All opentelemetry_pre_instrument entry points should be loaded
537+
pre_mock1.assert_called_once()
538+
539+
# No instrumentations should be loaded
540+
mock_dep.assert_not_called()
541+
distro_mock.load_instrumentor.assert_not_called()
542+
self.assertEqual(distro_mock.load_instrumentor.call_count, 0)
543+
544+
# All opentelemetry_post_instrument entry points should be loaded
545+
post_mock1.assert_called_once()

0 commit comments

Comments
 (0)