|
64 | 64 | from newrelic.core.custom_event import create_custom_event
|
65 | 65 | from newrelic.core.log_event_node import LogEventNode
|
66 | 66 | from newrelic.core.stack_trace import exception_stack
|
67 |
| -from newrelic.core.stats_engine import CustomMetrics, SampledDataSet |
| 67 | +from newrelic.core.stats_engine import CustomMetrics, DimensionalMetrics, SampledDataSet |
68 | 68 | from newrelic.core.thread_utilization import utilization_tracker
|
69 | 69 | from newrelic.core.trace_cache import (
|
70 | 70 | TraceCacheActiveTraceError,
|
@@ -307,6 +307,7 @@ def __init__(self, application, enabled=None, source=None):
|
307 | 307 | self.synthetics_header = None
|
308 | 308 |
|
309 | 309 | self._custom_metrics = CustomMetrics()
|
| 310 | + self._dimensional_metrics = DimensionalMetrics() |
310 | 311 |
|
311 | 312 | global_settings = application.global_settings
|
312 | 313 |
|
@@ -588,6 +589,7 @@ def __exit__(self, exc, value, tb):
|
588 | 589 | apdex_t=self.apdex,
|
589 | 590 | suppress_apdex=self.suppress_apdex,
|
590 | 591 | custom_metrics=self._custom_metrics,
|
| 592 | + dimensional_metrics=self._dimensional_metrics, |
591 | 593 | guid=self.guid,
|
592 | 594 | cpu_time=self._cpu_user_time_value,
|
593 | 595 | suppress_transaction_trace=self.suppress_transaction_trace,
|
@@ -1600,6 +1602,16 @@ def record_custom_metrics(self, metrics):
|
1600 | 1602 | for name, value in metrics:
|
1601 | 1603 | self._custom_metrics.record_custom_metric(name, value)
|
1602 | 1604 |
|
| 1605 | + def record_dimensional_metric(self, name, value, tags=None): |
| 1606 | + self._dimensional_metrics.record_dimensional_metric(name, value, tags) |
| 1607 | + |
| 1608 | + def record_dimensional_metrics(self, metrics): |
| 1609 | + for metric in metrics: |
| 1610 | + name, value = metric[:2] |
| 1611 | + tags = metric[2] if len(metric) >= 3 else None |
| 1612 | + |
| 1613 | + self._dimensional_metrics.record_dimensional_metric(name, value, tags) |
| 1614 | + |
1603 | 1615 | def record_custom_event(self, event_type, params):
|
1604 | 1616 | settings = self._settings
|
1605 | 1617 |
|
@@ -1898,6 +1910,44 @@ def record_custom_metrics(metrics, application=None):
|
1898 | 1910 | application.record_custom_metrics(metrics)
|
1899 | 1911 |
|
1900 | 1912 |
|
| 1913 | +def record_dimensional_metric(name, value, tags=None, application=None): |
| 1914 | + if application is None: |
| 1915 | + transaction = current_transaction() |
| 1916 | + if transaction: |
| 1917 | + transaction.record_dimensional_metric(name, value, tags) |
| 1918 | + else: |
| 1919 | + _logger.debug( |
| 1920 | + "record_dimensional_metric has been called but no " |
| 1921 | + "transaction was running. As a result, the following metric " |
| 1922 | + "has not been recorded. Name: %r Value: %r Tags: %r. To correct this " |
| 1923 | + "problem, supply an application object as a parameter to this " |
| 1924 | + "record_dimensional_metrics call.", |
| 1925 | + name, |
| 1926 | + value, |
| 1927 | + tags, |
| 1928 | + ) |
| 1929 | + elif application.enabled: |
| 1930 | + application.record_dimensional_metric(name, value, tags) |
| 1931 | + |
| 1932 | + |
| 1933 | +def record_dimensional_metrics(metrics, application=None): |
| 1934 | + if application is None: |
| 1935 | + transaction = current_transaction() |
| 1936 | + if transaction: |
| 1937 | + transaction.record_dimensional_metrics(metrics) |
| 1938 | + else: |
| 1939 | + _logger.debug( |
| 1940 | + "record_dimensional_metrics has been called but no " |
| 1941 | + "transaction was running. As a result, the following metrics " |
| 1942 | + "have not been recorded: %r. To correct this problem, " |
| 1943 | + "supply an application object as a parameter to this " |
| 1944 | + "record_dimensional_metric call.", |
| 1945 | + list(metrics), |
| 1946 | + ) |
| 1947 | + elif application.enabled: |
| 1948 | + application.record_dimensional_metrics(metrics) |
| 1949 | + |
| 1950 | + |
1901 | 1951 | def record_custom_event(event_type, params, application=None):
|
1902 | 1952 | """Record a custom event.
|
1903 | 1953 |
|
|
0 commit comments