Skip to content

Commit

Permalink
Merge branch 'main' into issues3547
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Feb 14, 2024
2 parents f2a8ed5 + 55bf100 commit 15d4a95
Show file tree
Hide file tree
Showing 28 changed files with 246 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
python-version: ${{ env[matrix.python-version] }}
architecture: 'x64'
- name: Install tox
run: pip install tox==3.27.1 -U tox-factor
run: pip install tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/public-api-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
python-version: '3.10'

- name: Install tox
run: pip install tox==3.27.1 -U tox-factor
run: pip install tox

- name: Public API Check
run: tox -e public-symbols-check
27 changes: 17 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
# Otherwise, set variable to the commit of your branch on
# opentelemetry-python-contrib which is compatible with these Core repo
# changes.
CONTRIB_REPO_SHA: d167ef7b43941a74378d625fea74628dd7572efa
CONTRIB_REPO_SHA: 1a984d3ba18d4080c58485b7d807dba241179d41
# This is needed because we do not clone the core repo in contrib builds anymore.
# When running contrib builds as part of core builds, we use actions/checkout@v2 which
# does not set an environment variable (simply just runs tox), which is different when
Expand Down Expand Up @@ -42,9 +42,6 @@ jobs:
- "getting-started"
- "opentracing-shim"
- "opencensus-shim"
- "exporter-jaeger-combined"
- "exporter-jaeger-proto-grpc"
- "exporter-jaeger-thrift"
- "exporter-opencensus"
- "exporter-otlp-proto-common"
- "exporter-otlp-combined"
Expand All @@ -58,6 +55,16 @@ jobs:
- "propagator-b3"
- "propagator-jaeger"
os: [ubuntu-20.04, windows-2019]
exclude:
- python-version: pypy3
package: "opencensus-shim"
- python-version: pypy3
package: "exporter-opencensus"
- python-version: pypy3
package: "exporter-otlp-combined"
- python-version: pypy3
package: "exporter-otlp-proto-grpc"

steps:
- name: Checkout Core Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
Expand All @@ -67,15 +74,15 @@ jobs:
python-version: ${{ env[matrix.python-version] }}
architecture: 'x64'
- name: Install tox
run: pip install tox==3.27.1 -U tox-factor
run: pip install tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: |
.tox
~/.cache/pip
key: v3-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini',
key: v4-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini',
'dev-requirements.txt') }}-core
- name: Windows does not let git check out files with long names
if: ${{ matrix.os == 'windows-2019'}}
Expand All @@ -100,15 +107,15 @@ jobs:
python-version: '3.10'
architecture: 'x64'
- name: Install tox
run: pip install tox==3.27.1
run: pip install tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: |
.tox
~/.cache/pip
key: v3-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt')
key: v4-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt')
}}-core
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
Expand Down Expand Up @@ -169,7 +176,7 @@ jobs:
- "tornado"
- "tortoiseorm"
- "urllib"
- "urllib3"
- "urllib3v"
- "wsgi"
- "prometheus-remote-write"
- "richconsole"
Expand All @@ -191,7 +198,7 @@ jobs:
python-version: ${{ env[matrix.python-version] }}
architecture: 'x64'
- name: Install tox
run: pip install tox==3.27.1 -U tox-factor
run: pip install tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Fix `OTLPMetricExporter` ignores `preferred_aggregation` property
([#3603](https://github.com/open-telemetry/opentelemetry-python/pull/3603))
- Logs: set `observed_timestamp` field
([#3565](https://github.com/open-telemetry/opentelemetry-python/pull/3565))
- Add missing Resource SchemaURL in OTLP exporters
Expand Down Expand Up @@ -35,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3645](https://github.com/open-telemetry/opentelemetry-python/pull/3645))
- Add Proxy classes for logging
([#3575](https://github.com/open-telemetry/opentelemetry-python/pull/3575))
- Remove dependency on 'backoff' library
([#3679](https://github.com/open-telemetry/opentelemetry-python/pull/3679))

## Version 1.22.0/0.43b0 (2023-12-15)

Expand Down
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ during their normal contribution hours.

This project uses [tox](https://tox.readthedocs.io) to automate
some aspects of development, including testing against multiple Python versions.
To install `tox`, run[^1]:
To install `tox`, run:

```console
$ pip install tox==3.27.1
$ pip install tox
```

[^1]: Right now we are experiencing issues with `tox==4.x.y`, so we recommend you use this version.

You can run `tox` with the following arguments:

- `tox` to run all existing tox commands, including unit tests for all packages
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ requests==2.31.0
ruamel.yaml==0.17.21
asgiref==3.7.2
psutil==5.9.6
GitPython==3.1.40
GitPython==3.1.41
flaky==3.7.0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ opentelemetry-instrumentation==0.41b0
opentelemetry-instrumentation-flask==0.41b0
opentelemetry-instrumentation-wsgi==0.41b0
opentelemetry-sdk==1.20.0
protobuf==3.19.4
protobuf==3.19.5
six==1.15.0
thrift==0.13.0
uWSGI==2.0.22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ opentelemetry-instrumentation==0.41b0
opentelemetry-instrumentation-flask==0.41b0
opentelemetry-instrumentation-wsgi==0.41b0
opentelemetry-sdk==1.20.0
protobuf==3.19.4
protobuf==3.19.5
six==1.15.0
thrift==0.13.0
uWSGI==2.0.22
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 @@ -10,15 +10,15 @@ idna==3.4
importlib-metadata==6.8.0
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
Jinja2==3.1.3
MarkupSafe==2.1.3
packaging==23.2
pluggy==1.3.0
py==1.11.0
py-cpuinfo==9.0.0
pytest==7.1.3
pytest-benchmark==4.0.0
requests==2.26.0
requests==2.31.0
tomli==2.0.1
typing_extensions==4.8.0
urllib3==1.26.18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ classifiers = [
]
dependencies = [
"opentelemetry-proto == 1.23.0.dev",
"backoff >= 1.10.0, < 3.0.0; python_version>='3.8'",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@

import logging
from collections.abc import Sequence
from typing import Any, Mapping, Optional, List, Callable, TypeVar, Dict

import backoff
from itertools import count
from typing import (
Any,
Mapping,
Optional,
List,
Callable,
TypeVar,
Dict,
Iterator,
)

from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.proto.common.v1.common_pb2 import (
Expand All @@ -37,7 +45,6 @@
from opentelemetry.sdk.trace import Resource
from opentelemetry.util.types import Attributes


_logger = logging.getLogger(__name__)

_TypingResourceT = TypeVar("_TypingResourceT")
Expand Down Expand Up @@ -113,7 +120,6 @@ def _get_resource_data(
resource_class: Callable[..., _TypingResourceT],
name: str,
) -> List[_TypingResourceT]:

resource_data = []

for (
Expand All @@ -134,14 +140,36 @@ def _get_resource_data(
return resource_data


# Work around API change between backoff 1.x and 2.x. Since 2.0.0 the backoff
# wait generator API requires a first .send(None) before reading the backoff
# values from the generator.
_is_backoff_v2 = next(backoff.expo()) is None


def _create_exp_backoff_generator(*args, **kwargs):
gen = backoff.expo(*args, **kwargs)
if _is_backoff_v2:
gen.send(None)
return gen
def _create_exp_backoff_generator(max_value: int = 0) -> Iterator[int]:
"""
Generates an infinite sequence of exponential backoff values. The sequence starts
from 1 (2^0) and doubles each time (2^1, 2^2, 2^3, ...). If a max_value is specified
and non-zero, the generated values will not exceed this maximum, capping at max_value
instead of growing indefinitely.
Parameters:
- max_value (int, optional): The maximum value to yield. If 0 or not provided, the
sequence grows without bound.
Returns:
Iterator[int]: An iterator that yields the exponential backoff values, either uncapped or
capped at max_value.
Example:
```
gen = _create_exp_backoff_generator(max_value=10)
for _ in range(5):
print(next(gen))
```
This will print:
1
2
4
8
10
Note: this functionality used to be handled by the 'backoff' package.
"""
for i in count(0):
out = 2**i
yield min(out, max_value) if max_value else out
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from opentelemetry.sdk.metrics.export import (
MetricExporter,
)
from opentelemetry.sdk.metrics.view import Aggregation
from os import environ
from opentelemetry.sdk.metrics import (
Counter,
Expand Down Expand Up @@ -65,9 +66,18 @@ class OTLPMetricExporterMixin:
def _common_configuration(
self,
preferred_temporality: Dict[type, AggregationTemporality] = None,
preferred_aggregation: Dict[type, Aggregation] = None,
) -> None:

instrument_class_temporality = {}
MetricExporter.__init__(
self,
preferred_temporality=self._get_temporality(preferred_temporality),
preferred_aggregation=self._get_aggregation(preferred_aggregation),
)

def _get_temporality(
self, preferred_temporality: Dict[type, AggregationTemporality]
) -> Dict[type, AggregationTemporality]:

otel_exporter_otlp_metrics_temporality_preference = (
environ.get(
Expand Down Expand Up @@ -119,6 +129,13 @@ def _common_configuration(

instrument_class_temporality.update(preferred_temporality or {})

return instrument_class_temporality

def _get_aggregation(
self,
preferred_aggregation: Dict[type, Aggregation],
) -> Dict[type, Aggregation]:

otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get(
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
"explicit_bucket_histogram",
Expand All @@ -128,7 +145,9 @@ def _common_configuration(
"base2_exponential_bucket_histogram"
):

histogram_aggregation_type = ExponentialBucketHistogramAggregation
instrument_class_aggregation = {
Histogram: ExponentialBucketHistogramAggregation(),
}

else:

Expand All @@ -145,13 +164,13 @@ def _common_configuration(
otel_exporter_otlp_metrics_default_histogram_aggregation,
)

histogram_aggregation_type = ExplicitBucketHistogramAggregation
instrument_class_aggregation = {
Histogram: ExplicitBucketHistogramAggregation(),
}

MetricExporter.__init__(
self,
preferred_temporality=instrument_class_temporality,
preferred_aggregation={Histogram: histogram_aggregation_type()},
)
instrument_class_aggregation.update(preferred_aggregation or {})

return instrument_class_aggregation


def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.

from unittest import TestCase

from opentelemetry.exporter.otlp.proto.common._internal import (
_create_exp_backoff_generator,
)


class TestBackoffGenerator(TestCase):
def test_exp_backoff_generator(self):
generator = _create_exp_backoff_generator()
self.assertEqual(next(generator), 1)
self.assertEqual(next(generator), 2)
self.assertEqual(next(generator), 4)
self.assertEqual(next(generator), 8)
self.assertEqual(next(generator), 16)

def test_exp_backoff_generator_with_max(self):
generator = _create_exp_backoff_generator(max_value=4)
self.assertEqual(next(generator), 1)
self.assertEqual(next(generator), 2)
self.assertEqual(next(generator), 4)
self.assertEqual(next(generator), 4)
self.assertEqual(next(generator), 4)

def test_exp_backoff_generator_with_odd_max(self):
# use a max_value that's not in the set
generator = _create_exp_backoff_generator(max_value=11)
self.assertEqual(next(generator), 1)
self.assertEqual(next(generator), 2)
self.assertEqual(next(generator), 4)
self.assertEqual(next(generator), 8)
self.assertEqual(next(generator), 11)

0 comments on commit 15d4a95

Please sign in to comment.