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 51 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
42926e1
:art: Refactor `register_plugin` steps for maintainability
ff137 Nov 6, 2024
1c09672
:art: improve logging in register_package
ff137 Nov 6, 2024
6fcd026
:art: Rename method and remove redundant main call
ff137 Nov 6, 2024
eeeead6
:art:
ff137 Nov 6, 2024
7e793c2
:loud_sound: Add debug logging to Context Builder
ff137 Nov 7, 2024
a98986a
:art: Deduplicate registering list of plugins
ff137 Nov 7, 2024
07f6a24
:art:
ff137 Nov 7, 2024
9b3d4c7
:loud_sound: Add debug logging to init_context
ff137 Nov 7, 2024
d32cd96
:loud_sound: Add debug logging to load_protocol_version
ff137 Nov 7, 2024
06f7072
:loud_sound: Add debug logging to load_protocols
ff137 Nov 7, 2024
902eede
:loud_sound: Add debug logging to register_admin_routes
ff137 Nov 7, 2024
2f4c4dc
:loud_sound: Add debug logging to register_protocol_events
ff137 Nov 7, 2024
2ae3d83
:loud_sound: Add debug logging to post_process_routes
ff137 Nov 7, 2024
f0b08a0
:art: Replace print statements with info logs
ff137 Nov 7, 2024
18e8a13
:art: Replace almost all print statements with info logs
ff137 Nov 7, 2024
6964339
:loud_sound: Expand logging for Conductor setup
ff137 Nov 7, 2024
dddae70
:art: Correct to uphold previous "Module doesn't exist" log behaviour
ff137 Nov 7, 2024
0119934
Revert ":art: Rename method and remove redundant main call"
ff137 Nov 7, 2024
8c69f3c
:art:
ff137 Nov 7, 2024
5f38767
:white_check_mark: Fix test by adding __name__ to mock object
ff137 Nov 7, 2024
5314ec5
:art:
ff137 Nov 7, 2024
fc3a9d5
:sparkles: Add custom trace log level
ff137 Nov 7, 2024
059d253
:art: Ensure trace level can only be added once
ff137 Nov 7, 2024
4f34138
:art: Add Logger
ff137 Nov 7, 2024
ea66fb1
:art: Update newly added logs to be trace level instead of debug
ff137 Nov 7, 2024
0f41555
:art: Update newly added logs to be trace level instead of debug
ff137 Nov 7, 2024
641d381
:loud_sound: Expand logging for Conductor start and stop
ff137 Nov 7, 2024
2bf4de7
:white_check_mark: Add unit tests for adding trace level functionality
ff137 Nov 7, 2024
cefafa9
:white_check_mark: Reset the logging states before and after TestLogg…
ff137 Nov 7, 2024
368cbf2
:art:
ff137 Nov 7, 2024
84963ea
:art:
ff137 Nov 7, 2024
59a491d
:bug: Handle case that load_module return type is Optional
ff137 Nov 7, 2024
14cb686
:loud_sound: Expand logging for ClassLoader
ff137 Nov 7, 2024
ef1d729
:loud_sound: Log a warning if resource not found, instead of passing
ff137 Nov 11, 2024
e473304
:art:
ff137 Nov 11, 2024
4f42f40
:art: Enable trace logs for remaining modules
ff137 Nov 11, 2024
84764d5
:bug: Fix registering and loading of modules
ff137 Nov 12, 2024
f17c8ed
:loud_sound: Expand logging for Ledger Configuration
ff137 Nov 12, 2024
d28c80b
:rewind: Revert `trace` log changes, and move to debug level
ff137 Nov 27, 2024
7b109c2
:sparkles: Add caching to ClassLoader.load_module
ff137 Nov 27, 2024
f94192d
:art: Improve log
ff137 Nov 27, 2024
9d64d0f
:art: Reduce log verbosity
ff137 Nov 27, 2024
f1b8f75
:sparkles: Add `lru_cache` to load_class and set maxsize
ff137 Nov 27, 2024
5f4c1e3
:rewind: Revert addition of lru caching
ff137 Dec 2, 2024
c646d68
:art: Update logs / reduce verbosity
ff137 Dec 2, 2024
7f7b7d0
:art: Reduce repetition
ff137 Dec 4, 2024
199d5bb
:art: Log warning when StorageNotFoundError encountered, instead of e…
ff137 Dec 5, 2024
a108fb4
:art: Set Shutdown log level to fatal, with exc_info
ff137 Dec 5, 2024
88b23d1
:art: Log warning for bad credential format, instead of always except…
ff137 Dec 5, 2024
5bb6237
:construction: Add exc_info to error log for debugging
ff137 Dec 5, 2024
143b9ba
:art: Replace AskarError with ProfileError
ff137 Dec 5, 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 @@ -42,7 +42,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 @@ -18,6 +19,8 @@
from ...models.schema import AnonCredsSchema, GetSchemaResult, SchemaResult
from ...models.schema_info import AnoncredsSchemaInfo

LOGGER = logging.getLogger(__name__)


class DIDWebRegistry(BaseAnonCredsResolver, BaseAnonCredsRegistrar):
"""DIDWebRegistry."""
Expand All @@ -41,7 +44,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 @@ -145,7 +145,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
73 changes: 42 additions & 31 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 Down Expand Up @@ -27,17 +29,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 @@ -64,11 +71,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 @@ -82,18 +86,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 @@ -105,12 +112,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 @@ -127,6 +129,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 @@ -137,19 +140,19 @@ 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.connections")
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.connections",
"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 @@ -165,26 +168,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