Skip to content

Commit

Permalink
feat(api): add endpoint name to request log
Browse files Browse the repository at this point in the history
  • Loading branch information
vmttn committed Jul 3, 2023
1 parent f0f0b76 commit b15450d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/src/alembic/versions/2daaedf28c12_extended_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def upgrade() -> None:
)
op.add_column("api_request", sa.Column("client_host", sa.Text(), nullable=True))
op.add_column("api_request", sa.Column("client_port", sa.Integer(), nullable=True))
op.add_column("api_request", sa.Column("endpoint_name", sa.Text(), nullable=True))


def downgrade() -> None:
Expand Down
1 change: 1 addition & 0 deletions api/src/data_inclusion/api/core/request/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ class Request(Base):
query_params = sqla.Column(JSONB)
client_host = sqla.Column(sqla.Text)
client_port = sqla.Column(sqla.Integer)
endpoint_name = sqla.Column(sqla.Text)
3 changes: 3 additions & 0 deletions api/src/data_inclusion/api/core/request/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def save_request(request: requests.Request, response: responses.Response) -> Non
query_params=dict(request.query_params),
client_host=request.client.host,
client_port=request.client.port,
endpoint_name=request.scope["route"].name
if "route" in request.scope
else None,
)
session.add(request_instance)
session.commit()
1 change: 1 addition & 0 deletions api/tests/core/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_save_api_request_with_token(api_client, db_session):
assert request_instance.method == "GET"
assert request_instance.path_params == {"source": "foo", "id": "bar"}
assert request_instance.query_params == {"baz": "1"}
assert request_instance.endpoint_name == "retrieve_structure_endpoint"


def test_save_api_request_without_token(api_client, db_session):
Expand Down

0 comments on commit b15450d

Please sign in to comment.