mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 05:25:42 +00:00
Tracing improvements (#6353)
* Prevent tracing in worker thread * Tweak logic * Further improvements * Adds invoke command to launch gunicorn server * Update docstring * Add explicit check for migrations or data import * Update tracing.py Allow tracing in worker thread
This commit is contained in:
@ -19,6 +19,25 @@ def isRunningMigrations():
|
||||
return any((x in sys.argv for x in ['migrate', 'makemigrations', 'showmigrations']))
|
||||
|
||||
|
||||
def isInWorkerThread():
|
||||
"""Returns True if the current thread is a background worker thread."""
|
||||
return 'qcluster' in sys.argv
|
||||
|
||||
|
||||
def isInServerThread():
|
||||
"""Returns True if the current thread is a server thread."""
|
||||
if isInWorkerThread():
|
||||
return False
|
||||
|
||||
if 'runserver' in sys.argv:
|
||||
return True
|
||||
|
||||
if 'gunicorn' in sys.argv[0]:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def isInMainThread():
|
||||
"""Django runserver starts two processes, one for the actual dev server and the other to reload the application.
|
||||
|
||||
@ -28,7 +47,7 @@ def isInMainThread():
|
||||
if 'runserver' in sys.argv and '--noreload' not in sys.argv:
|
||||
return os.environ.get('RUN_MAIN', None) == 'true'
|
||||
|
||||
return True
|
||||
return not isInWorkerThread()
|
||||
|
||||
|
||||
def canAppAccessDatabase(
|
||||
|
@ -19,6 +19,7 @@ from opentelemetry.sdk.metrics.export import (
|
||||
from opentelemetry.sdk.trace import TracerProvider
|
||||
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
|
||||
|
||||
import InvenTree.ready
|
||||
from InvenTree.version import inventreeVersion
|
||||
|
||||
# Logger configuration
|
||||
@ -42,6 +43,9 @@ def setup_tracing(
|
||||
resources_input: The resources to send with the traces.
|
||||
console: Whether to output the traces to the console.
|
||||
"""
|
||||
if InvenTree.ready.isImportingData() or InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
if resources_input is None:
|
||||
resources_input = {}
|
||||
if auth is None:
|
||||
|
Reference in New Issue
Block a user