Skip to content

Commit 1ad759a

Browse files
fix: setup middleware without client argument for starlette (#1952)
1 parent a23afc6 commit 1ad759a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.ci/.matrix_exclude.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,5 @@ exclude:
279279
FRAMEWORK: pyodbc-newest # error on wheel
280280
- VERSION: python-3.12
281281
FRAMEWORK: cassandra-newest # c extension issue
282+
- VERSION: python-3.12
283+
FRAMEWORK: starlette-newest # waiting for 3.12.2 for this fix: https://github.com/python/cpython/pull/111221

elasticapm/contrib/starlette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ElasticAPM:
105105
>>> elasticapm.capture_message('hello, world!')
106106
"""
107107

108-
def __init__(self, app: ASGIApp, client: Optional[Client], **kwargs) -> None:
108+
def __init__(self, app: ASGIApp, client: Optional[Client] = None, **kwargs) -> None:
109109
"""
110110
111111
Args:

tests/contrib/asyncio/starlette_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,11 @@ def test_transaction_active_in_base_exception_handler(app, elasticapm_client):
534534
assert exc.transaction_id
535535

536536
assert len(elasticapm_client.events[constants.TRANSACTION]) == 1
537+
538+
539+
def test_middleware_without_client_arg():
540+
with mock.patch.dict("os.environ", {"ELASTIC_APM_SERVICE_NAME": "foo"}):
541+
app = Starlette()
542+
elasticapm = ElasticAPM(app)
543+
544+
assert elasticapm.client.config.service_name == "foo"

0 commit comments

Comments
 (0)