Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Update OpenTelemetry SDK to 1.12.0 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale authored Aug 24, 2022
1 parent c211765 commit c277296
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This exporter allows exporting metrics created using the [OpenTelemetry SDK for Python](https://github.com/open-telemetry/opentelemetry-python)
directly to [Dynatrace](https://www.dynatrace.com).

**It was built against OpenTelemetry SDK version `1.12.0-rc2` and should work with any `1.12+` version.**
**It was built against OpenTelemetry SDK version `1.12.0` and should work with any `1.12+` version.**

More information on exporting OpenTelemetry metrics to Dynatrace can be found in the
[Dynatrace documentation](https://www.dynatrace.com/support/help/shortlink/opentelemetry-metrics).
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ package_dir=
=src
packages=find_namespace:
install_requires=
opentelemetry-api~=1.12.0-rc2
opentelemetry-sdk~=1.12.0-rc2
opentelemetry-api~=1.12.0
opentelemetry-sdk~=1.12.0
requests~=2.25
dynatrace-metric-utils~=0.2.0

Expand Down
4 changes: 2 additions & 2 deletions src/dynatrace/opentelemetry/metrics/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def configure_dynatrace_metrics_export(
"""
return PeriodicExportingMetricReader(
export_interval_millis=export_interval_millis,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
exporter=_DynatraceMetricsExporter(
endpoint_url=endpoint_url,
api_token=api_token,
prefix=prefix,
default_dimensions=default_dimensions,
export_dynatrace_metadata=export_dynatrace_metadata
export_dynatrace_metadata=export_dynatrace_metadata,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
)
)
16 changes: 15 additions & 1 deletion src/dynatrace/opentelemetry/metrics/export/_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import logging
from typing import Mapping, Optional
from typing import Mapping, Optional, Dict

import requests
from dynatrace.metric.utils import (
Expand All @@ -25,6 +25,10 @@
MetricExportResult,
MetricsData
)
from opentelemetry.sdk.metrics._internal.aggregation import (
AggregationTemporality,
)
from opentelemetry.sdk.metrics.view import Aggregation

from dynatrace.opentelemetry.metrics.export._factory import (
_OTelDynatraceMetricsFactory
Expand All @@ -47,7 +51,13 @@ def __init__(
prefix: Optional[str] = None,
default_dimensions: Optional[Mapping[str, str]] = None,
export_dynatrace_metadata: Optional[bool] = False,
preferred_temporality: Dict[type, AggregationTemporality] = None,
preferred_aggregation: Dict[
type, Aggregation
] = None,
):
super().__init__(preferred_temporality=preferred_temporality,
preferred_aggregation=preferred_aggregation)
self.__logger = logging.getLogger(__name__)

if endpoint_url:
Expand Down Expand Up @@ -123,6 +133,10 @@ def export(self,
return MetricExportResult.FAILURE
return MetricExportResult.SUCCESS

def force_flush(self, timeout_millis: float = 10_000) -> bool:
# nothing to do.
pass

def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
# nothing to do.
pass
Expand Down
13 changes: 7 additions & 6 deletions test/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,12 @@ def test_multiple_records(self, mock_post):
def test_view(self, mock_post):
mock_post.return_value = self._get_session_response()

exporter = _DynatraceMetricsExporter()
exporter = _DynatraceMetricsExporter(
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
)

metric_reader = PeriodicExportingMetricReader(
export_interval_millis=3600000,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
# 1h so that the test can finish before the collection event fires.
exporter=exporter)

Expand Down Expand Up @@ -534,11 +535,11 @@ def test_configuration_default(self):
api_token=None,
prefix=None,
default_dimensions=None,
export_dynatrace_metadata=False
export_dynatrace_metadata=False,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
)
mock_reader.assert_called_once_with(
export_interval_millis=None,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
exporter=mock.ANY,
)
_, kwargs = mock_reader.call_args
Expand Down Expand Up @@ -566,11 +567,11 @@ def test_configuration_custom(self):
api_token="dt.APItoken",
prefix="otel.python.test",
default_dimensions={"defaultKey": "defaultValue"},
export_dynatrace_metadata=True
export_dynatrace_metadata=True,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
)
mock_reader.assert_called_once_with(
export_interval_millis=100,
preferred_temporality=_DYNATRACE_TEMPORALITY_PREFERENCE,
exporter=mock.ANY,
)
_, kwargs = mock_reader.call_args
Expand Down

0 comments on commit c277296

Please sign in to comment.