Skip to content

Commit d11e469

Browse files
authored
Merge branch 'main' into main
2 parents 71e83ef + 7bddbb5 commit d11e469

File tree

16 files changed

+146
-99
lines changed

16 files changed

+146
-99
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
([#2397](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2397)))
3737
- `opentelemetry-processor-baggage` Initial release
3838
([#2436](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2436))
39+
- `opentelemetry-processor-baggage` Add baggage key predicate
40+
([#2535](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2535))
3941

4042
### Fixed
4143

@@ -60,9 +62,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6062
([#2524](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2524))
6163
- `opentelemetry-instrumentation-asyncio` Check for __name__ attribute in the coroutine
6264
([#2521](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2521))
65+
- `opentelemetry-instrumentation-requests` Fix wrong time unit for duration histogram
66+
([#2553](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2553))
6367
- `opentelemetry-util-http` Preserve brackets around literal IPv6 hosts ([#2552](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2552))
6468

65-
6669
## Version 1.24.0/0.45b0 (2024-03-28)
6770

6871
### Added

instrumentation/opentelemetry-instrumentation-boto/test-requirements.txt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,39 @@
1-
annotated-types==0.6.0
21
asgiref==3.7.2
32
attrs==23.2.0
4-
aws-sam-translator==1.85.0
5-
aws-xray-sdk==2.12.1
63
boto==2.49.0
74
boto3==1.34.44
85
botocore==1.34.44
96
certifi==2024.2.2
107
cffi==1.16.0
11-
cfn-lint==0.85.2
128
charset-normalizer==3.3.2
139
cryptography==42.0.3
1410
Deprecated==1.2.14
1511
docker==7.0.0
16-
ecdsa==0.18.0
17-
graphql-core==3.2.3
1812
idna==3.6
1913
importlib-metadata==6.11.0
20-
importlib-resources==6.1.1
2114
iniconfig==2.0.0
22-
Jinja2==3.1.3
15+
Jinja2==3.1.4
2316
jmespath==1.0.1
24-
jschema-to-python==1.2.3
25-
jsondiff==2.0.0
26-
jsonpatch==1.33
27-
jsonpickle==3.0.2
28-
jsonpointer==2.4
29-
jsonschema==4.21.1
30-
jsonschema-specifications==2023.12.1
31-
junit-xml==1.9
3217
MarkupSafe==2.1.5
3318
moto==2.3.2
34-
mpmath==1.3.0
35-
networkx==3.1
3619
packaging==23.2
37-
pbr==6.0.0
38-
pkgutil_resolve_name==1.3.10
3920
pluggy==1.4.0
4021
py==1.11.0
4122
py-cpuinfo==9.0.0
42-
pyasn1==0.5.1
4323
pycparser==2.21
44-
pydantic==2.6.1
45-
pydantic_core==2.16.2
4624
pytest==7.1.3
4725
pytest-benchmark==4.0.0
4826
python-dateutil==2.8.2
49-
python-jose==3.3.0
5027
pytz==2024.1
5128
PyYAML==6.0.1
52-
referencing==0.33.0
53-
regex==2023.12.25
5429
requests==2.31.0
5530
responses==0.25.0
56-
rpds-py==0.18.0
57-
rsa==4.9
5831
s3transfer==0.10.0
59-
sarif-om==1.0.4
6032
six==1.16.0
61-
sshpubkeys==3.3.1
62-
sympy==1.12
6333
tomli==2.0.1
6434
typing_extensions==4.9.0
6535
urllib3==1.26.18
66-
Werkzeug==3.0.1
36+
Werkzeug==2.1.2
6737
wrapt==1.16.0
6838
xmltodict==0.13.0
6939
zipp==3.17.0

instrumentation/opentelemetry-instrumentation-botocore/test-requirements.txt

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,35 @@
1-
annotated-types==0.6.0
21
asgiref==3.7.2
32
attrs==23.2.0
4-
aws-sam-translator==1.85.0
53
aws-xray-sdk==2.12.1
64
boto3==1.28.80
75
botocore==1.31.80
86
certifi==2024.2.2
97
cffi==1.16.0
10-
cfn-lint==0.85.2
118
charset-normalizer==3.3.2
129
cryptography==42.0.5
1310
Deprecated==1.2.14
1411
docker==7.0.0
15-
ecdsa==0.18.0
1612
idna==3.6
1713
importlib-metadata==6.11.0
18-
importlib-resources==6.1.1
1914
iniconfig==2.0.0
20-
Jinja2==3.1.3
15+
Jinja2==3.1.4
2116
jmespath==1.0.1
22-
jschema-to-python==1.2.3
23-
jsondiff==2.0.0
24-
jsonpatch==1.33
25-
jsonpickle==3.0.3
26-
jsonpointer==2.4
27-
jsonschema==4.21.1
28-
jsonschema-specifications==2023.12.1
29-
junit-xml==1.9
3017
MarkupSafe==2.0.1
3118
moto==3.1.19
32-
mpmath==1.3.0
33-
networkx==3.1
3419
packaging==23.2
35-
pbr==6.0.0
36-
pkgutil_resolve_name==1.3.10
3720
pluggy==1.4.0
3821
py==1.11.0
3922
py-cpuinfo==9.0.0
40-
pyasn1==0.5.1
4123
pycparser==2.21
42-
pydantic==2.6.2
43-
pydantic_core==2.16.3
4424
pytest==7.1.3
4525
pytest-benchmark==4.0.0
4626
python-dateutil==2.8.2
47-
python-jose==3.3.0
4827
pytz==2024.1
4928
PyYAML==6.0.1
50-
referencing==0.33.0
51-
regex==2023.12.25
5229
requests==2.31.0
5330
responses==0.25.0
54-
rpds-py==0.18.0
55-
rsa==4.9
5631
s3transfer==0.7.0
57-
sarif-om==1.0.4
5832
six==1.16.0
59-
sshpubkeys==3.3.1
60-
sympy==1.12
6133
tomli==2.0.1
6234
typing_extensions==4.9.0
6335
urllib3==1.26.18

instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def test_basic_post_request_metric_success(self):
279279
if isinstance(point, NumberDataPoint):
280280
self.assertEqual(point.value, 0)
281281

282-
def test_metric_uninstruemnt_app(self):
282+
def test_metric_uninstrument_app(self):
283283
self._client.get("/foobar")
284284
self._instrumentor.uninstrument_app(self._app)
285285
self._client.get("/foobar")

instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_basic_metric_success(self):
245245
)
246246
self.assertEqual(point.value, 0)
247247

248-
def test_metric_uninstruemnt(self):
248+
def test_metric_uninstrument(self):
249249
self.client.get("/hello/756")
250250
PyramidInstrumentor().uninstrument()
251251
self.config = Configurator()

instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ def get_or_create_headers():
229229
exception = exc
230230
result = getattr(exc, "response", None)
231231
finally:
232-
elapsed_time = max(
233-
round((default_timer() - start_time) * 1000), 0
234-
)
232+
elapsed_time = max(default_timer() - start_time, 0)
235233

236234
if isinstance(result, Response):
237235
span_attributes = {}

instrumentation/opentelemetry-instrumentation-system-metrics/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ classifiers = [
2626
dependencies = [
2727
"opentelemetry-instrumentation == 0.46b0.dev",
2828
"opentelemetry-api ~= 1.11",
29-
"opentelemetry-sdk ~= 1.11",
3029
"psutil ~= 5.9",
3130
]
3231

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
from opentelemetry.instrumentation.system_metrics.package import _instruments
9292
from opentelemetry.instrumentation.system_metrics.version import __version__
9393
from opentelemetry.metrics import CallbackOptions, Observation, get_meter
94-
from opentelemetry.sdk.util import get_dict_as_key
9594

9695
_logger = logging.getLogger(__name__)
9796

@@ -638,8 +637,8 @@ def _get_system_network_connections(
638637
net_connection, metric
639638
)
640639

641-
connection_counters_key = get_dict_as_key(
642-
self._system_network_connections_labels
640+
connection_counters_key = tuple(
641+
sorted(self._system_network_connections_labels.items())
643642
)
644643

645644
if connection_counters_key in connection_counters:

instrumentation/opentelemetry-instrumentation-threading/test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
asgiref==3.7.2
22
attrs==23.2.0
3-
confluent-kafka==2.3.0
43
Deprecated==1.2.14
54
importlib-metadata==6.11.0
65
iniconfig==2.0.0

opentelemetry-distro/tests/test_distro.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# type: ignore
1515

1616
import os
17-
from unittest import TestCase
17+
from unittest import TestCase, mock
1818

1919
from pkg_resources import DistributionNotFound, require
2020

@@ -33,17 +33,10 @@ def test_package_available(self):
3333
except DistributionNotFound:
3434
self.fail("opentelemetry-distro not installed")
3535

36+
@mock.patch.dict("os.environ", {}, clear=True)
3637
def test_default_configuration(self):
3738
distro = OpenTelemetryDistro()
38-
self.assertIsNone(os.environ.get(OTEL_TRACES_EXPORTER))
39-
self.assertIsNone(os.environ.get(OTEL_METRICS_EXPORTER))
4039
distro.configure()
41-
self.assertEqual(
42-
"otlp", os.environ.get(OTEL_TRACES_EXPORTER)
43-
)
44-
self.assertEqual(
45-
"otlp", os.environ.get(OTEL_METRICS_EXPORTER)
46-
)
47-
self.assertEqual(
48-
"grpc", os.environ.get(OTEL_EXPORTER_OTLP_PROTOCOL)
49-
)
40+
self.assertEqual("otlp", os.environ.get(OTEL_TRACES_EXPORTER))
41+
self.assertEqual("otlp", os.environ.get(OTEL_METRICS_EXPORTER))
42+
self.assertEqual("grpc", os.environ.get(OTEL_EXPORTER_OTLP_PROTOCOL))

opentelemetry-instrumentation/src/opentelemetry/instrumentation/distro.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ def configure(self, **kwargs):
5050
def load_instrumentor( # pylint: disable=no-self-use
5151
self, entry_point: EntryPoint, **kwargs
5252
):
53-
"""Takes a collection of instrumentation entry points
54-
and activates them by instantiating and calling instrument()
55-
on each one.
53+
"""Takes an instrumentation entry point and activates it by instantiating
54+
and calling instrument() on it.
55+
This is called for each opentelemetry_instrumentor entry point by auto
56+
instrumentation.
5657
5758
Distros can override this method to customize the behavior by
5859
inspecting each entry point and configuring them in special ways,

processor/opentelemetry-processor-baggage/README.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,32 @@ Do not put sensitive information in Baggage.
2020

2121
To repeat: a consequence of adding data to Baggage is that the keys and
2222
values will appear in all outgoing HTTP headers from the application.
23+
24+
## Usage
25+
26+
Add the span processor when configuring the tracer provider.
27+
28+
To configure the span processor to copy all baggage entries during configuration:
29+
30+
```python
31+
from opentelemetry.processor.baggage import BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS
32+
33+
tracer_provider = TracerProvider()
34+
tracer_provider.add_span_processor(BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS))
35+
```
36+
37+
Alternatively, you can provide a custom baggage key predicate to select which baggage keys you want to copy.
38+
39+
For example, to only copy baggage entries that start with `my-key`:
40+
41+
```python
42+
starts_with_predicate = lambda baggage_key: baggage_key.startswith("my-key")
43+
tracer_provider.add_span_processor(BaggageSpanProcessor(starts_with_predicate))
44+
```
45+
46+
For example, to only copy baggage entries that match the regex `^key.+`:
47+
48+
```python
49+
regex_predicate = lambda baggage_key: baggage_key.startswith("^key.+")
50+
tracer_provider.add_span_processor(BaggageSpanProcessor(regex_predicate))
51+
```

processor/opentelemetry-processor-baggage/src/opentelemetry/processor/baggage/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# pylint: disable=import-error
1616

17-
from .processor import BaggageSpanProcessor
17+
from .processor import ALLOW_ALL_BAGGAGE_KEYS, BaggageSpanProcessor
1818
from .version import __version__
1919

20-
__all__ = ["BaggageSpanProcessor", "__version__"]
20+
__all__ = ["ALLOW_ALL_BAGGAGE_KEYS", "BaggageSpanProcessor", "__version__"]

processor/opentelemetry-processor-baggage/src/opentelemetry/processor/baggage/processor.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Optional
15+
from typing import Callable, Optional
1616

1717
from opentelemetry.baggage import get_all as get_all_baggage
1818
from opentelemetry.context import Context
1919
from opentelemetry.sdk.trace.export import SpanProcessor
2020
from opentelemetry.trace import Span
2121

22+
# A BaggageKeyPredicate is a function that takes a baggage key and returns a boolean
23+
BaggageKeyPredicateT = Callable[[str], bool]
24+
25+
# A BaggageKeyPredicate that always returns True, allowing all baggage keys to be added to spans
26+
ALLOW_ALL_BAGGAGE_KEYS: BaggageKeyPredicateT = lambda _: True
27+
2228

2329
class BaggageSpanProcessor(SpanProcessor):
2430
"""
@@ -44,12 +50,13 @@ class BaggageSpanProcessor(SpanProcessor):
4450
4551
"""
4652

47-
def __init__(self) -> None:
48-
pass
53+
def __init__(self, baggage_key_predicate: BaggageKeyPredicateT) -> None:
54+
self._baggage_key_predicate = baggage_key_predicate
4955

5056
def on_start(
5157
self, span: "Span", parent_context: Optional[Context] = None
5258
) -> None:
5359
baggage = get_all_baggage(parent_context)
5460
for key, value in baggage.items():
55-
span.set_attribute(key, value)
61+
if self._baggage_key_predicate(key):
62+
span.set_attribute(key, value)

0 commit comments

Comments
 (0)