From 0cd439f5ecf077d6027037ad928e011391c9648d Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 28 Oct 2021 09:48:35 -0700 Subject: [PATCH] move logs to _logs (#2240) * move logs to _logs * fix lint --- docs/examples/logs/example.py | 4 ++-- docs/sdk/logs.export.rst | 8 +++---- docs/sdk/logs.rst | 4 ++-- docs/sdk/logs.severity.rst | 6 ++--- .../otlp/proto/grpc/log_exporter/__init__.py | 6 ++--- .../tests/logs/test_otlp_logs_exporter.py | 8 ++++--- opentelemetry-sdk/setup.cfg | 2 +- .../sdk/{logs => _logs}/__init__.py | 6 ++--- .../sdk/{logs => _logs}/export/__init__.py | 4 ++-- .../export/in_memory_log_exporter.py | 4 ++-- .../sdk/{logs => _logs}/severity.py | 0 opentelemetry-sdk/tests/logs/test_export.py | 8 +++---- .../tests/logs/test_global_provider.py | 22 +++++++++---------- opentelemetry-sdk/tests/logs/test_handler.py | 4 ++-- .../tests/logs/test_multi_log_prcessor.py | 4 ++-- 15 files changed, 46 insertions(+), 44 deletions(-) rename opentelemetry-sdk/src/opentelemetry/sdk/{logs => _logs}/__init__.py (98%) rename opentelemetry-sdk/src/opentelemetry/sdk/{logs => _logs}/export/__init__.py (98%) rename opentelemetry-sdk/src/opentelemetry/sdk/{logs => _logs}/export/in_memory_log_exporter.py (93%) rename opentelemetry-sdk/src/opentelemetry/sdk/{logs => _logs}/severity.py (100%) diff --git a/docs/examples/logs/example.py b/docs/examples/logs/example.py index f38eec37550..db41ea4086c 100644 --- a/docs/examples/logs/example.py +++ b/docs/examples/logs/example.py @@ -2,12 +2,12 @@ from opentelemetry import trace from opentelemetry.exporter.otlp.proto.grpc.log_exporter import OTLPLogExporter -from opentelemetry.sdk.logs import ( +from opentelemetry.sdk._logs import ( LogEmitterProvider, OTLPHandler, set_log_emitter_provider, ) -from opentelemetry.sdk.logs.export import BatchLogProcessor +from opentelemetry.sdk._logs.export import BatchLogProcessor from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( diff --git a/docs/sdk/logs.export.rst b/docs/sdk/logs.export.rst index d247e4db72f..19a40237424 100644 --- a/docs/sdk/logs.export.rst +++ b/docs/sdk/logs.export.rst @@ -1,7 +1,7 @@ -opentelemetry.sdk.logs.export -============================= +opentelemetry.sdk._logs.export +============================== -.. automodule:: opentelemetry.sdk.logs.export +.. automodule:: opentelemetry.sdk._logs.export :members: :undoc-members: - :show-inheritance: \ No newline at end of file + :show-inheritance: diff --git a/docs/sdk/logs.rst b/docs/sdk/logs.rst index 7eb6f932648..ade637a88d1 100644 --- a/docs/sdk/logs.rst +++ b/docs/sdk/logs.rst @@ -1,4 +1,4 @@ -opentelemetry.sdk.logs package +opentelemetry.sdk._logs package =============================== Submodules @@ -9,7 +9,7 @@ Submodules logs.export logs.severity -.. automodule:: opentelemetry.sdk.logs +.. automodule:: opentelemetry.sdk._logs :members: :undoc-members: :show-inheritance: diff --git a/docs/sdk/logs.severity.rst b/docs/sdk/logs.severity.rst index bcf30cf361e..1197e8b44e8 100644 --- a/docs/sdk/logs.severity.rst +++ b/docs/sdk/logs.severity.rst @@ -1,7 +1,7 @@ -opentelemetry.sdk.logs.severity -=============================== +opentelemetry.sdk._logs.severity +================================ -.. automodule:: opentelemetry.sdk.logs.severity +.. automodule:: opentelemetry.sdk._logs.severity :members: :undoc-members: :show-inheritance: \ No newline at end of file diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py index ecf9e16e8f7..211655d93a2 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py @@ -31,9 +31,9 @@ ResourceLogs, ) from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord -from opentelemetry.sdk.logs import LogRecord as SDKLogRecord -from opentelemetry.sdk.logs import LogData -from opentelemetry.sdk.logs.export import LogExporter, LogExportResult +from opentelemetry.sdk._logs import LogRecord as SDKLogRecord +from opentelemetry.sdk._logs import LogData +from opentelemetry.sdk._logs.export import LogExporter, LogExportResult class OTLPLogExporter( diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py index ef2146b5c00..aef5c722ac4 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py @@ -42,9 +42,11 @@ from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as OTLPResource, ) -from opentelemetry.sdk.logs import LogData, LogRecord -from opentelemetry.sdk.logs.export import LogExportResult -from opentelemetry.sdk.logs.severity import SeverityNumber as SDKSeverityNumber +from opentelemetry.sdk._logs import LogData, LogRecord +from opentelemetry.sdk._logs.export import LogExportResult +from opentelemetry.sdk._logs.severity import ( + SeverityNumber as SDKSeverityNumber, +) from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace import TraceFlags diff --git a/opentelemetry-sdk/setup.cfg b/opentelemetry-sdk/setup.cfg index 19031c11e36..158c8a198cf 100644 --- a/opentelemetry-sdk/setup.cfg +++ b/opentelemetry-sdk/setup.cfg @@ -55,7 +55,7 @@ opentelemetry_tracer_provider = opentelemetry_traces_exporter = console = opentelemetry.sdk.trace.export:ConsoleSpanExporter opentelemetry_log_emitter_provider = - sdk_log_emitter_provider = opentelemetry.sdk.logs:LogEmitterProvider + sdk_log_emitter_provider = opentelemetry.sdk._logs:LogEmitterProvider opentelemetry_id_generator = random = opentelemetry.sdk.trace.id_generator:RandomIdGenerator opentelemetry_environment_variables = diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py similarity index 98% rename from opentelemetry-sdk/src/opentelemetry/sdk/logs/__init__.py rename to opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index 9917daf020f..619482e3fd2 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -21,10 +21,10 @@ import threading from typing import Any, Callable, Optional, Tuple, Union, cast +from opentelemetry.sdk._logs.severity import SeverityNumber, std_to_otlp from opentelemetry.sdk.environment_variables import ( OTEL_PYTHON_LOG_EMITTER_PROVIDER, ) -from opentelemetry.sdk.logs.severity import SeverityNumber, std_to_otlp from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util import ns_to_iso_str from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -124,7 +124,7 @@ def emit(self, log_data: LogData): @abc.abstractmethod def shutdown(self): - """Called when a :class:`opentelemetry.sdk.logs.LogEmitter` is shutdown""" + """Called when a :class:`opentelemetry.sdk._logs.LogEmitter` is shutdown""" @abc.abstractmethod def force_flush(self, timeout_millis: int = 30000): @@ -489,7 +489,7 @@ def get_log_emitter( """Returns a `LogEmitter` for use within a python process. This function is a convenience wrapper for - opentelemetry.sdk.logs.LogEmitterProvider.get_log_emitter. + opentelemetry.sdk._logs.LogEmitterProvider.get_log_emitter. If log_emitter_provider param is omitted the current configured one is used. """ diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/logs/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py similarity index 98% rename from opentelemetry-sdk/src/opentelemetry/sdk/logs/export/__init__.py rename to opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py index f831edc1d05..f65c967534b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/logs/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py @@ -22,7 +22,7 @@ from typing import IO, Callable, Deque, List, Optional, Sequence from opentelemetry.context import attach, detach, set_value -from opentelemetry.sdk.logs import LogData, LogProcessor, LogRecord +from opentelemetry.sdk._logs import LogData, LogProcessor, LogRecord from opentelemetry.util._time import _time_ns _logger = logging.getLogger(__name__) @@ -39,7 +39,7 @@ class LogExporter(abc.ABC): Interface to be implemented by services that want to export logs received in their own format. - To export data this MUST be registered to the :class`opentelemetry.sdk.logs.LogEmitter` using a + To export data this MUST be registered to the :class`opentelemetry.sdk._logs.LogEmitter` using a log processor. """ diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/logs/export/in_memory_log_exporter.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/in_memory_log_exporter.py similarity index 93% rename from opentelemetry-sdk/src/opentelemetry/sdk/logs/export/in_memory_log_exporter.py rename to opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/in_memory_log_exporter.py index 95cb8bccba9..68cb6b7389a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/logs/export/in_memory_log_exporter.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/in_memory_log_exporter.py @@ -15,8 +15,8 @@ import threading import typing -from opentelemetry.sdk.logs import LogData -from opentelemetry.sdk.logs.export import LogExporter, LogExportResult +from opentelemetry.sdk._logs import LogData +from opentelemetry.sdk._logs.export import LogExporter, LogExportResult class InMemoryLogExporter(LogExporter): diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/logs/severity.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/severity.py similarity index 100% rename from opentelemetry-sdk/src/opentelemetry/sdk/logs/severity.py rename to opentelemetry-sdk/src/opentelemetry/sdk/_logs/severity.py diff --git a/opentelemetry-sdk/tests/logs/test_export.py b/opentelemetry-sdk/tests/logs/test_export.py index 51eaeb3d897..964b44f7694 100644 --- a/opentelemetry-sdk/tests/logs/test_export.py +++ b/opentelemetry-sdk/tests/logs/test_export.py @@ -21,21 +21,21 @@ from unittest.mock import Mock, patch from opentelemetry.sdk import trace -from opentelemetry.sdk.logs import ( +from opentelemetry.sdk._logs import ( LogData, LogEmitterProvider, LogRecord, OTLPHandler, ) -from opentelemetry.sdk.logs.export import ( +from opentelemetry.sdk._logs.export import ( BatchLogProcessor, ConsoleExporter, SimpleLogProcessor, ) -from opentelemetry.sdk.logs.export.in_memory_log_exporter import ( +from opentelemetry.sdk._logs.export.in_memory_log_exporter import ( InMemoryLogExporter, ) -from opentelemetry.sdk.logs.severity import SeverityNumber +from opentelemetry.sdk._logs.severity import SeverityNumber from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace import TraceFlags diff --git a/opentelemetry-sdk/tests/logs/test_global_provider.py b/opentelemetry-sdk/tests/logs/test_global_provider.py index fc687d1961d..96083fca2af 100644 --- a/opentelemetry-sdk/tests/logs/test_global_provider.py +++ b/opentelemetry-sdk/tests/logs/test_global_provider.py @@ -18,20 +18,20 @@ from logging import WARNING from unittest.mock import patch -from opentelemetry.sdk import logs -from opentelemetry.sdk.environment_variables import ( - OTEL_PYTHON_LOG_EMITTER_PROVIDER, -) -from opentelemetry.sdk.logs import ( +from opentelemetry.sdk import _logs +from opentelemetry.sdk._logs import ( LogEmitterProvider, get_log_emitter_provider, set_log_emitter_provider, ) +from opentelemetry.sdk.environment_variables import ( + OTEL_PYTHON_LOG_EMITTER_PROVIDER, +) class TestGlobals(unittest.TestCase): def tearDown(self): - reload(logs) + reload(_logs) def check_override_not_allowed(self): """set_log_emitter_provider should throw a warning when overridden""" @@ -42,7 +42,7 @@ def check_override_not_allowed(self): test.output, [ ( - "WARNING:opentelemetry.sdk.logs:Overriding of current " + "WARNING:opentelemetry.sdk._logs:Overriding of current " "LogEmitterProvider is not allowed" ) ], @@ -50,14 +50,14 @@ def check_override_not_allowed(self): self.assertIs(provider, get_log_emitter_provider()) def test_set_tracer_provider(self): - reload(logs) + reload(_logs) provider = LogEmitterProvider() set_log_emitter_provider(provider) retrieved_provider = get_log_emitter_provider() self.assertEqual(provider, retrieved_provider) def test_tracer_provider_override_warning(self): - reload(logs) + reload(_logs) self.check_override_not_allowed() @patch.dict( @@ -65,11 +65,11 @@ def test_tracer_provider_override_warning(self): {OTEL_PYTHON_LOG_EMITTER_PROVIDER: "sdk_log_emitter_provider"}, ) def test_sdk_log_emitter_provider(self): - reload(logs) + reload(_logs) self.check_override_not_allowed() @patch.dict("os.environ", {OTEL_PYTHON_LOG_EMITTER_PROVIDER: "unknown"}) def test_unknown_log_emitter_provider(self): - reload(logs) + reload(_logs) with self.assertRaises(Exception): get_log_emitter_provider() diff --git a/opentelemetry-sdk/tests/logs/test_handler.py b/opentelemetry-sdk/tests/logs/test_handler.py index 474a87fe8df..d7942f912b8 100644 --- a/opentelemetry-sdk/tests/logs/test_handler.py +++ b/opentelemetry-sdk/tests/logs/test_handler.py @@ -17,8 +17,8 @@ from unittest.mock import Mock from opentelemetry.sdk import trace -from opentelemetry.sdk.logs import LogEmitter, OTLPHandler -from opentelemetry.sdk.logs.severity import SeverityNumber +from opentelemetry.sdk._logs import LogEmitter, OTLPHandler +from opentelemetry.sdk._logs.severity import SeverityNumber from opentelemetry.trace import INVALID_SPAN_CONTEXT diff --git a/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py b/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py index a3d095077a8..e55124edcc7 100644 --- a/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py +++ b/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py @@ -21,7 +21,7 @@ from abc import ABC, abstractmethod from unittest.mock import Mock -from opentelemetry.sdk.logs import ( +from opentelemetry.sdk._logs import ( ConcurrentMultiLogProcessor, LogEmitterProvider, LogProcessor, @@ -29,7 +29,7 @@ OTLPHandler, SynchronousMultiLogProcessor, ) -from opentelemetry.sdk.logs.severity import SeverityNumber +from opentelemetry.sdk._logs.severity import SeverityNumber class AnotherLogProcessor(LogProcessor):