Skip to content

Commit acc1c7c

Browse files
WhichOneof instead of HasField
1 parent aa6c822 commit acc1c7c

File tree

1 file changed

+12
-10
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter

1 file changed

+12
-10
lines changed

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ def _split_metrics_data(
348348
# with different accessors for data points, etc
349349
# We maintain these structures throughout batch calculation
350350
current_data_points = []
351-
if metric.HasField("sum"):
351+
field_name = metric.WhichOneof("data")
352+
if field_name == "sum":
352353
split_metrics.append(
353354
{
354355
"name": metric.name,
@@ -362,7 +363,7 @@ def _split_metrics_data(
362363
}
363364
)
364365
current_data_points = metric.sum.data_points
365-
elif metric.HasField("histogram"):
366+
elif field_name == "histogram":
366367
split_metrics.append(
367368
{
368369
"name": metric.name,
@@ -375,7 +376,7 @@ def _split_metrics_data(
375376
}
376377
)
377378
current_data_points = metric.histogram.data_points
378-
elif metric.HasField("exponential_histogram"):
379+
elif field_name == "exponential_histogram":
379380
split_metrics.append(
380381
{
381382
"name": metric.name,
@@ -390,7 +391,7 @@ def _split_metrics_data(
390391
current_data_points = (
391392
metric.exponential_histogram.data_points
392393
)
393-
elif metric.HasField("gauge"):
394+
elif field_name == "gauge":
394395
split_metrics.append(
395396
{
396397
"name": metric.name,
@@ -402,7 +403,7 @@ def _split_metrics_data(
402403
}
403404
)
404405
current_data_points = metric.gauge.data_points
405-
elif metric.HasField("summary"):
406+
elif field_name == "summary":
406407
split_metrics.append(
407408
{
408409
"name": metric.name,
@@ -436,7 +437,8 @@ def _split_metrics_data(
436437
batch_size = 0
437438
split_data_points = []
438439

439-
if metric.HasField("sum"):
440+
field_name = metric.WhichOneof("data")
441+
if field_name == "sum":
440442
split_metrics = [
441443
{
442444
"name": metric.name,
@@ -449,7 +451,7 @@ def _split_metrics_data(
449451
},
450452
}
451453
]
452-
elif metric.HasField("histogram"):
454+
elif field_name == "histogram":
453455
split_metrics = [
454456
{
455457
"name": metric.name,
@@ -461,7 +463,7 @@ def _split_metrics_data(
461463
},
462464
}
463465
]
464-
elif metric.HasField("exponential_histogram"):
466+
elif field_name == "exponential_histogram":
465467
split_metrics = [
466468
{
467469
"name": metric.name,
@@ -473,7 +475,7 @@ def _split_metrics_data(
473475
},
474476
}
475477
]
476-
elif metric.HasField("gauge"):
478+
elif field_name == "gauge":
477479
split_metrics = [
478480
{
479481
"name": metric.name,
@@ -484,7 +486,7 @@ def _split_metrics_data(
484486
},
485487
}
486488
]
487-
elif metric.HasField("summary"):
489+
elif field_name == "summary":
488490
split_metrics = [
489491
{
490492
"name": metric.name,

0 commit comments

Comments
 (0)