Skip to content
Draft
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
Empty file removed app/aws/xray/__init__.py
Empty file.
109 changes: 0 additions & 109 deletions app/aws/xray/context.py

This file was deleted.

79 changes: 0 additions & 79 deletions app/aws/xray_celery_handlers.py

This file was deleted.

14 changes: 0 additions & 14 deletions app/celery/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

from flask import current_app

from app.aws.xray_celery_handlers import (
xray_after_task_publish,
xray_before_task_publish,
xray_task_failure,
xray_task_postrun,
xray_task_prerun,
)
from celery import Celery, Task, signals
from celery.signals import worker_process_shutdown

Expand Down Expand Up @@ -49,13 +42,6 @@ def init_app(self, app):
task_cls=make_task(app),
)

# Register the xray handlers
signals.after_task_publish.connect(xray_after_task_publish)
signals.before_task_publish.connect(xray_before_task_publish)
signals.task_failure.connect(xray_task_failure)
signals.task_postrun.connect(xray_task_postrun)
signals.task_prerun.connect(xray_task_prerun)

# See https://docs.celeryproject.org/en/stable/userguide/configuration.html
self.conf.update(
{
Expand Down
3 changes: 0 additions & 3 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ class Config(object):
DEBUG = False
NOTIFY_LOG_PATH = os.getenv("NOTIFY_LOG_PATH")

# Xray SDK
AWS_XRAY_ENABLED = env.bool("AWS_XRAY_SDK_ENABLED", False) # X-Ray switch leveraged by the SDK

# Cronitor
CRONITOR_ENABLED = False
CRONITOR_KEYS = json.loads(os.getenv("CRONITOR_KEYS", "{}"))
Expand Down
10 changes: 0 additions & 10 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@

# import newrelic.agent # See https://bit.ly/2xBVKBH
from apig_wsgi import make_lambda_handler
from aws_xray_sdk.core import patch_all, xray_recorder
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware
from dotenv import load_dotenv
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix

from app import create_app
from app.aws.xray.context import NotifyContext

# Patch all supported libraries for X-Ray
# Used to trace requests and responses through the stack
patch_all()

load_dotenv()

Expand All @@ -25,9 +18,6 @@

app = create_app(application)

xray_recorder.configure(service="Notify-API", context=NotifyContext())
XRayMiddleware(app, xray_recorder)

apig_wsgi_handler = make_lambda_handler(
app, binary_support=True, non_binary_content_type_prefixes=["application/yaml", "application/json"]
)
Expand Down
30 changes: 28 additions & 2 deletions gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,35 @@
environment = os.environ.get("NOTIFY_ENVIRONMENT")
newrelic.agent.initialize(environment=environment) # noqa: E402

workers = 4

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'workers' is unnecessary as it is
redefined
before this value is used.
This assignment to 'workers' is unnecessary as it is
redefined
before this value is used.
worker_class = "gevent"
worker_connections = 256

# Detect OpenTelemetry and use sync workers when present to avoid conflicts
# OpenTelemetry auto-instrumentation + gevent monkey patching can cause SSL recursion issues
def _detect_opentelemetry():
"""Check if OpenTelemetry is present and configured for auto-instrumentation."""
try:
# Check for OTEL environment variables that indicate auto-instrumentation
otel_vars = [
"OTEL_PYTHON_CONFIGURATOR",
"OTEL_PYTHON_DISTRO",
"OTEL_SERVICE_NAME",
"OTEL_RESOURCE_ATTRIBUTES"
]
return any(os.environ.get(var) for var in otel_vars)
except Exception:
return False

# Use sync workers when OpenTelemetry is detected, gevent otherwise
if _detect_opentelemetry():
worker_class = "sync"
# Increase worker count for sync workers as they handle one request at a time
workers = int(os.environ.get("GUNICORN_WORKERS", "8"))
print("OpenTelemetry detected - using sync workers for compatibility")
else:
worker_class = "gevent"
worker_connections = 256

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'worker_connections' is not used.

Copilot Autofix

AI 3 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

workers = int(os.environ.get("GUNICORN_WORKERS", "4"))
print("Using gevent workers")
bind = "0.0.0.0:{}".format(os.getenv("PORT"))
accesslog = "-"
# Guincorn sets the server type on our app. We don't want to show it in the header in the response.
Expand Down
6 changes: 0 additions & 6 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,4 @@ ignore_missing_imports = True
ignore_missing_imports = True

[mypy-simple_salesforce.*]
ignore_missing_imports = True

[mypy-aws_xray_sdk.*]
ignore_missing_imports = True

[mypy-celery_aws_xray_sdk_extension.*]
ignore_missing_imports = True
Loading
Loading