Skip to content

Commit

Permalink
Small improvements of OpenLineageClient.emit
Browse files Browse the repository at this point in the history
* Do not print debug message "client will emit event" if event is filtered out
* Do not fail if transport is not set up if event is ignored
* Update annotations a bit

Signed-off-by: Maxim Martynov <martinov_m_s_@mail.ru>
  • Loading branch information
dolfinus committed Mar 27, 2024
1 parent 2d1ee64 commit 86a1bb7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client/python/openlineage/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ def _initialize_url(
),
)

def emit(self, event: Union[RunEvent, DatasetEvent | JobEvent]) -> None: # noqa: UP007
def emit(self, event: RunEvent | DatasetEvent | JobEvent) -> None:
if not (isinstance(event, (RunEvent, DatasetEvent, JobEvent))):
msg = "`emit` only accepts RunEvent, DatasetEvent, JobEvent classes"
raise ValueError(msg) # noqa: TRY004
if self._filters and self.filter_event(event) is None:
return
if not self.transport:
log.error("Tried to emit OpenLineage event, but transport is not configured.")
return

if log.isEnabledFor(logging.DEBUG):
val = Serde.to_json(event).encode("utf-8")
log.debug("OpenLineageClient will emit event %s", val)
if self._filters and self.filter_event(event) is None:
return
if event:
self.transport.emit(event)
self.transport.emit(event)

@classmethod
def from_environment(cls: type[_T]) -> _T:
Expand All @@ -112,8 +112,8 @@ def from_dict(cls: type[_T], config: dict[str, str]) -> _T:

def filter_event(
self,
event: Union[RunEvent, DatasetEvent, JobEvent], # noqa: UP007
) -> Union[RunEvent, DatasetEvent, JobEvent] | None: # noqa: UP007
event: RunEvent | DatasetEvent | JobEvent,
) -> RunEvent | DatasetEvent | JobEvent | None:
"""Filters jobs according to config-defined events"""
for _filter in self._filters:
if isinstance(event, RunEvent) and _filter.filter_event(event) is None:
Expand Down

0 comments on commit 86a1bb7

Please sign in to comment.