Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Sep 4, 2024
1 parent b0d36a9 commit ed13d15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- sdk: Add support for log formatting
([#4137](https://github.com/open-telemetry/opentelemetry-python/pull/4166))
- Implement events sdk
([#4137](https://github.com/open-telemetry/opentelemetry-python/pull/4166))
([#4176](https://github.com/open-telemetry/opentelemetry-python/pull/4176))

## Version 1.27.0/0.48b0 (2024-08-28)

Expand Down
19 changes: 10 additions & 9 deletions opentelemetry-sdk/src/opentelemetry/sdk/_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
from typing import Optional

from opentelemetry import trace
from opentelemetry._logs import get_logger_provider, SeverityNumber
from opentelemetry._events import EventLoggerProvider, EventLogger, Event
from opentelemetry.sdk._logs import LoggerProvider, Logger, LogRecord

from opentelemetry._events import Event, EventLogger, EventLoggerProvider
from opentelemetry._logs import SeverityNumber, get_logger_provider
from opentelemetry.sdk._logs import Logger, LoggerProvider, LogRecord
from opentelemetry.util.types import Attributes


_logger = logging.getLogger(__name__)


Expand All @@ -39,7 +37,9 @@ def get_event_logger(
) -> EventLogger:
if not name:
_logger.warning("EventLogger created with invalid name: %s", name)
return EventLogger(self._logger_provider, name, version, schema_url, attributes)
return EventLogger(
self._logger_provider, name, version, schema_url, attributes
)

def force_flush(self, timeout_millis: int = 30000) -> bool:
self._logger_provider.force_flush(timeout_millis)
Expand All @@ -60,8 +60,9 @@ def __init__(
schema_url=schema_url,
attributes=attributes,
)
self._logger: Logger = logger_provider.get_logger(name, version, schema_url, attributes)

self._logger: Logger = logger_provider.get_logger(
name, version, schema_url, attributes
)

def emit(self, event: Event) -> None:
span_context = trace.get_current_span().get_span_context()
Expand All @@ -75,6 +76,6 @@ def emit(self, event: Event) -> None:
severity_number=event.severity_number or SeverityNumber.INFO,
body=event.body,
resource=self._logger.resource,
attributes=event.attributes
attributes=event.attributes,
)
self._logger.emit(log_record)
18 changes: 6 additions & 12 deletions opentelemetry-sdk/tests/events/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from time import time_ns
from unittest.mock import Mock, patch

from opentelemetry._events import Event
from opentelemetry._logs import set_logger_provider, SeverityNumber
from opentelemetry._logs import SeverityNumber, set_logger_provider
from opentelemetry.sdk._events import EventLoggerProvider
from opentelemetry.sdk._logs import LoggerProvider
from opentelemetry.sdk._logs._internal import Logger, NoOpLogger
from opentelemetry.sdk.environment_variables import OTEL_SDK_DISABLED


class TestEventLoggerProvider(unittest.TestCase):
def test_event_logger_provider(self):
logger_provider = LoggerProvider()
Expand Down Expand Up @@ -88,17 +88,14 @@ def test_event_logger(self, logger_mock):
logger_provider = LoggerProvider()
logger_mock_inst = Mock()
logger_mock.return_value = logger_mock_inst
event_logger = EventLoggerProvider(logger_provider).get_event_logger(
EventLoggerProvider(logger_provider).get_event_logger(
"name",
version="version",
schema_url="schema_url",
attributes={"key": "value"},
)
logger_mock.assert_called_once_with(
"name",
"version",
"schema_url",
{"key": "value"}
"name", "version", "schema_url", {"key": "value"}
)

@patch("opentelemetry.sdk._events.LogRecord")
Expand All @@ -114,10 +111,7 @@ def test_event_logger_emit(self, logger_mock, log_record_mock):
attributes={"key": "value"},
)
logger_mock.assert_called_once_with(
"name",
"version",
"schema_url",
{"key": "value"}
"name", "version", "schema_url", {"key": "value"}
)
now = Mock()
trace_id = Mock()
Expand All @@ -134,7 +128,7 @@ def test_event_logger_emit(self, logger_mock, log_record_mock):
attributes={
"key": "val",
"foo": "bar",
}
},
)
log_record_mock_inst = Mock()
log_record_mock.return_value = log_record_mock_inst
Expand Down

0 comments on commit ed13d15

Please sign in to comment.