-
Notifications
You must be signed in to change notification settings - Fork 11
Signoz otel collector working #2418
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,23 @@ | |
| import time | ||
| import traceback | ||
|
|
||
| # Check if OpenTelemetry auto-instrumentation is active | ||
| # If so, use sync workers to avoid monkey patching conflicts | ||
| otel_env_vars = [ | ||
| "OTEL_SERVICE_NAME", | ||
| "OTEL_RESOURCE_ATTRIBUTES", | ||
| "OTEL_EXPORTER_OTLP_ENDPOINT", | ||
| "OTEL_TRACES_EXPORTER", | ||
| "OTEL_METRICS_EXPORTER", | ||
| ] | ||
|
|
||
| otel_detected = any(os.environ.get(var) for var in otel_env_vars) | ||
|
|
||
| # Also check if opentelemetry is in the Python path (auto-instrumentation) | ||
| pythonpath = os.environ.get("PYTHONPATH", "") | ||
| if "otel-auto-instrumentation" in pythonpath or "opentelemetry" in pythonpath: | ||
| otel_detected = True | ||
|
|
||
| import gunicorn # type: ignore | ||
| import newrelic.agent # See https://bit.ly/2xBVKBH | ||
|
|
||
|
|
@@ -12,8 +29,15 @@ | |
| # Guincorn sets the server type on our app. We don't want to show it in the header in the response. | ||
| gunicorn.SERVER = "Undisclosed" | ||
|
|
||
| workers = 5 | ||
| worker_class = "gevent" | ||
| # Use sync workers when OpenTelemetry is detected to avoid SSL monkey patching conflicts | ||
| worker_class = "sync" if otel_detected else "gevent" | ||
|
|
||
| # Adjust worker count based on worker class | ||
| # Sync workers need more processes to handle the same load as gevent | ||
| if otel_detected: | ||
| workers = 8 # More workers for sync mode | ||
| else: | ||
| workers = 5 # Standard worker count for gevent | ||
| bind = "0.0.0.0:{}".format(os.getenv("PORT")) | ||
| accesslog = "-" | ||
|
|
||
|
|
@@ -48,12 +72,36 @@ | |
| graceful_timeout = 85 | ||
| timeout = 90 | ||
|
|
||
| # Additional configuration for sync workers when using OpenTelemetry | ||
| if otel_detected: | ||
| # Sync workers might need slightly longer timeout for instrumented requests | ||
| timeout = 95 | ||
| graceful_timeout = 90 | ||
Check noticeCode scanning / CodeQL Unused global variable Note
The global variable 'graceful_timeout' is not used.
Copilot AutofixAI 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. |
||
|
|
||
| # Start timer for total running time | ||
| start_time = time.time() | ||
|
|
||
|
|
||
| def on_starting(server): | ||
| server.log.info("Starting Notifications Admin") | ||
| server.log.info(f"Using worker class: {worker_class}") | ||
|
|
||
| # Log telemetry configuration using the same detection logic | ||
| server.log.info(f"OpenTelemetry detected: {otel_detected}") | ||
|
|
||
| if otel_detected: | ||
| server.log.info("✅ OpenTelemetry auto-instrumentation active - using sync workers to avoid SSL conflicts") | ||
| # Log which env vars triggered detection | ||
| active_vars = [var for var in otel_env_vars if os.environ.get(var)] | ||
| if active_vars: | ||
| server.log.info(f"OTEL environment variables: {active_vars}") | ||
| pythonpath = os.environ.get("PYTHONPATH", "") | ||
| if "otel-auto-instrumentation" in pythonpath: | ||
| server.log.info("OTEL auto-instrumentation detected in PYTHONPATH") | ||
| else: | ||
| server.log.info("No OpenTelemetry detected - using gevent workers for better performance") | ||
|
|
||
| server.log.info("AWS X-Ray removed - OpenTelemetry handles all tracing") | ||
|
|
||
|
|
||
| def worker_abort(worker): | ||
|
|
@@ -70,3 +118,17 @@ | |
|
|
||
| def worker_int(worker): | ||
| worker.log.info("worker: received SIGINT {}".format(worker.pid)) | ||
|
|
||
|
|
||
| def post_worker_init(worker): | ||
| """Initialize worker process - useful for OpenTelemetry sync workers""" | ||
| if otel_detected: | ||
| worker.log.info(f"Initializing sync worker {worker.pid} for OpenTelemetry instrumentation") | ||
| # Ensure clean SSL context in sync workers | ||
| import ssl | ||
|
|
||
| # Reset any cached SSL contexts to prevent recursion issues | ||
| if hasattr(ssl, "_create_default_https_context"): | ||
| ssl._create_default_https_context = ssl.create_default_context | ||
| else: | ||
| worker.log.info(f"Initializing gevent worker {worker.pid}") | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Check notice
Code scanning / CodeQL
Unused global variable Note
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.