Skip to content

fix: setup middleware without client argument for starlette #1952

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

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
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"