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

Starlette Application Stops When ElasticAPM Server is Unreachable #2031

Closed
Impro02 opened this issue Apr 25, 2024 · 8 comments
Closed

Starlette Application Stops When ElasticAPM Server is Unreachable #2031

Impro02 opened this issue Apr 25, 2024 · 8 comments
Labels
agent-python community Issues opened by the community triage Issues awaiting triage

Comments

@Impro02
Copy link

Impro02 commented Apr 25, 2024

Describe the bug:
When integrating ElasticAPM middleware with a Starlette application, the application ceases to function if the ElasticAPM server is unreachable. This occurs under various circumstances, such as an incorrect URL, proxy issues, or certificate verification failures.

To Reproduce

  • Set up a Starlette application with ElasticAPM middleware.
  • Configure the ElasticAPM middleware to point to a non-existent APM server URL (to simulate server downtime).
  • Start the Starlette application.
  • Observe logging output indicating that the APM server cannot be reached.
  • After approximately 30 seconds, the application stops.

Environment (please complete the following information)

  • OS: Linux/Windows
  • Python version: 3.11
  • Framework and version: Starlette/FastAPI
  • APM Server version:
  • Agent version:

Additional context

Add any other context about the problem here.

This issue poses a significant risk to application reliability, as any downtime or configuration issue with the ElasticAPM server directly affects the availability of all services using the Starlette framework with ElasticAPM middleware.

  • Agent config options
    Click to expand apm = _make_apm_client( { "SERVICE_NAME": "XX", "ENVIRONMENT": "DEV", "SERVER_URL": "https://...", "SERVER_CERT": "path_to_cer", "VERIFY_SERVER_CERT": True, } ) app.add_middleware(_ElasticAPM, client=apm)
  • requirements.txt:
    Click to expand fastapi>=0.108.0 elastic-apm
@github-actions github-actions bot added agent-python community Issues opened by the community triage Issues awaiting triage labels Apr 25, 2024
@xrmx
Copy link
Member

xrmx commented Apr 26, 2024

Thanks for reporting

@Kludex
Copy link

Kludex commented Apr 26, 2024

The link on the title doesn't work.

@xrmx
Copy link
Member

xrmx commented Apr 26, 2024

@Kludex thanks!

@xrmx xrmx changed the title Starlette Application Stops When ElasticAPM Server is Unreachable #2571 Starlette Application Stops When ElasticAPM Server is Unreachable Apr 26, 2024
@xrmx
Copy link
Member

xrmx commented Apr 30, 2024

@Impro02 I'm trying to replicate it with the example you provided on the starlette discussion with the following packages:

anyio==4.3.0
certifi==2024.2.2
click==8.1.7
ecs-logging==2.1.0
elastic-apm==6.22.0
h11==0.14.0
idna==3.7
sniffio==1.3.1
starlette==0.37.2
urllib3==2.2.1
uvicorn==0.29.0
wrapt==1.14.1

With both python 3.10.12 and 3.11.9 the app is still responding to the /status endpoint after minutes.

@Impro02
Copy link
Author

Impro02 commented May 2, 2024

@xrmx After more investigation, the issue seems to be triggered by psutil lib.
From my tests, with the following environment, it will crash after psutil installation.

I use python 3.12.1

anyio==4.3.0
certifi==2024.2.2
click==8.1.7
colorama==0.4.6
ecs-logging==2.1.0
elastic-apm==6.22.0
h11==0.14.0
idna==3.7
psutil==5.9.8
setuptools==68.2.2
sniffio==1.3.1
starlette==0.37.2
urllib3==2.2.1
uvicorn==0.29.0
wheel==0.41.2
wrapt==1.14.1

@xrmx
Copy link
Member

xrmx commented May 2, 2024

Ok, so this looks more like metrics related.

Still cannot reproduce with python 3.12.3. Have you tried to update python version?

@Impro02
Copy link
Author

Impro02 commented May 2, 2024

Using python 3.12.3 seems to fix the issue.

@xrmx
Copy link
Member

xrmx commented May 2, 2024

Closing then.

@xrmx xrmx closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-python community Issues opened by the community triage Issues awaiting triage
Projects
None yet
Development

No branches or pull requests

3 participants