File: test_metrics.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (498 lines) | stat: -rw-r--r-- 24,339 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import platform
import shutil
import unittest
from unittest import mock

# pylint: disable=import-error
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.metrics.export import (
    AggregationTemporality,
    HistogramDataPoint,
    Metric,
    MetricExportResult,
    MetricsData,
    NumberDataPoint,
    ResourceMetrics,
    ScopeMetrics,
    Sum,
)

from azure.monitor.opentelemetry.exporter.export._base import ExportResult
from azure.monitor.opentelemetry.exporter.export.metrics._exporter import (
    AzureMonitorMetricExporter,
    _get_metric_export_result,
)
from azure.monitor.opentelemetry.exporter._generated.models import ContextTagKeys
from azure.monitor.opentelemetry.exporter._utils import (
    azure_monitor_context,
    ns_to_iso_str,
)


def throw(exc_type, *args, **kwargs):
    def func(*_args, **_kwargs):
        raise exc_type(*args, **kwargs)

    return func


# pylint: disable=import-error
# pylint: disable=protected-access
# pylint: disable=too-many-lines
class TestAzureMetricExporter(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        os.environ.clear()
        os.environ["APPINSIGHTS_INSTRUMENTATIONKEY"] = "1234abcd-5678-4efa-8abc-1234567890ab"
        os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
        cls._exporter = AzureMonitorMetricExporter()
        cls._metrics_data = MetricsData(
            resource_metrics=[
                ResourceMetrics(
                    resource=Resource.create(attributes={"asd": "test_resource"}),
                    scope_metrics=[
                        ScopeMetrics(
                            scope=InstrumentationScope("test_name"),
                            metrics=[
                                Metric(
                                    name="test name",
                                    description="test description",
                                    unit="ms",
                                    data=Sum(
                                        data_points=[
                                            NumberDataPoint(
                                                attributes={
                                                    "test": "attribute",
                                                },
                                                start_time_unix_nano=1646865018558419456,
                                                time_unix_nano=1646865018558419457,
                                                value=10,
                                            )
                                        ],
                                        aggregation_temporality=AggregationTemporality.CUMULATIVE,
                                        is_monotonic=False,
                                    ),
                                )
                            ],
                            schema_url="test url",
                        )
                    ],
                    schema_url="test url",
                )
            ]
        )

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls._exporter.storage._path, True)

    def test_constructor(self):
        """Test the constructor."""
        exporter = AzureMonitorMetricExporter(
            connection_string="InstrumentationKey=4321abcd-5678-4efa-8abc-1234567890ab",
        )
        self.assertEqual(
            exporter._instrumentation_key,
            "4321abcd-5678-4efa-8abc-1234567890ab",
        )

    def test_from_connection_string(self):
        exporter = AzureMonitorMetricExporter.from_connection_string(
            "InstrumentationKey=4321abcd-5678-4efa-8abc-1234567890ab"
        )
        self.assertTrue(isinstance(exporter, AzureMonitorMetricExporter))
        self.assertEqual(
            exporter._instrumentation_key,
            "4321abcd-5678-4efa-8abc-1234567890ab",
        )

    def test_export_none(self):
        exporter = self._exporter
        result = exporter.export(None)
        self.assertEqual(result, MetricExportResult.SUCCESS)

    def test_export_failure(self):
        exporter = self._exporter
        with mock.patch(
            "azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter._transmit"
        ) as transmit:  # noqa: E501
            transmit.return_value = ExportResult.FAILED_RETRYABLE
            storage_mock = mock.Mock()
            exporter.storage.put = storage_mock
            result = exporter.export(self._metrics_data)
        self.assertEqual(result, MetricExportResult.FAILURE)
        self.assertEqual(storage_mock.call_count, 1)

    def test_export_success(self):
        exporter = self._exporter
        with mock.patch(
            "azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter._transmit"
        ) as transmit:  # noqa: E501
            transmit.return_value = ExportResult.SUCCESS
            storage_mock = mock.Mock()
            exporter._transmit_from_storage = storage_mock
            result = exporter.export(self._metrics_data)
            self.assertEqual(result, MetricExportResult.SUCCESS)
            self.assertEqual(storage_mock.call_count, 1)

    @mock.patch("azure.monitor.opentelemetry.exporter.export.metrics._exporter._logger")
    def test_export_exception(self, logger_mock):
        exporter = self._exporter
        with mock.patch(
            "azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter._transmit",
            throw(Exception),
        ):  # noqa: E501
            result = exporter.export(self._metrics_data)
            self.assertEqual(result, MetricExportResult.FAILURE)
            self.assertEqual(logger_mock.exception.called, True)

    def test_export_not_retryable(self):
        exporter = self._exporter
        with mock.patch(
            "azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter._transmit"
        ) as transmit:  # noqa: E501
            transmit.return_value = ExportResult.FAILED_NOT_RETRYABLE
            result = exporter.export(self._metrics_data)
            self.assertEqual(result, MetricExportResult.FAILURE)

    def test_point_to_envelope_partA(self):
        exporter = self._exporter
        resource = Resource(
            {
                "service.name": "testServiceName",
                "service.namespace": "testServiceNamespace",
                "service.instance.id": "testServiceInstanceId",
            }
        )
        point = NumberDataPoint(
            attributes={
                "test": "attribute",
                "user_agent.synthetic.type": "bot",
            },
            start_time_unix_nano=1646865018558419456,
            time_unix_nano=1646865018558419457,
            value=10,
        )
        envelope = exporter._point_to_envelope(point, "test name", resource)

        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertIsNotNone(envelope.tags)
        self.assertEqual(
            envelope.tags.get(ContextTagKeys.AI_DEVICE_ID), azure_monitor_context[ContextTagKeys.AI_DEVICE_ID]
        )
        self.assertEqual(
            envelope.tags.get(ContextTagKeys.AI_DEVICE_LOCALE), azure_monitor_context[ContextTagKeys.AI_DEVICE_LOCALE]
        )
        self.assertEqual(
            envelope.tags.get(ContextTagKeys.AI_DEVICE_OS_VERSION),
            azure_monitor_context[ContextTagKeys.AI_DEVICE_OS_VERSION],
        )
        self.assertEqual(
            envelope.tags.get(ContextTagKeys.AI_DEVICE_TYPE), azure_monitor_context[ContextTagKeys.AI_DEVICE_TYPE]
        )
        self.assertEqual(
            envelope.tags.get(ContextTagKeys.AI_INTERNAL_SDK_VERSION),
            azure_monitor_context[ContextTagKeys.AI_INTERNAL_SDK_VERSION],
        )
        self.assertEqual(envelope.tags.get(ContextTagKeys.AI_OPERATION_SYNTHETIC_SOURCE), "True")
        self.assertEqual(envelope.tags.get(ContextTagKeys.AI_CLOUD_ROLE), "testServiceNamespace.testServiceName")
        self.assertEqual(envelope.tags.get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE), "testServiceInstanceId")
        self.assertEqual(envelope.tags.get(ContextTagKeys.AI_INTERNAL_NODE_NAME), "testServiceInstanceId")

    def test_point_to_envelope_partA_default(self):
        exporter = self._exporter
        resource = Resource({"service.name": "testServiceName"})
        point = NumberDataPoint(
            attributes={
                "test": "attribute",
            },
            start_time_unix_nano=1646865018558419456,
            time_unix_nano=1646865018558419457,
            value=10,
        )
        envelope = exporter._point_to_envelope(point, "test name", resource)
        self.assertEqual(envelope.tags.get(ContextTagKeys.AI_CLOUD_ROLE), "testServiceName")
        self.assertEqual(envelope.tags.get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE), platform.node())
        self.assertEqual(
            envelope.tags.get(ContextTagKeys.AI_INTERNAL_NODE_NAME),
            envelope.tags.get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE),
        )

    def test_point_to_envelope_number(self):
        exporter = self._exporter
        resource = Resource.create(attributes={"asd": "test_resource"})
        scope = InstrumentationScope("test_scope")
        point = NumberDataPoint(
            attributes={
                "test": "attribute",
            },
            start_time_unix_nano=1646865018558419456,
            time_unix_nano=1646865018558419457,
            value=10,
        )
        envelope = exporter._point_to_envelope(point, "test name", resource, scope)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(len(envelope.data.base_data.properties), 1)
        self.assertEqual(envelope.data.base_data.properties["test"], "attribute")
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "test name")
        self.assertEqual(envelope.data.base_data.metrics[0].namespace, None)
        self.assertEqual(envelope.data.base_data.metrics[0].value, 10)
        self.assertEqual(envelope.data.base_data.metrics[0].count, 1)

    def test_point_to_envelope_histogram(self):
        exporter = self._exporter
        resource = Resource.create(attributes={"asd": "test_resource"})
        point = HistogramDataPoint(
            attributes={
                "test": "attribute",
            },
            bucket_counts=[0, 3, 4],
            count=7,
            explicit_bounds=[0, 5, 10, 0],
            max=18,
            min=1,
            start_time_unix_nano=1646865018558419456,
            time_unix_nano=1646865018558419457,
            sum=31,
        )
        envelope = exporter._point_to_envelope(point, "test name", resource)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(len(envelope.data.base_data.properties), 1)
        self.assertEqual(envelope.data.base_data.properties["test"], "attribute")
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "test name")
        self.assertEqual(envelope.data.base_data.metrics[0].value, 31)
        self.assertEqual(envelope.data.base_data.metrics[0].count, 7)

    @mock.patch.dict(
        "os.environ",
        {
            "APPLICATIONINSIGHTS_METRIC_NAMESPACE_OPT_IN": "True",
        },
    )
    def test_point_to_envelope_metric_namespace(self):
        exporter = self._exporter
        resource = Resource.create(attributes={"asd": "test_resource"})
        scope = InstrumentationScope("test_scope")
        point = NumberDataPoint(
            attributes={
                "test": "attribute",
            },
            start_time_unix_nano=1646865018558419456,
            time_unix_nano=1646865018558419457,
            value=10,
        )
        envelope = exporter._point_to_envelope(point, "test name", resource, scope)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(len(envelope.data.base_data.properties), 1)
        self.assertEqual(envelope.data.base_data.properties["test"], "attribute")
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "test name")
        self.assertEqual(envelope.data.base_data.metrics[0].namespace, "test_scope")
        self.assertEqual(envelope.data.base_data.metrics[0].value, 10)
        self.assertEqual(envelope.data.base_data.metrics[0].count, 1)

    @mock.patch("azure.monitor.opentelemetry.exporter.export.trace._utils._get_target_and_path_for_http_dependency")
    def test_point_to_envelope_std_metric_client_duration(self, target_mock):
        exporter = self._exporter
        resource = Resource(
            {
                "service.name": "testServiceName",
                "service.namespace": "testServiceNamespace",
                "service.instance.id": "testServiceInstanceId",
            }
        )
        point = mock.Mock(spec=NumberDataPoint)
        point.attributes = {
            "http.status_code": 200,
            "custom_attr": "custom_key",
        }
        point.start_time_unix_nano = 1646865018558419456
        point.time_unix_nano = 1646865018558419457
        point.value = 15.0
        target_mock.return_value = ("test_service", "test_path")
        envelope = exporter._point_to_envelope(point, "http.client.duration", resource)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(envelope.data.base_data.properties["_MS.MetricId"], "dependencies/duration")
        self.assertEqual(envelope.data.base_data.properties["_MS.IsAutocollected"], "True")
        self.assertEqual(envelope.data.base_data.properties["Dependency.Type"], "http")
        self.assertEqual(envelope.data.base_data.properties["Dependency.Success"], "True")
        self.assertEqual(envelope.data.base_data.properties["dependency/target"], "test_service")
        self.assertEqual(envelope.data.base_data.properties["dependency/resultCode"], "200")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleInstance"], "testServiceInstanceId")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleName"], "testServiceNamespace.testServiceName")
        self.assertIsNone(envelope.data.base_data.properties.get("custom_attr"))
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "http.client.duration")
        self.assertEqual(envelope.data.base_data.metrics[0].value, 15.0)

        # Success/Failure
        point.attributes["http.status_code"] = 500
        envelope = exporter._point_to_envelope(point, "http.client.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["Dependency.Success"], "False")

        point.attributes["http.status_code"] = None
        envelope = exporter._point_to_envelope(point, "http.client.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["Dependency.Success"], "False")
        self.assertEqual(envelope.data.base_data.properties["dependency/resultCode"], "0")

        point.attributes["http.status_code"] = "None"
        envelope = exporter._point_to_envelope(point, "http.client.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["Dependency.Success"], "False")
        self.assertEqual(envelope.data.base_data.properties["dependency/resultCode"], "0")

        # stable
        point.attributes = {
            "http.response.status_code": 200,
            "custom_attr": "custom_key",
        }
        envelope = exporter._point_to_envelope(point, "http.client.request.duration", resource)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(envelope.data.base_data.properties["_MS.MetricId"], "dependencies/duration")
        self.assertEqual(envelope.data.base_data.properties["_MS.IsAutocollected"], "True")
        self.assertEqual(envelope.data.base_data.properties["Dependency.Type"], "http")
        self.assertEqual(envelope.data.base_data.properties["Dependency.Success"], "True")
        self.assertEqual(envelope.data.base_data.properties["dependency/target"], "test_service")
        self.assertEqual(envelope.data.base_data.properties["dependency/resultCode"], "200")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleInstance"], "testServiceInstanceId")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleName"], "testServiceNamespace.testServiceName")
        self.assertIsNone(envelope.data.base_data.properties.get("custom_attr"))
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "http.client.request.duration")
        self.assertEqual(envelope.data.base_data.metrics[0].value, 15.0)

    def test_point_to_envelope_std_metric_server_duration(self):
        exporter = self._exporter
        resource = Resource(
            {
                "service.name": "testServiceName",
                "service.namespace": "testServiceNamespace",
                "service.instance.id": "testServiceInstanceId",
            }
        )
        point = mock.Mock(spec=NumberDataPoint)
        point.attributes = {
            "http.status_code": 200,
            "custom_attr": "custom_key",
        }
        point.start_time_unix_nano = 1646865018558419456
        point.time_unix_nano = 1646865018558419457
        point.value = 15.0
        envelope = exporter._point_to_envelope(point, "http.server.duration", resource)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(envelope.data.base_data.properties["_MS.MetricId"], "requests/duration")
        self.assertEqual(envelope.data.base_data.properties["_MS.IsAutocollected"], "True")
        self.assertEqual(envelope.data.base_data.properties["Request.Success"], "True")
        self.assertEqual(envelope.data.base_data.properties["request/resultCode"], "200")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleInstance"], "testServiceInstanceId")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleName"], "testServiceNamespace.testServiceName")
        self.assertIsNone(envelope.data.base_data.properties.get("custom_attr"))
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "http.server.duration")
        self.assertEqual(envelope.data.base_data.metrics[0].value, 15.0)

        # Success/Failure
        point.attributes["http.status_code"] = 500
        envelope = exporter._point_to_envelope(point, "http.server.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["Request.Success"], "False")

        point.attributes["http.status_code"] = None
        envelope = exporter._point_to_envelope(point, "http.server.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["Request.Success"], "False")
        self.assertEqual(envelope.data.base_data.properties.get("request/resultCode"), "0")

        point.attributes["http.status_code"] = "None"
        envelope = exporter._point_to_envelope(point, "http.server.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["Request.Success"], "False")
        self.assertEqual(envelope.data.base_data.properties.get("request/resultCode"), "0")

        # Synthetic
        point.attributes["user_agent.synthetic.type"] = "bot"
        envelope = exporter._point_to_envelope(point, "http.server.duration", resource)
        self.assertEqual(envelope.data.base_data.properties["operation/synthetic"], "True")

        # Stable
        point.attributes = {
            "http.response.status_code": 200,
            "custom_attr": "custom_key",
        }
        envelope = exporter._point_to_envelope(point, "http.server.request.duration", resource)
        self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key)
        self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Metric")
        self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano))
        self.assertEqual(envelope.data.base_type, "MetricData")
        self.assertEqual(envelope.data.base_data.properties["_MS.MetricId"], "requests/duration")
        self.assertEqual(envelope.data.base_data.properties["_MS.IsAutocollected"], "True")
        self.assertEqual(envelope.data.base_data.properties["Request.Success"], "True")
        self.assertEqual(envelope.data.base_data.properties["request/resultCode"], "200")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleInstance"], "testServiceInstanceId")
        self.assertEqual(envelope.data.base_data.properties["cloud/roleName"], "testServiceNamespace.testServiceName")
        self.assertIsNone(envelope.data.base_data.properties.get("custom_attr"))
        self.assertEqual(len(envelope.data.base_data.metrics), 1)
        self.assertEqual(envelope.data.base_data.metrics[0].name, "http.server.request.duration")
        self.assertEqual(envelope.data.base_data.metrics[0].value, 15.0)

    def test_point_to_envelope_std_metric_unsupported(self):
        exporter = self._exporter
        resource = Resource(
            {
                "service.name": "testServiceName",
                "service.namespace": "testServiceNamespace",
                "service.instance.id": "testServiceInstanceId",
            }
        )
        point = NumberDataPoint(
            attributes={
                "http.status_code": 200,
                "peer.service": "test_service",
                "custom_attr": "custom_key",
            },
            start_time_unix_nano=1646865018558419456,
            time_unix_nano=1646865018558419457,
            value=15.0,
        )
        envelope = exporter._point_to_envelope(point, "http.server.request.size", resource)
        self.assertIsNone(envelope)


class TestAzureMetricExporterUtils(unittest.TestCase):
    def test_get_metric_export_result(self):
        self.assertEqual(
            _get_metric_export_result(ExportResult.SUCCESS),
            MetricExportResult.SUCCESS,
        )
        self.assertEqual(
            _get_metric_export_result(ExportResult.FAILED_NOT_RETRYABLE),
            MetricExportResult.FAILURE,
        )
        self.assertEqual(
            _get_metric_export_result(ExportResult.FAILED_RETRYABLE),
            MetricExportResult.FAILURE,
        )
        self.assertEqual(
            _get_metric_export_result(None),
            MetricExportResult.FAILURE,
        )