Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Improve logging in core components #3332

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
815a0f3
:art: Refactor `register_plugin` steps for maintainability
ff137 Nov 6, 2024
ce9f8b7
:art: improve logging in register_package
ff137 Nov 6, 2024
3e5088e
:art: Rename method and remove redundant main call
ff137 Nov 6, 2024
59e4951
:art:
ff137 Nov 6, 2024
02011a8
:loud_sound: Add debug logging to Context Builder
ff137 Nov 7, 2024
1263191
:art: Deduplicate registering list of plugins
ff137 Nov 7, 2024
24c1426
:art:
ff137 Nov 7, 2024
8264688
:loud_sound: Add debug logging to init_context
ff137 Nov 7, 2024
b539ab0
:loud_sound: Add debug logging to load_protocol_version
ff137 Nov 7, 2024
595d391
:loud_sound: Add debug logging to load_protocols
ff137 Nov 7, 2024
b1a73a0
:loud_sound: Add debug logging to register_admin_routes
ff137 Nov 7, 2024
5e199d1
:loud_sound: Add debug logging to register_protocol_events
ff137 Nov 7, 2024
9cf03f6
:loud_sound: Add debug logging to post_process_routes
ff137 Nov 7, 2024
6330701
:art: Replace print statements with info logs
ff137 Nov 7, 2024
6a8febd
:art: Replace almost all print statements with info logs
ff137 Nov 7, 2024
8f46fdb
:loud_sound: Expand logging for Conductor setup
ff137 Nov 7, 2024
edde403
:art: Correct to uphold previous "Module doesn't exist" log behaviour
ff137 Nov 7, 2024
cc5ceab
:white_check_mark: Fix test by using assertLogs instead of capturing …
ff137 Nov 7, 2024
44e9807
Revert ":art: Rename method and remove redundant main call"
ff137 Nov 7, 2024
cfec6a6
:art:
ff137 Nov 7, 2024
500e4b2
:white_check_mark: Fix test by adding __name__ to mock object
ff137 Nov 7, 2024
5134d16
:art:
ff137 Nov 7, 2024
aa0765a
:sparkles: Add custom trace log level
ff137 Nov 7, 2024
190cc28
:art: Ensure trace level can only be added once
ff137 Nov 7, 2024
63ca170
:art: Add Logger
ff137 Nov 7, 2024
3641e2f
:art: Update newly added logs to be trace level instead of debug
ff137 Nov 7, 2024
bf1295f
:art: Update newly added logs to be trace level instead of debug
ff137 Nov 7, 2024
926eab1
:loud_sound: Expand logging for Conductor start and stop
ff137 Nov 7, 2024
32bb6b4
:white_check_mark: Add unit tests for adding trace level functionality
ff137 Nov 7, 2024
9d0275a
:white_check_mark: Reset the logging states before and after TestLogg…
ff137 Nov 7, 2024
a53b949
:art:
ff137 Nov 7, 2024
e77cf3f
:test_tube: Debug log assertion test failing sporadically
ff137 Nov 7, 2024
4f63240
:white_check_mark: Modify log assertion to be more robust
ff137 Nov 7, 2024
0ff9da4
:art:
ff137 Nov 7, 2024
9058784
:bug: Handle case that load_module return type is Optional
ff137 Nov 7, 2024
ebfbaaf
:loud_sound: Expand logging for ClassLoader
ff137 Nov 7, 2024
4312905
:loud_sound: Log a warning if resource not found, instead of passing
ff137 Nov 11, 2024
9d347bb
:art:
ff137 Nov 11, 2024
06ceea9
:art: Enable trace logs for remaining modules
ff137 Nov 11, 2024
838adcd
:bug: Fix registering and loading of modules
ff137 Nov 12, 2024
f342646
:loud_sound: Expand logging for Ledger Configuration
ff137 Nov 12, 2024
683c1c7
Merge branch 'main' into improve-logging
ff137 Nov 27, 2024
51ba3e7
:rewind: Revert `trace` log changes, and move to debug level
ff137 Nov 27, 2024
523d429
:sparkles: Add caching to ClassLoader.load_module
ff137 Nov 27, 2024
a2b32ce
:art: Improve log
ff137 Nov 27, 2024
a7e0a69
:art: Reduce log verbosity
ff137 Nov 27, 2024
35e6445
:sparkles: Add `lru_cache` to load_class and set maxsize
ff137 Nov 27, 2024
79c58f2
Merge branch 'main' into improve-logging
ff137 Nov 27, 2024
31782d4
:rewind: Revert addition of lru caching
ff137 Dec 2, 2024
15d4631
:art: Update logs / reduce verbosity
ff137 Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions acapy_agent/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""acapy_agent package entry point."""

import logging
import os
import sys

LOGGER = logging.getLogger(__name__)


def init_debug(args):
"""Initialize debugging environment."""
Expand All @@ -26,16 +29,18 @@ def init_debug(args):
import debugpy

debugpy.listen((DAP_HOST, DAP_PORT))
print(f"=== Waiting for debugger to attach to {DAP_HOST}:{DAP_PORT} ===")
LOGGER.info(
f"=== Waiting for debugger to attach to {DAP_HOST}:{DAP_PORT} ==="
)
debugpy.wait_for_client()
except ImportError:
print("debugpy library was not found")
LOGGER.error("debugpy library was not found")

if ENABLE_PYDEVD_PYCHARM or "--debug-pycharm" in args:
try:
import pydevd_pycharm

print(
LOGGER.info(
"aca-py remote debugging to "
f"{PYDEVD_PYCHARM_HOST}:{PYDEVD_PYCHARM_AGENT_PORT}"
)
Expand All @@ -47,7 +52,7 @@ def init_debug(args):
suspend=False,
)
except ImportError:
print("pydevd_pycharm library was not found")
LOGGER.error("pydevd_pycharm library was not found")


def run(args):
Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/anoncreds/default/did_indy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def supported_identifiers_regex(self) -> Pattern:

async def setup(self, context: InjectionContext):
"""Setup."""
print("Successfully registered DIDIndyRegistry")
LOGGER.info("Successfully registered DIDIndyRegistry")

async def get_schema(self, profile: Profile, schema_id: str) -> GetSchemaResult:
"""Get a schema from the registry."""
Expand Down
5 changes: 4 additions & 1 deletion acapy_agent/anoncreds/default/did_web/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""DID Web Registry."""

import logging
import re
from typing import Optional, Pattern, Sequence

Expand All @@ -17,6 +18,8 @@
)
from ...models.schema import AnonCredsSchema, GetSchemaResult, SchemaResult

LOGGER = logging.getLogger(__name__)


class DIDWebRegistry(BaseAnonCredsResolver, BaseAnonCredsRegistrar):
"""DIDWebRegistry."""
Expand All @@ -40,7 +43,7 @@ def supported_identifiers_regex(self) -> Pattern:

async def setup(self, context: InjectionContext):
"""Setup."""
print("Successfully registered DIDWebRegistry")
LOGGER.info("Successfully registered DIDWebRegistry")

async def get_schema(self, profile, schema_id: str) -> GetSchemaResult:
"""Get a schema from the registry."""
Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/anoncreds/default/legacy_indy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def supported_identifiers_regex(self) -> Pattern:

async def setup(self, context: InjectionContext):
"""Setup."""
print("Successfully registered LegacyIndyRegistry")
LOGGER.info("Successfully registered LegacyIndyRegistry")

@staticmethod
def make_schema_id(schema: AnonCredsSchema) -> str:
Expand Down
7 changes: 5 additions & 2 deletions acapy_agent/commands/provision.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provision command for setting up agent settings before starting."""

import asyncio
import logging
from typing import Sequence

from configargparse import ArgumentParser
Expand All @@ -22,6 +23,8 @@
from ..storage.base import BaseStorage
from . import PROG

LOGGER = logging.getLogger(__name__)


class ProvisionError(BaseError):
"""Base exception for provisioning errors."""
Expand Down Expand Up @@ -58,9 +61,9 @@ async def provision(settings: dict):
)

if await ledger_config(root_profile, public_did and public_did.did, True):
print("Ledger configured")
LOGGER.info("Ledger configured")
else:
print("Ledger not configured")
LOGGER.warning("Ledger not configured")

await root_profile.close()
except BaseError as e:
Expand Down
4 changes: 2 additions & 2 deletions acapy_agent/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def start_app(conductor: Conductor):

async def shutdown_app(conductor: Conductor):
"""Shut down."""
print("\nShutting down")
LOGGER.info("Shutting down")
await conductor.stop()


Expand Down Expand Up @@ -59,7 +59,7 @@ def execute(argv: Sequence[str] = None):
# Run the application
if uvloop:
uvloop.install()
print("uvloop installed")
LOGGER.info("uvloop installed")
run_loop(start_app(conductor), shutdown_app(conductor))


Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_registered(cls, category: Optional[str] = None):


def create_argument_parser(*, prog: Optional[str] = None):
"""Create am instance of an arg parser, force yaml format for external config."""
"""Create an instance of an arg parser, force yaml format for external config."""
return ArgumentParser(config_file_parser_class=YAMLConfigFileParser, prog=prog)


Expand Down
71 changes: 41 additions & 30 deletions acapy_agent/config/default_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Classes for configuring the default injection context."""

import logging

from ..anoncreds.registry import AnonCredsRegistry
from ..cache.base import BaseCache
from ..cache.in_memory import InMemoryCache
Expand All @@ -26,17 +28,22 @@
from .injection_context import InjectionContext
from .provider import CachedProvider, ClassProvider

LOGGER = logging.getLogger(__name__)


class DefaultContextBuilder(ContextBuilder):
"""Default context builder."""

async def build_context(self) -> InjectionContext:
"""Build the base injection context; set DIDComm prefix to emit."""
LOGGER.debug("Building new injection context")

context = InjectionContext(settings=self.settings)
context.settings.set_default("default_label", "Aries Cloud Agent")

if context.settings.get("timing.enabled"):
timing_log = context.settings.get("timing.log_file")
LOGGER.debug("Enabling timing collector with log file: %s", timing_log)
collector = Collector(log_path=timing_log)
context.injector.bind_instance(Collector, collector)

Expand All @@ -63,11 +70,8 @@ async def build_context(self) -> InjectionContext:

# DIDComm Messaging
if context.settings.get("experiment.didcomm_v2"):
from didcomm_messaging import (
CryptoService,
PackagingService,
RoutingService,
)
LOGGER.info("DIDComm v2 experimental mode enabled")
from didcomm_messaging import CryptoService, PackagingService, RoutingService
from didcomm_messaging.crypto.backend.askar import AskarCryptoService

context.injector.bind_instance(CryptoService, AskarCryptoService())
Expand All @@ -81,18 +85,21 @@ async def build_context(self) -> InjectionContext:

async def bind_providers(self, context: InjectionContext):
"""Bind various class providers."""
LOGGER.debug("Begin binding providers to context")

context.injector.bind_provider(ProfileManager, ProfileManagerProvider())

wallet_type = self.settings.get("wallet.type")
if wallet_type == "askar-anoncreds":
LOGGER.debug("Using AnonCreds tails server")
context.injector.bind_provider(
BaseTailsServer,
ClassProvider(
"acapy_agent.tails.anoncreds_tails_server.AnonCredsTailsServer",
),
)
else:
LOGGER.debug("Using Indy tails server")
context.injector.bind_provider(
BaseTailsServer,
ClassProvider(
Expand All @@ -104,12 +111,7 @@ async def bind_providers(self, context: InjectionContext):
context.injector.bind_provider(
BaseWireFormat,
CachedProvider(
# StatsProvider(
ClassProvider("acapy_agent.transport.pack_format.PackWireFormat"),
# (
# "encode_message", "parse_message"
# ),
# )
),
)

Expand All @@ -120,6 +122,7 @@ async def bind_providers(self, context: InjectionContext):
async def load_plugins(self, context: InjectionContext):
"""Set up plugin registry and load plugins."""

LOGGER.debug("Initializing plugin registry")
plugin_registry = PluginRegistry(
blocklist=self.settings.get("blocked_plugins", [])
)
Expand All @@ -130,18 +133,18 @@ async def load_plugins(self, context: InjectionContext):
if not self.settings.get("transport.disabled"):
plugin_registry.register_package("acapy_agent.protocols")

# Currently providing admin routes only
plugin_registry.register_plugin("acapy_agent.holder")

plugin_registry.register_plugin("acapy_agent.ledger")

plugin_registry.register_plugin("acapy_agent.messaging.jsonld")
plugin_registry.register_plugin("acapy_agent.resolver")
plugin_registry.register_plugin("acapy_agent.settings")
plugin_registry.register_plugin("acapy_agent.vc")
plugin_registry.register_plugin("acapy_agent.vc.data_integrity")
plugin_registry.register_plugin("acapy_agent.wallet")
plugin_registry.register_plugin("acapy_agent.wallet.keys")
# Define plugin groups
default_plugins = [
"acapy_agent.holder",
"acapy_agent.ledger",
"acapy_agent.messaging.jsonld",
"acapy_agent.resolver",
"acapy_agent.settings",
"acapy_agent.vc",
"acapy_agent.vc.data_integrity",
"acapy_agent.wallet",
"acapy_agent.wallet.keys",
]

anoncreds_plugins = [
"acapy_agent.anoncreds",
Expand All @@ -157,26 +160,34 @@ async def load_plugins(self, context: InjectionContext):
"acapy_agent.revocation",
]

def register_askar_plugins():
for plugin in askar_plugins:
def register_plugins(plugins: list[str], plugin_type: str):
"""Register a group of plugins with logging."""
LOGGER.debug("Registering %s plugins", plugin_type)
for plugin in plugins:
plugin_registry.register_plugin(plugin)

def register_askar_plugins():
register_plugins(askar_plugins, "askar")

def register_anoncreds_plugins():
for plugin in anoncreds_plugins:
plugin_registry.register_plugin(plugin)
register_plugins(anoncreds_plugins, "anoncreds")

if wallet_type == "askar-anoncreds":
register_anoncreds_plugins()
else:
register_askar_plugins()
register_plugins(default_plugins, "default")

if context.settings.get("multitenant.admin_enabled"):
LOGGER.debug("Multitenant admin enabled - registering additional plugins")
plugin_registry.register_plugin("acapy_agent.multitenant.admin")
register_askar_plugins()
register_anoncreds_plugins()
else:
if wallet_type == "askar-anoncreds":
register_anoncreds_plugins()
else:
register_askar_plugins()

# Register external plugins
for plugin_path in self.settings.get("external_plugins", []):
LOGGER.debug("Registering external plugin: %s", plugin_path)
plugin_registry.register_plugin(plugin_path)

# Register message protocols
Expand Down
Loading