Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
In this commit we are fixing various things:
* Update project path to start with amazon, not opentelemetry.
* Update isort to consider amazon first party.
* Fix imports with project path and isort update.
* Update some modules/classes to be internal, based on package private classes in Java implementation.
* Add basic unit tests to ensure imports are working as expected and setting up the foundation to implement full unit tests later.
  • Loading branch information
thpierce committed Jan 11, 2024
1 parent a377af6 commit 7c08b06
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ profile=black
multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*,.tox/*
known_first_party=opentelemetry
known_first_party=opentelemetry,amazon
known_third_party=psutil,pytest
6 changes: 3 additions & 3 deletions aws-opentelemetry-distro/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ dependencies = [
test = []

[project.entry-points.opentelemetry_configurator]
aws_configurator = "opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenTelemetryConfigurator"
aws_configurator = "amazon.opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenTelemetryConfigurator"

[project.entry-points.opentelemetry_distro]
aws_distro = "opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"
aws_distro = "amazon.opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"

[project.urls]
Homepage = "https://github.com/aws-observability/aws-otel-python-instrumentation/tree/main/aws-opentelemetry-distro"
Expand All @@ -39,4 +39,4 @@ include = [
]

[tool.hatch.build.targets.wheel]
packages = ["src/amazon/opentelemetry"]
packages = ["src/amazon"]
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from metric_attribute_generator import MetricAttributeGenerator

from amazon.opentelemetry.distro.metric_attribute_generator import MetricAttributeGenerator
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import BoundedAttributes, ReadableSpan


class AwsMetricAttributeGenerator(MetricAttributeGenerator):
class _AwsMetricAttributeGenerator(MetricAttributeGenerator):
"""AwsMetricAttributeGenerator generates specific metric attributes for incoming and outgoing traffic.
AwsMetricAttributeGenerator generates very specific metric attributes based on low-cardinality span and resource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from opentelemetry.sdk._configuration import _BaseConfigurator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from logging import getLogger

from opentelemetry.instrumentation.distro import BaseDistro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# SPDX-License-Identifier: Apache-2.0
from typing import Optional

from metric_attribute_generator import MetricAttributeGenerator
from typing_extensions import override

from amazon.opentelemetry.distro.metric_attribute_generator import MetricAttributeGenerator
from opentelemetry.context import Context
from opentelemetry.metrics import Histogram
from opentelemetry.sdk.resources import Resource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from aws_metric_attribute_generator import AwsMetricAttributeGenerator
from aws_span_metrics_processor import AwsSpanMetricsProcessor
from metric_attribute_generator import MetricAttributeGenerator

from amazon.opentelemetry.distro._aws_metric_attribute_generator import _AwsMetricAttributeGenerator
from amazon.opentelemetry.distro.aws_span_metrics_processor import AwsSpanMetricsProcessor
from amazon.opentelemetry.distro.metric_attribute_generator import MetricAttributeGenerator
from opentelemetry.sdk.metrics import Histogram, Meter, MeterProvider
from opentelemetry.sdk.resources import Resource

Expand All @@ -14,7 +13,7 @@
_LATENCY_UNITS: str = "Milliseconds"

# Defaults
_DEFAULT_GENERATOR: MetricAttributeGenerator = AwsMetricAttributeGenerator()
_DEFAULT_GENERATOR: MetricAttributeGenerator = _AwsMetricAttributeGenerator()
_DEFAULT_SCOPE_NAME: str = "AwsSpanMetricsProcessor"


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from unittest import TestCase

from amazon.opentelemetry.distro._aws_metric_attribute_generator import _AwsMetricAttributeGenerator


class TestAwsMetricAttributeGenerator(TestCase):
def test_basic(self):
generator: _AwsMetricAttributeGenerator = _AwsMetricAttributeGenerator()
self.assertEqual(generator.generate_metric_attributes_dict_from_span(None, None), {})
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase

from opentelemetry.distro.aws_opentelemetry_configurator import AwsOpenTelemetryConfigurator, AwsTracerProvider
from amazon.opentelemetry.distro.aws_opentelemetry_configurator import AwsOpenTelemetryConfigurator, AwsTracerProvider


class TestAwsOpenTelemetryConfigurator(TestCase):
# pylint: disable=no-self-use
def test_default_configuration(self):
configurator = AwsOpenTelemetryConfigurator()
configurator.configure()
trace_provider = configurator.get_trace_provider()
assert isinstance(trace_provider, AwsTracerProvider)
self.assertTrue(isinstance(trace_provider, AwsTracerProvider))
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase

from pkg_resources import DistributionNotFound, require
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from unittest import TestCase

from amazon.opentelemetry.distro.aws_span_metrics_processor import AwsSpanMetricsProcessor


class TestAwsSpanMetricsProcessor(TestCase):
def test_basic(self):
processor: AwsSpanMetricsProcessor = AwsSpanMetricsProcessor(None, None, None, None, None)
self.assertTrue(processor.force_flush)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from unittest import TestCase

from amazon.opentelemetry.distro.aws_span_metrics_processor_builder import AwsSpanMetricsProcessorBuilder


class TestAwsSpanMetricsProcessorBuilder(TestCase):
def test_basic(self):
builder: AwsSpanMetricsProcessorBuilder = AwsSpanMetricsProcessorBuilder(None, None)
self.assertIs(builder.set_scope_name("test"), builder)

0 comments on commit 7c08b06

Please sign in to comment.