diff --git a/CHANGELOG.md b/CHANGELOG.md index f562971aeb7..e6ddd580e7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +- Change ``__all__`` to be statically defined. + ([#3143](https://github.com/open-telemetry/opentelemetry-python/pull/3143)) - Remove the ability to set a global metric prefix for Prometheus exporter ([#3137](https://github.com/open-telemetry/opentelemetry-python/pull/3137)) - Adds environment variables for log exporter diff --git a/opentelemetry-api/src/opentelemetry/_logs/__init__.py b/opentelemetry-api/src/opentelemetry/_logs/__init__.py index d9677a5f220..a01d1b14ee5 100644 --- a/opentelemetry-api/src/opentelemetry/_logs/__init__.py +++ b/opentelemetry-api/src/opentelemetry/_logs/__init__.py @@ -34,9 +34,7 @@ .. versionadded:: 1.15.0 """ -# pylint: disable=unused-import - -from opentelemetry._logs._internal import ( # noqa: F401 +from opentelemetry._logs._internal import ( Logger, LoggerProvider, LogRecord, @@ -46,13 +44,17 @@ get_logger_provider, set_logger_provider, ) -from opentelemetry._logs.severity import ( # noqa: F401 - SeverityNumber, - std_to_otel, -) - -__all__ = [] -for key, value in globals().copy().items(): # type: ignore - if not key.startswith("_"): - value.__module__ = __name__ # type: ignore - __all__.append(key) +from opentelemetry._logs.severity import SeverityNumber, std_to_otel + +__all__ = [ + "Logger", + "LoggerProvider", + "LogRecord", + "NoOpLogger", + "NoOpLoggerProvider", + "get_logger", + "get_logger_provider", + "set_logger_provider", + "SeverityNumber", + "std_to_otel", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index a548ef3793b..a86fbaee0f1 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import -from opentelemetry.sdk._logs._internal import ( # noqa: F401 +from opentelemetry.sdk._logs._internal import ( LogData, Logger, LoggerProvider, @@ -23,8 +22,11 @@ LogRecordProcessor, ) -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "LogData", + "Logger", + "LoggerProvider", + "LoggingHandler", + "LogRecord", + "LogRecordProcessor", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py index 10402886671..37a9eca7a08 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import - -from opentelemetry.sdk._logs._internal.export import ( # noqa: F401 +from opentelemetry.sdk._logs._internal.export import ( BatchLogRecordProcessor, ConsoleLogExporter, LogExporter, @@ -23,12 +21,15 @@ ) # The point module is not in the export directory to avoid a circular import. -from opentelemetry.sdk._logs._internal.export.in_memory_log_exporter import ( # noqa: F401 +from opentelemetry.sdk._logs._internal.export.in_memory_log_exporter import ( InMemoryLogExporter, ) -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "BatchLogRecordProcessor", + "ConsoleLogExporter", + "LogExporter", + "LogExportResult", + "SimpleLogRecordProcessor", + "InMemoryLogExporter", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py index 2219bc35c52..1ca14283cf6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py @@ -12,16 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import -from opentelemetry.sdk.metrics._internal import ( # noqa: F401 - Meter, - MeterProvider, -) -from opentelemetry.sdk.metrics._internal.exceptions import ( # noqa: F401 - MetricsTimeoutError, -) -from opentelemetry.sdk.metrics._internal.instrument import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal import Meter, MeterProvider +from opentelemetry.sdk.metrics._internal.exceptions import MetricsTimeoutError +from opentelemetry.sdk.metrics._internal.instrument import ( Counter, Histogram, ObservableCounter, @@ -30,8 +24,14 @@ UpDownCounter, ) -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "Meter", + "MeterProvider", + "MetricsTimeoutError", + "Counter", + "Histogram", + "ObservableCounter", + "ObservableGauge", + "ObservableUpDownCounter", + "UpDownCounter", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py index 76021bd576d..a87beadce56 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import -from opentelemetry.sdk.metrics._internal.export import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal.export import ( AggregationTemporality, ConsoleMetricExporter, InMemoryMetricReader, @@ -25,7 +24,7 @@ ) # The point module is not in the export directory to avoid a circular import. -from opentelemetry.sdk.metrics._internal.point import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal.point import ( DataPointT, DataT, Gauge, @@ -39,8 +38,23 @@ Sum, ) -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "AggregationTemporality", + "ConsoleMetricExporter", + "InMemoryMetricReader", + "MetricExporter", + "MetricExportResult", + "MetricReader", + "PeriodicExportingMetricReader", + "DataPointT", + "DataT", + "Gauge", + "Histogram", + "HistogramDataPoint", + "Metric", + "MetricsData", + "NumberDataPoint", + "ResourceMetrics", + "ScopeMetrics", + "Sum", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py index b20053d876d..f6e4dcb3aae 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import - -from opentelemetry.sdk.metrics._internal.aggregation import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal.aggregation import ( Aggregation, DefaultAggregation, DropAggregation, @@ -22,10 +20,14 @@ LastValueAggregation, SumAggregation, ) -from opentelemetry.sdk.metrics._internal.view import View # noqa: F401 +from opentelemetry.sdk.metrics._internal.view import View -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "Aggregation", + "DefaultAggregation", + "DropAggregation", + "ExplicitBucketHistogramAggregation", + "LastValueAggregation", + "SumAggregation", + "View", +]