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

🎨 Ensure appropriate log levels for a production context #980

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ def create_app() -> FastAPI:
# additional yaml version of openapi.json
@app.get("/openapi.yaml", include_in_schema=False)
def read_openapi_yaml() -> Response:
logger.info("GET request received: OpenAPI yaml endpoint")
logger.debug("GET request received: OpenAPI yaml endpoint")
openapi_json = app.openapi()
yaml_s = io.StringIO()
yaml.dump(openapi_json, yaml_s, allow_unicode=True, sort_keys=False)
logger.info("Returning OpenAPI yaml text.")
logger.debug("Returning OpenAPI yaml text.")
return Response(content=yaml_s.getvalue(), media_type="text/yaml")


Expand Down
30 changes: 15 additions & 15 deletions app/routes/admin/tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ async def create_tenant(
) -> CreateTenantResponse:
"""Create a new tenant."""
bound_logger = logger.bind(body=body)
bound_logger.info("POST request received: Starting tenant creation")
bound_logger.debug("POST request received: Starting tenant creation")

roles = body.roles
wallet_label = body.wallet_label
wallet_name = body.wallet_name or uuid4().hex

bound_logger.info("Assert that requested label is not used in trust registry")
bound_logger.debug("Assert that requested label is not used in trust registry")
try:
actor_name_exists = await assert_actor_name(wallet_label)
except TrustRegistryException as e:
Expand Down Expand Up @@ -98,7 +98,7 @@ async def create_tenant(
)
async with get_tenant_admin_controller(admin_auth) as admin_controller:
try:
bound_logger.info("Creating wallet")
bound_logger.debug("Creating wallet")
wallet_response = await handle_acapy_call(
logger=bound_logger,
acapy_call=admin_controller.multitenancy.create_wallet,
Expand All @@ -121,7 +121,7 @@ async def create_tenant(

try:
if roles:
bound_logger.info(
bound_logger.debug(
"Onboarding `{}` with requested roles: `{}`", wallet_label, roles
)
onboard_result = await onboard_tenant(
Expand Down Expand Up @@ -189,7 +189,7 @@ async def delete_tenant_by_id(
):
"""Delete tenant by id."""
bound_logger = logger.bind(body={"wallet_id": wallet_id})
bound_logger.info("DELETE request received: Deleting tenant by id")
bound_logger.debug("DELETE request received: Deleting tenant by id")

async with get_tenant_admin_controller(admin_auth) as admin_controller:
await get_wallet_and_assert_valid_group(
Expand Down Expand Up @@ -217,7 +217,7 @@ async def delete_tenant_by_id(
acapy_call=admin_controller.multitenancy.delete_wallet,
wallet_id=wallet_id,
)
bound_logger.info("Successfully deleted tenant.")
bound_logger.debug("Successfully deleted tenant.")


@router.get("/{wallet_id}/access-token", response_model=TenantAuth)
Expand All @@ -227,7 +227,7 @@ async def get_wallet_auth_token(
admin_auth: AcaPyAuthVerified = Depends(acapy_auth_tenant_admin),
) -> TenantAuth:
bound_logger = logger.bind(body={"wallet_id": wallet_id})
bound_logger.info("GET request received: Access token for tenant")
bound_logger.debug("GET request received: Access token for tenant")

async with get_tenant_admin_controller(admin_auth) as admin_controller:
await get_wallet_and_assert_valid_group(
Expand All @@ -246,7 +246,7 @@ async def get_wallet_auth_token(
)

response = TenantAuth(access_token=tenant_api_key(response.token))
bound_logger.info("Successfully retrieved access token.")
bound_logger.debug("Successfully retrieved access token.")
return response


Expand All @@ -259,7 +259,7 @@ async def update_tenant(
) -> Tenant:
"""Update tenant by id."""
bound_logger = logger.bind(body={"wallet_id": wallet_id, "body": body})
bound_logger.info("PUT request received: Update tenant")
bound_logger.debug("PUT request received: Update tenant")

async with get_tenant_admin_controller(admin_auth) as admin_controller:
await get_wallet_and_assert_valid_group(
Expand All @@ -274,7 +274,7 @@ async def update_tenant(
)

response = tenant_from_wallet_record(wallet)
bound_logger.info("Successfully updated tenant.")
bound_logger.debug("Successfully updated tenant.")
return response


Expand All @@ -286,7 +286,7 @@ async def get_tenant(
) -> Tenant:
"""Get tenant by id."""
bound_logger = logger.bind(body={"wallet_id": wallet_id})
bound_logger.info("GET request received: Fetch tenant by id")
bound_logger.debug("GET request received: Fetch tenant by id")

async with get_tenant_admin_controller(admin_auth) as admin_controller:
wallet = await get_wallet_and_assert_valid_group(
Expand All @@ -297,7 +297,7 @@ async def get_tenant(
)

response = tenant_from_wallet_record(wallet)
bound_logger.info("Successfully fetched tenant from wallet record.")
bound_logger.debug("Successfully fetched tenant from wallet record.")
return response


Expand All @@ -311,7 +311,7 @@ async def get_tenants(
) -> List[Tenant]:
"""Get all tenants, or fetch by wallet name."""
bound_logger = logger.bind(body={"wallet_name": wallet_name, "group_id": group_id})
bound_logger.info(
bound_logger.debug(
"GET request received: Fetch tenants by wallet name and/or group id"
)

Expand All @@ -328,9 +328,9 @@ async def get_tenants(
wallets_list = wallets.results

if not wallets_list:
bound_logger.info("No wallets found.")
bound_logger.debug("No wallets found.")
return []

response = [tenant_from_wallet_record(record) for record in wallets_list]
bound_logger.info("Successfully fetched wallets.")
bound_logger.debug("Successfully fetched wallets.")
return response
10 changes: 5 additions & 5 deletions app/routes/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def create_invitation(
Contains an invitation object, an invitation url, and a connection id for this invite.
"""
bound_logger = logger.bind(body=body)
bound_logger.info("POST request received: Create invitation")
bound_logger.debug("POST request received: Create invitation")
if body is None:
body = CreateInvitation()

Expand Down Expand Up @@ -119,7 +119,7 @@ async def accept_invitation(
The record of your new connection
"""
bound_logger = logger.bind(body=body)
bound_logger.info("POST request received: Accept invitation")
bound_logger.debug("POST request received: Accept invitation")
async with client_from_auth(auth) as aries_controller:
connection_record = await handle_acapy_call(
logger=bound_logger,
Expand Down Expand Up @@ -175,7 +175,7 @@ async def get_connections(
List[Connection]
A list of connection records
"""
logger.info("GET request received: Get connections")
logger.debug("GET request received: Get connections")

async with client_from_auth(auth) as aries_controller:
connections = await handle_acapy_call(
Expand Down Expand Up @@ -227,7 +227,7 @@ async def get_connection_by_id(
The connection record
"""
bound_logger = logger.bind(body={"connection_id": connection_id})
bound_logger.info("GET request received: Get connection by ID")
bound_logger.debug("GET request received: Get connection by ID")
async with client_from_auth(auth) as aries_controller:
connection = await handle_acapy_call(
logger=bound_logger,
Expand Down Expand Up @@ -264,7 +264,7 @@ async def delete_connection_by_id(
status_code: 204
"""
bound_logger = logger.bind(body={"connection_id": connection_id})
bound_logger.info("DELETE request received: Delete connection by ID")
bound_logger.debug("DELETE request received: Delete connection by ID")

async with client_from_auth(auth) as aries_controller:
await handle_acapy_call(
Expand Down
28 changes: 13 additions & 15 deletions app/routes/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def create_schema(
The created schema object
"""
bound_logger = logger.bind(body=schema)
bound_logger.info("POST request received: Create schema (publish and register)")
bound_logger.debug("POST request received: Create schema (publish and register)")

async with get_governance_controller(governance_auth) as aries_controller:
schema_response = await schemas_service.create_schema(
Expand Down Expand Up @@ -127,7 +127,7 @@ async def get_schemas(
"schema_version": schema_version,
}
)
bound_logger.info("GET request received: Get created schemas")
bound_logger.debug("GET request received: Get created schemas")

async with client_from_auth(auth) as aries_controller:
if not is_governance: # regular tenant is calling endpoint
Expand All @@ -153,9 +153,9 @@ async def get_schemas(
raise

if schemas:
bound_logger.info("Successfully fetched schemas.")
bound_logger.debug("Successfully fetched schemas.")
else:
bound_logger.info("No schemas matching request.")
bound_logger.debug("No schemas matching request.")

return schemas

Expand Down Expand Up @@ -188,7 +188,7 @@ async def get_schema(
The schema object
"""
bound_logger = logger.bind(body={"schema_id": schema_id})
bound_logger.info("GET request received: Get schema by id")
bound_logger.debug("GET request received: Get schema by id")

async with client_from_auth(auth) as aries_controller:
schema = await handle_acapy_call(
Expand All @@ -198,11 +198,10 @@ async def get_schema(
)

if not schema.var_schema:
bound_logger.info("Bad request: schema id not found.")
raise HTTPException(404, f"Schema with id {schema_id} not found.")

result = credential_schema_from_acapy(schema.var_schema)
bound_logger.info("Successfully fetched schema by id.")
bound_logger.debug("Successfully fetched schema by id.")
return result


Expand Down Expand Up @@ -248,7 +247,7 @@ async def create_credential_definition(
"support_revocation": credential_definition.support_revocation,
}
)
bound_logger.info("POST request received: Create credential definition")
bound_logger.debug("POST request received: Create credential definition")

support_revocation = credential_definition.support_revocation

Expand All @@ -271,7 +270,7 @@ async def create_credential_definition(
max_attempts=3,
retry_delay=0.5,
)
bound_logger.info("Successfully created credential definition.")
bound_logger.debug("Successfully created credential definition.")
return result


Expand Down Expand Up @@ -320,7 +319,7 @@ async def get_credential_definitions(
"schema_version": schema_version,
}
)
bound_logger.info(
bound_logger.debug(
"GET request received: Get credential definitions created by agent"
)

Expand All @@ -337,9 +336,9 @@ async def get_credential_definitions(
)

if credential_definitions:
bound_logger.info("Successfully fetched credential definitions.")
bound_logger.debug("Successfully fetched credential definitions.")
else:
bound_logger.info("No credential definitions matching request.")
bound_logger.debug("No credential definitions matching request.")

return credential_definitions

Expand Down Expand Up @@ -374,7 +373,7 @@ async def get_credential_definition_by_id(
bound_logger = logger.bind(
body={"credential_definition_id": credential_definition_id}
)
bound_logger.info("GET request received: Get credential definition by id")
bound_logger.debug("GET request received: Get credential definition by id")

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Getting credential definition")
Expand All @@ -385,7 +384,6 @@ async def get_credential_definition_by_id(
)

if not credential_definition.credential_definition:
bound_logger.info("Bad request: credential definition id not found.")
raise HTTPException(
404,
f"Credential Definition with id {credential_definition_id} not found.",
Expand All @@ -405,5 +403,5 @@ async def get_credential_definition_by_id(
)
cloudapi_credential_definition.schema_id = schema.id

bound_logger.info("Successfully fetched credential definition.")
bound_logger.debug("Successfully fetched credential definition.")
return cloudapi_credential_definition
Loading
Loading