Skip to content

Commit

Permalink
add thread + postgres instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgorana committed Sep 19, 2024
1 parent 31528af commit c748a6d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/grid/backend/grid/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ disable_existing_loggers: True

formatters:
default:
format: "ROOT %(asctime)s - %(levelname)s - %(name)s - %(message)s"
format: "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
uvicorn.default:
"()": uvicorn.logging.DefaultFormatter
format: "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
Expand Down
2 changes: 1 addition & 1 deletion packages/syft/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ telemetry =
opentelemetry-instrumentation-botocore==0.48b0
opentelemetry-instrumentation-logging==0.48b0
opentelemetry-instrumentation-sqlalchemy==0.48b0
opentelemetry-instrumentation-threading==0.48b0
; opentelemetry-instrumentation-asyncio==0.48b0
; opentelemetry-instrumentation-sqlite3==0.48b0
; opentelemetry-instrumentation-threading==0.48b0
; opentelemetry-instrumentation-jinja2==0.48b0
; opentelemetry-instrumentation-system-metrics==0.48b0

Expand Down
3 changes: 3 additions & 0 deletions packages/syft/src/syft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
from .util.commit import __commit__
from .util.patch_ipython import patch_ipython
from .util.telemetry import instrument
from .util.telemetry import instrument_threads
from .util.util import autocache
from .util.util import get_root_data_path
from .util.version_compare import make_requires
Expand All @@ -103,6 +104,8 @@
sys.path.append(str(Path(__file__)))


instrument_threads()

patch_ipython()


Expand Down
2 changes: 2 additions & 0 deletions packages/syft/src/syft/store/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
from ...serde.serializable import serializable
from ...server.credentials import SyftVerifyKey
from ...types.uid import UID
from ...util.telemetry import instrument_sqlalchemny
from .schema import PostgresBase
from .schema import SQLiteBase

logger = logging.getLogger(__name__)
instrument_sqlalchemny()


@serializable(canonical_name="DBConfig", version=1)
Expand Down
29 changes: 28 additions & 1 deletion packages/syft/src/syft/util/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def instrument_fastapi(app: Any) -> None:
logger.error(f"Failed to load FastAPIInstrumentor. {e}")



def instrument_botocore() -> None:
if not TRACING_ENABLED:
return
Expand All @@ -88,4 +87,32 @@ def instrument_botocore() -> None:
logger.error(f"Failed to load BotocoreInstrumentor. {e}")


def instrument_threads() -> None:
if not TRACING_ENABLED:
return

try:
# third party
from opentelemetry.instrumentation.threading import ThreadingInstrumentor

ThreadingInstrumentor().instrument()
logger.info("Added OTEL ThreadingInstrumentor")
except Exception as e:
logger.error(f"Failed to load ThreadingInstrumentor. {e}")


def instrument_sqlalchemny() -> None:
if not TRACING_ENABLED:
return

try:
# third party
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor

SQLAlchemyInstrumentor().instrument(enable_commenter=True, commenter_options={})
logger.info("Added OTEL SQLAlchemyInstrumentor")
except Exception as e:
logger.error(f"Failed to load SQLAlchemyInstrumentor. {e}")


instrument = setup_instrumenter()
1 change: 0 additions & 1 deletion packages/syft/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from syft.service.user import user



def patch_protocol_file(filepath: Path):
dp = get_data_protocol()
shutil.copyfile(src=dp.file_path, dst=filepath)
Expand Down

0 comments on commit c748a6d

Please sign in to comment.