Skip to content

Commit

Permalink
fix: setup middleware without client argument for starlette (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-f-santos authored Jan 22, 2024
1 parent a23afc6 commit 1ad759a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .ci/.matrix_exclude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,5 @@ exclude:
FRAMEWORK: pyodbc-newest # error on wheel
- VERSION: python-3.12
FRAMEWORK: cassandra-newest # c extension issue
- VERSION: python-3.12
FRAMEWORK: starlette-newest # waiting for 3.12.2 for this fix: https://github.com/python/cpython/pull/111221
2 changes: 1 addition & 1 deletion elasticapm/contrib/starlette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ElasticAPM:
>>> elasticapm.capture_message('hello, world!')
"""

def __init__(self, app: ASGIApp, client: Optional[Client], **kwargs) -> None:
def __init__(self, app: ASGIApp, client: Optional[Client] = None, **kwargs) -> None:
"""
Args:
Expand Down
8 changes: 8 additions & 0 deletions tests/contrib/asyncio/starlette_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,11 @@ def test_transaction_active_in_base_exception_handler(app, elasticapm_client):
assert exc.transaction_id

assert len(elasticapm_client.events[constants.TRANSACTION]) == 1


def test_middleware_without_client_arg():
with mock.patch.dict("os.environ", {"ELASTIC_APM_SERVICE_NAME": "foo"}):
app = Starlette()
elasticapm = ElasticAPM(app)

assert elasticapm.client.config.service_name == "foo"

0 comments on commit 1ad759a

Please sign in to comment.