-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(hook_gunicorn): added gunicorn support to otel
Signed-off-by: Cagri Yonca <[email protected]>
- Loading branch information
1 parent
b1eb5b9
commit 2500054
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# (c) Copyright IBM Corp. 2021 | ||
# (c) Copyright Instana Inc. 2019 | ||
|
||
try: | ||
from instana.log import logger | ||
from instana.singletons import agent | ||
|
||
import gunicorn | ||
from gunicorn.arbiter import Arbiter | ||
from gunicorn.config import Config | ||
from gunicorn.workers.sync import SyncWorker | ||
|
||
def pre_fork(config: Config, server: Arbiter, worker: SyncWorker) -> None: | ||
"""This is our gunicorn hook to detect and act when worker processes are forked off.""" | ||
logger.debug("Handling gunicorn fork...") | ||
agent.handle_fork() | ||
|
||
Config.pre_fork = pre_fork | ||
|
||
logger.debug("Gunicorn pre-fork hook applied") | ||
except ImportError: | ||
logger.debug( | ||
"gunicorn hooks: decorators not available: likely not running under gunicorn" | ||
) | ||
pass |