Skip to content

Commit 75f5aa6

Browse files
author
Alex Boten
authored
Merge branch 'main' into issue_2142
2 parents a3bca48 + 4ed4fd0 commit 75f5aa6

File tree

19 files changed

+1013
-552
lines changed

19 files changed

+1013
-552
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.9.1-0.28b1...HEAD)
99

10+
- `opentelemetry-exporter-otlp-grpc` update SDK dependency to ~1.9.
11+
([#2442](https://github.com/open-telemetry/opentelemetry-python/pull/2442))
12+
- bugfix(auto-instrumentation): attach OTLPHandler to root logger
13+
([#2450](https://github.com/open-telemetry/opentelemetry-python/pull/2450))
14+
- Bump semantic conventions from 1.6.1 to 1.8.0
15+
([#2461](https://github.com/open-telemetry/opentelemetry-python/pull/2461))
16+
1017
## [1.9.1-0.28b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.9.1-0.28b1) - 2022-01-29
1118

1219
- Update opentelemetry-proto to v0.12.0. Note that this update removes deprecated status codes.

dev-requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ readme-renderer~=24.0
1313
grpcio-tools~=1.41.0
1414
mypy-protobuf~=3.0.0
1515
protobuf~=3.18.1
16+
# temporary fix. we should update the jinja, flask deps
17+
# See https://github.com/pallets/markupsafe/issues/282
18+
# breaking change introduced in markupsafe causes jinja, flask to break
19+
markupsafe==2.0.1

docs-requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ flask~=1.0
1919
opentracing~=2.2.0
2020
thrift>=0.10.0
2121
wrapt>=1.0.0,<2.0.0
22+
# temporary fix. we should update the jinja, flask deps
23+
# See https://github.com/pallets/markupsafe/issues/282
24+
# breaking change introduced in markupsafe causes jinja, flask to break
25+
markupsafe==2.0.1

docs/examples/fork-process-model/flask-gunicorn/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ opentelemetry-instrumentation==0.18b0
1212
opentelemetry-instrumentation-flask==0.18b1
1313
opentelemetry-instrumentation-wsgi==0.18b1
1414
opentelemetry-sdk==0.18b0
15-
protobuf==3.14.0
15+
protobuf==3.15.0
1616
six==1.15.0
1717
thrift==0.13.0
1818
uWSGI==2.0.19.1

exporter/opentelemetry-exporter-otlp-proto-grpc/setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ install_requires =
4343
grpcio >= 1.0.0, < 2.0.0
4444
googleapis-common-protos ~= 1.52
4545
opentelemetry-api ~= 1.3
46-
opentelemetry-sdk ~= 1.3
46+
opentelemetry-sdk ~= 1.9
4747
opentelemetry-proto == 1.9.1
4848
backoff ~= 1.10.0
4949

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
OpenTelemetry SDK Configurator for Easy Instrumentation with Distros
1818
"""
1919

20+
import logging
2021
from abc import ABC, abstractmethod
2122
from os import environ
2223
from typing import Dict, Optional, Sequence, Tuple, Type
@@ -31,6 +32,7 @@
3132
)
3233
from opentelemetry.sdk._logs import (
3334
LogEmitterProvider,
35+
OTLPHandler,
3436
set_log_emitter_provider,
3537
)
3638
from opentelemetry.sdk._logs.export import BatchLogProcessor, LogExporter
@@ -91,7 +93,7 @@ def _init_tracing(
9193

9294

9395
def _init_logging(
94-
exporters: Dict[str, Sequence[LogExporter]],
96+
exporters: Dict[str, Type[LogExporter]],
9597
auto_instrumentation_version: Optional[str] = None,
9698
):
9799
# if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name
@@ -111,6 +113,11 @@ def _init_logging(
111113
BatchLogProcessor(exporter_class(**exporter_args))
112114
)
113115

116+
log_emitter = provider.get_log_emitter(__name__)
117+
handler = OTLPHandler(level=logging.NOTSET, log_emitter=log_emitter)
118+
119+
logging.getLogger().addHandler(handler)
120+
114121

115122
def _import_config_components(
116123
selected_components, entry_point_name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
15+
16+
from logging import getLogger
17+
from threading import Lock
18+
from typing import Iterable, Set
19+
20+
from opentelemetry.sdk._metrics.aggregation import (
21+
_convert_aggregation_temporality,
22+
)
23+
from opentelemetry.sdk._metrics.measurement import Measurement
24+
from opentelemetry.sdk._metrics.point import AggregationTemporality, Metric
25+
from opentelemetry.sdk.resources import Resource
26+
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
27+
28+
_logger = getLogger(__name__)
29+
30+
31+
class _ViewInstrumentMatch:
32+
def __init__(
33+
self,
34+
name: str,
35+
unit: str,
36+
description: str,
37+
aggregation: type,
38+
instrumentation_info: InstrumentationInfo,
39+
resource: Resource,
40+
attribute_keys: Set[str] = None,
41+
):
42+
self._name = name
43+
self._unit = unit
44+
self._description = description
45+
self._aggregation = aggregation
46+
self._instrumentation_info = instrumentation_info
47+
self._resource = resource
48+
self._attribute_keys = attribute_keys
49+
self._attributes_aggregation = {}
50+
self._attributes_previous_point = {}
51+
self._lock = Lock()
52+
53+
def consume_measurement(self, measurement: Measurement) -> None:
54+
55+
if self._attribute_keys is not None:
56+
57+
attributes = {}
58+
59+
for key, value in measurement.attributes.items():
60+
if key in self._attribute_keys:
61+
attributes[key] = value
62+
elif measurement.attributes is not None:
63+
attributes = measurement.attributes
64+
else:
65+
attributes = {}
66+
67+
attributes = frozenset(attributes.items())
68+
69+
if attributes not in self._attributes_aggregation.keys():
70+
with self._lock:
71+
self._attributes_aggregation[attributes] = self._aggregation()
72+
73+
self._attributes_aggregation[attributes].aggregate(measurement)
74+
75+
def collect(self, temporality: int) -> Iterable[Metric]:
76+
77+
with self._lock:
78+
for (
79+
attributes,
80+
aggregation,
81+
) in self._attributes_aggregation.items():
82+
83+
previous_point = self._attributes_previous_point.get(
84+
attributes
85+
)
86+
87+
current_point = aggregation.collect()
88+
89+
# pylint: disable=assignment-from-none
90+
self._attributes_previous_point[
91+
attributes
92+
] = _convert_aggregation_temporality(
93+
previous_point,
94+
current_point,
95+
AggregationTemporality.CUMULATIVE,
96+
)
97+
98+
if current_point is not None:
99+
100+
yield Metric(
101+
attributes=dict(attributes),
102+
description=self._description,
103+
instrumentation_info=self._instrumentation_info,
104+
name=self._name,
105+
resource=self._resource,
106+
unit=self._unit,
107+
point=_convert_aggregation_temporality(
108+
previous_point,
109+
current_point,
110+
temporality,
111+
),
112+
)

0 commit comments

Comments
 (0)