Skip to content

Commit

Permalink
Merge branch 'main' into issue_3887
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jun 28, 2024
2 parents 9f9e3e6 + 38d2587 commit 5912460
Show file tree
Hide file tree
Showing 106 changed files with 2,269 additions and 1,224 deletions.
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Description

<!--
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
-->

Fixes # (issue)

Expand All @@ -21,6 +23,7 @@ Please describe the tests that you ran to verify your changes. Provide instructi

# Does This PR Require a Contrib Repo Change?

<!--
Answer the following question based on these examples of changes that would require a Contrib Repo Change:
- [The OTel specification](https://github.com/open-telemetry/opentelemetry-specification) has changed which prompted this PR to update the method interfaces of `opentelemetry-api/` or `opentelemetry-sdk/`
- The method interfaces of `test/util` have changed
Expand All @@ -33,6 +36,7 @@ Answer the following question based on these examples of changes that would requ
- Major changes to project information, such as in:
- `README.md`
- `CONTRIBUTING.md`
-->

- [ ] Yes. - Link to PR:
- [ ] No.
Expand Down
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ suggestion-mode=yes
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no

# Run python dependant checks considering the baseline version
py-version=3.8


[MESSAGES CONTROL]

Expand Down
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Do not execute Flask Tests in debug mode
([#3956](https://github.com/open-telemetry/opentelemetry-python/pull/3956))
- When encountering an error encoding metric attributes in the OTLP exporter, log the key that had an error.
([#3838](https://github.com/open-telemetry/opentelemetry-python/pull/3838))
- Log a warning when a `LogRecord` in `sdk/log` has dropped attributes
due to reaching limits
([#3946](https://github.com/open-telemetry/opentelemetry-python/pull/3946))
- Fix RandomIdGenerator can generate invalid Span/Trace Ids
([#3949](https://github.com/open-telemetry/opentelemetry-python/pull/3949))
- Add Python 3.12 to tox
([#3616](https://github.com/open-telemetry/opentelemetry-python/pull/3616))
- Improve resource field structure for LogRecords
([#3972](https://github.com/open-telemetry/opentelemetry-python/pull/3972))
- Update Semantic Conventions code generation scripts:
- fix namespace exclusion that resulted in dropping `os` and `net` namespaces.
- add `Final` decorator to constants to prevent collisions
- enable mypy and fix detected issues
- allow to drop specific attributes in preparation for Semantic Conventions v1.26.0
([#3973](https://github.com/open-telemetry/opentelemetry-python/pull/3966))
- Update semantic conventions to version 1.26.0.
([#3964](https://github.com/open-telemetry/opentelemetry-python/pull/3964))
- Use semconv exception attributes for record exceptions in spans
([#3979](https://github.com/open-telemetry/opentelemetry-python/pull/3979))
- Fix _encode_events assumes events.attributes.dropped exists
([#3965](https://github.com/open-telemetry/opentelemetry-python/pull/3965))
- Validate links at span creation
([#3991](https://github.com/open-telemetry/opentelemetry-python/pull/3991))

## Version 1.25.0/0.46b0 (2024-05-30)

Expand Down Expand Up @@ -62,7 +85,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- units with slash are converted e.g. `m/s` -> `meters_per_second`.
- The exporter's API is not changed
- Add parameters for Distros and configurators to configure autoinstrumentation in addition to existing environment variables.
([#3864] (https://github.com/open-telemetry/opentelemetry-python/pull/3864))
([#3864](https://github.com/open-telemetry/opentelemetry-python/pull/3864))

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

Expand Down
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ To create a new PR, fork the project in GitHub and clone the upstream repo:

```console
$ git clone https://github.com/open-telemetry/opentelemetry-python.git
$ cd opentelemetry-python
```

Add your fork as an origin:
Expand Down Expand Up @@ -262,3 +263,24 @@ automatically load as options for the `opentelemetry-instrument` command.
as specified with the [napoleon
extension](http://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#google-vs-numpy)
extension in [Sphinx](http://www.sphinx-doc.org/en/master/index.html).

## Updating supported Python versions

### Bumping the Python baseline

When updating the minimum supported Python version remember to:

- Remove the version in `pyproject.toml` trove classifiers
- Remove the version from `tox.ini`
- Search for `sys.version_info` usage and remove code for unsupported versions
- Bump `py-version` in `.pylintrc` for Python version dependent checks

### Adding support for a new Python release

When adding support for a new Python release remember to:

- Add the version in `tox.ini`
- Add the version in `pyproject.toml` trove classifiers
- Update github workflows accordingly; lint and benchmarks use the latest supported version
- Update `.pre-commit-config.yaml`
- Update tox examples in the documentation
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme-renderer==42.0
markupsafe==2.1.3
bleach==4.1.0 # This dependency was updated to a breaking version.
codespell==2.1.0
requests==2.31.0
requests==2.32.3
ruamel.yaml==0.17.21
asgiref==3.7.2
psutil==5.9.6
Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started/tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pluggy==1.3.0
py-cpuinfo==9.0.0
pytest==7.4.4
pytest-benchmark==4.0.0
requests==2.31.0
requests==2.32.3
tomli==2.0.1
typing_extensions==4.8.0
urllib3==1.26.18
urllib3==1.26.19
Werkzeug==3.0.3
wrapt==1.15.0
zipp==3.17.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _encode_attributes(
try:
pb2_attributes.append(_encode_key_value(key, value))
except Exception as error:
_logger.exception(error)
_logger.exception("Failed to encode key %s: %s", key, error)
else:
pb2_attributes = None
return pb2_attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _encode_events(
name=event.name,
time_unix_nano=event.timestamp,
attributes=_encode_attributes(event.attributes),
dropped_attributes_count=event.attributes.dropped,
dropped_attributes_count=event.dropped_attributes,
)
pb2_events.append(encoded_event)
return pb2_events
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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 unittest
from logging import ERROR

from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
)
from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue
from opentelemetry.proto.common.v1.common_pb2 import (
ArrayValue as PB2ArrayValue,
)
from opentelemetry.proto.common.v1.common_pb2 import KeyValue as PB2KeyValue


class TestOTLPAttributeEncoder(unittest.TestCase):
def test_encode_attributes_all_kinds(self):
result = _encode_attributes(
{
"a": 1, # int
"b": 3.14, # float
"c": False, # bool
"hello": "world", # str
"greet": ["hola", "bonjour"], # Sequence[str]
"data": [1, 2], # Sequence[int]
"data_granular": [1.4, 2.4], # Sequence[float]
}
)
self.assertEqual(
result,
[
PB2KeyValue(key="a", value=PB2AnyValue(int_value=1)),
PB2KeyValue(key="b", value=PB2AnyValue(double_value=3.14)),
PB2KeyValue(key="c", value=PB2AnyValue(bool_value=False)),
PB2KeyValue(
key="hello", value=PB2AnyValue(string_value="world")
),
PB2KeyValue(
key="greet",
value=PB2AnyValue(
array_value=PB2ArrayValue(
values=[
PB2AnyValue(string_value="hola"),
PB2AnyValue(string_value="bonjour"),
]
)
),
),
PB2KeyValue(
key="data",
value=PB2AnyValue(
array_value=PB2ArrayValue(
values=[
PB2AnyValue(int_value=1),
PB2AnyValue(int_value=2),
]
)
),
),
PB2KeyValue(
key="data_granular",
value=PB2AnyValue(
array_value=PB2ArrayValue(
values=[
PB2AnyValue(double_value=1.4),
PB2AnyValue(double_value=2.4),
]
)
),
),
],
)

def test_encode_attributes_error_logs_key(self):
with self.assertLogs(level=ERROR) as error:
result = _encode_attributes({"a": 1, "bad_key": None, "b": 2})

self.assertEqual(len(error.records), 1)
self.assertEqual(error.records[0].msg, "Failed to encode key %s: %s")
self.assertEqual(error.records[0].args[0], "bad_key")
self.assertIsInstance(error.records[0].args[1], Exception)
self.assertEqual(
result,
[
PB2KeyValue(key="a", value=PB2AnyValue(int_value=1)),
PB2KeyValue(key="b", value=PB2AnyValue(int_value=2)),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def setUp(self):
)

type(event_mock).name = PropertyMock(return_value="a")

type(event_mock).dropped_attributes = PropertyMock(return_value=0)
self.span = _Span(
"a",
context=Mock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ py-cpuinfo==9.0.0
pytest==7.4.4
pytest-benchmark==4.0.0
PyYAML==6.0.1
requests==2.31.0
requests==2.32.3
responses==0.24.1
tomli==2.0.1
typing_extensions==4.10.0
urllib3==2.2.1
urllib3==2.2.2
wrapt==1.16.0
zipp==3.17.0
-e opentelemetry-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ py-cpuinfo==9.0.0
pytest==7.4.4
pytest-benchmark==4.0.0
PyYAML==6.0.1
requests==2.31.0
requests==2.32.3
responses==0.24.1
tomli==2.0.1
typing_extensions==4.10.0
urllib3==2.2.1
urllib3==2.2.2
wrapt==1.16.0
zipp==3.17.0
-e opentelemetry-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pluggy==1.5.0
py-cpuinfo==9.0.0
pytest==7.4.4
pytest-benchmark==4.0.0
requests==2.31.0
requests==2.32.3
tomli==2.0.1
typing_extensions==4.10.0
urllib3==2.2.1
urllib3==2.2.2
wrapt==1.16.0
zipp==3.17.0
-e opentelemetry-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ protobuf==3.20.3
py-cpuinfo==9.0.0
pytest==7.4.4
pytest-benchmark==4.0.0
requests==2.31.0
requests==2.32.3
tomli==2.0.1
typing_extensions==4.10.0
urllib3==2.2.1
urllib3==2.2.2
wrapt==1.16.0
zipp==3.17.0
-e opentelemetry-api
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"Deprecated >= 1.2.6",
# FIXME This should be able to be removed after 3.12 is released if there is a reliable API
# in importlib.metadata.
"importlib-metadata >= 6.0, <= 7.1",
"importlib-metadata >= 6.0, <= 7.2.1",
]
dynamic = [
"version",
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from opentelemetry.sdk._logs._internal import (
LogData,
LogDroppedAttributesWarning,
Logger,
LoggerProvider,
LoggingHandler,
Expand All @@ -31,4 +32,5 @@
"LogLimits",
"LogRecord",
"LogRecordProcessor",
"LogDroppedAttributesWarning",
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
import threading
import traceback
import warnings
from os import environ
from time import time_ns
from typing import Any, Callable, Optional, Tuple, Union # noqa
Expand Down Expand Up @@ -57,6 +58,18 @@
_ENV_VALUE_UNSET = ""


class LogDroppedAttributesWarning(UserWarning):
"""Custom warning to indicate dropped log attributes due to limits.
This class is used to filter and handle these specific warnings separately
from other warnings, ensuring that they are only shown once without
interfering with default user warnings.
"""


warnings.simplefilter("once", LogDroppedAttributesWarning)


class LogLimits:
"""This class is based on a SpanLimits class in the Tracing module.
Expand Down Expand Up @@ -189,7 +202,15 @@ def __init__(
),
}
)
self.resource = resource
self.resource = (
resource if isinstance(resource, Resource) else Resource.create({})
)
if self.dropped_attributes > 0:
warnings.warn(
"Log record attributes were dropped due to limits",
LogDroppedAttributesWarning,
stacklevel=2,
)

def __eq__(self, other: object) -> bool:
if not isinstance(other, LogRecord):
Expand Down Expand Up @@ -219,9 +240,7 @@ def to_json(self, indent=4) -> str:
else ""
),
"trace_flags": self.trace_flags,
"resource": (
repr(self.resource.attributes) if self.resource else ""
),
"resource": json.loads(self.resource.to_json()),
},
indent=indent,
)
Expand Down
Loading

0 comments on commit 5912460

Please sign in to comment.