Skip to content

Commit

Permalink
feat(sdk): structured logging (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousben authored Dec 6, 2024
1 parent 0dd560c commit 48a5a40
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
41 changes: 27 additions & 14 deletions python-sdk/indexify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import sys
import threading
import time
from importlib.metadata import version
from typing import Annotated, List, Optional

import nanoid
import structlog
import typer
from rich.console import Console
from rich.panel import Panel
Expand All @@ -32,6 +34,7 @@
}
)

logging = structlog.get_logger(module=__name__)
console = Console(theme=custom_theme)

app = typer.Typer(pretty_exceptions_enable=False, no_args_is_help=True)
Expand Down Expand Up @@ -158,6 +161,9 @@ def build_default_image():
@app.command(help="Joins the extractors to the coordinator server")
def executor(
server_addr: str = "localhost:8900",
dev: Annotated[
bool, typer.Option("--dev", "-d", help="Run the executor in development mode")
] = False,
workers: Annotated[
int, typer.Option(help="number of worker processes for extraction")
] = 1,
Expand All @@ -174,19 +180,26 @@ def executor(
"1", help="Requested Image Version for this executor"
),
):
# configure structured logging
if not dev:
processors = [
structlog.processors.dict_tracebacks,
structlog.processors.JSONRenderer(),
]
structlog.configure(processors=processors)

id = nanoid.generate()
console.print(
Panel(
f"Number of workers: {workers}\n"
f"Config path: {config_path}\n"
f"Server address: {server_addr}\n"
f"Executor ID: {id}\n"
f"Executor cache: {executor_cache}\n"
f"Name Alias: {name_alias}"
f"Image Version: {image_version}\n",
title="Agent Configuration",
border_style="info",
)
executor_version = version("indexify")
logging.info(
"executor started",
workers=workers,
server_addr=server_addr,
config_path=config_path,
executor_id=id,
executor_version=executor_version,
executor_cache=executor_cache,
name_alias=name_alias,
image_version=image_version,
)

from pathlib import Path
Expand All @@ -208,8 +221,8 @@ def executor(

try:
asyncio.get_event_loop().run_until_complete(agent.run())
except asyncio.CancelledError as ex:
console.print(Text(f"Exiting gracefully: {ex}", style="bold yellow"))
except asyncio.CancelledError:
logging.info("graceful shutdown")


def _create_image(image: Image, python_sdk_path):
Expand Down
7 changes: 6 additions & 1 deletion python-sdk/indexify/executor/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ async def run(self):
image_version=image_version,
labels=runtime_probe.labels,
).model_dump()
logging.info("registering_executor", executor_id=self._executor_id, url=url)
logging.info(
"registering_executor",
executor_id=self._executor_id,
url=url,
executor_version=executor_version,
)
try:
async with get_httpx_client(self._config_path, True) as client:
async with aconnect_sse(
Expand Down
16 changes: 8 additions & 8 deletions python-sdk/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48a5a40

Please sign in to comment.