|
68 | 68 | from newrelic.core.custom_event import create_custom_event
|
69 | 69 | from newrelic.core.log_event_node import LogEventNode
|
70 | 70 | from newrelic.core.stack_trace import exception_stack
|
71 |
| -from newrelic.core.stats_engine import CustomMetrics, SampledDataSet |
| 71 | +from newrelic.core.stats_engine import CustomMetrics, DimensionalMetrics, SampledDataSet |
72 | 72 | from newrelic.core.thread_utilization import utilization_tracker
|
73 | 73 | from newrelic.core.trace_cache import (
|
74 | 74 | TraceCacheActiveTraceError,
|
@@ -309,6 +309,7 @@ def __init__(self, application, enabled=None, source=None):
|
309 | 309 | self.synthetics_header = None
|
310 | 310 |
|
311 | 311 | self._custom_metrics = CustomMetrics()
|
| 312 | + self._dimensional_metrics = DimensionalMetrics() |
312 | 313 |
|
313 | 314 | global_settings = application.global_settings
|
314 | 315 |
|
@@ -591,6 +592,7 @@ def __exit__(self, exc, value, tb):
|
591 | 592 | apdex_t=self.apdex,
|
592 | 593 | suppress_apdex=self.suppress_apdex,
|
593 | 594 | custom_metrics=self._custom_metrics,
|
| 595 | + dimensional_metrics=self._dimensional_metrics, |
594 | 596 | guid=self.guid,
|
595 | 597 | cpu_time=self._cpu_user_time_value,
|
596 | 598 | suppress_transaction_trace=self.suppress_transaction_trace,
|
@@ -1597,6 +1599,16 @@ def record_custom_metrics(self, metrics):
|
1597 | 1599 | for name, value in metrics:
|
1598 | 1600 | self._custom_metrics.record_custom_metric(name, value)
|
1599 | 1601 |
|
| 1602 | + def record_dimensional_metric(self, name, value, tags=None): |
| 1603 | + self._dimensional_metrics.record_dimensional_metric(name, value, tags) |
| 1604 | + |
| 1605 | + def record_dimensional_metrics(self, metrics): |
| 1606 | + for metric in metrics: |
| 1607 | + name, value = metric[:2] |
| 1608 | + tags = metric[2] if len(metric) >= 3 else None |
| 1609 | + |
| 1610 | + self._dimensional_metrics.record_dimensional_metric(name, value, tags) |
| 1611 | + |
1600 | 1612 | def record_custom_event(self, event_type, params):
|
1601 | 1613 | settings = self._settings
|
1602 | 1614 |
|
@@ -1908,6 +1920,44 @@ def record_custom_metrics(metrics, application=None):
|
1908 | 1920 | application.record_custom_metrics(metrics)
|
1909 | 1921 |
|
1910 | 1922 |
|
| 1923 | +def record_dimensional_metric(name, value, tags=None, application=None): |
| 1924 | + if application is None: |
| 1925 | + transaction = current_transaction() |
| 1926 | + if transaction: |
| 1927 | + transaction.record_dimensional_metric(name, value, tags) |
| 1928 | + else: |
| 1929 | + _logger.debug( |
| 1930 | + "record_dimensional_metric has been called but no " |
| 1931 | + "transaction was running. As a result, the following metric " |
| 1932 | + "has not been recorded. Name: %r Value: %r Tags: %r. To correct this " |
| 1933 | + "problem, supply an application object as a parameter to this " |
| 1934 | + "record_dimensional_metrics call.", |
| 1935 | + name, |
| 1936 | + value, |
| 1937 | + tags, |
| 1938 | + ) |
| 1939 | + elif application.enabled: |
| 1940 | + application.record_dimensional_metric(name, value, tags) |
| 1941 | + |
| 1942 | + |
| 1943 | +def record_dimensional_metrics(metrics, application=None): |
| 1944 | + if application is None: |
| 1945 | + transaction = current_transaction() |
| 1946 | + if transaction: |
| 1947 | + transaction.record_dimensional_metrics(metrics) |
| 1948 | + else: |
| 1949 | + _logger.debug( |
| 1950 | + "record_dimensional_metrics has been called but no " |
| 1951 | + "transaction was running. As a result, the following metrics " |
| 1952 | + "have not been recorded: %r. To correct this problem, " |
| 1953 | + "supply an application object as a parameter to this " |
| 1954 | + "record_dimensional_metric call.", |
| 1955 | + list(metrics), |
| 1956 | + ) |
| 1957 | + elif application.enabled: |
| 1958 | + application.record_dimensional_metrics(metrics) |
| 1959 | + |
| 1960 | + |
1911 | 1961 | def record_custom_event(event_type, params, application=None):
|
1912 | 1962 | """Record a custom event.
|
1913 | 1963 |
|
|
0 commit comments