-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3467 from GSA-TTS/main
- Loading branch information
Showing
3 changed files
with
29 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
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,24 @@ | ||
import functools | ||
import logging | ||
import time | ||
|
||
import newrelic.agent | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def newrelic_timing_metric(metric_name): | ||
def inner(func): | ||
@functools.wraps(func) | ||
def wrapper_timer(*args, **kwargs): | ||
start_time = time.perf_counter() | ||
value = func(*args, **kwargs) | ||
end_time = time.perf_counter() | ||
run_time = end_time - start_time | ||
logger.info(f"{metric_name} executed in {run_time:.4f} secs") | ||
newrelic.agent.record_custom_metric(f"Custom/{metric_name}", run_time) | ||
return value | ||
|
||
return wrapper_timer | ||
|
||
return inner |