Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter-otlp-proto-common] Include metric info in encoding exception #4154

Merged
merged 7 commits into from
Sep 4, 2024

Conversation

pmcollins
Copy link
Member

Also remove redundant str(exception) from the exception message

Description

Fixes #4093

As the linked issue mentions, if a failure occurs during converting a metric to proto, the exception message doesn't contain information about the metric that couldn't be converted. This change adds that information to the exception.

Before this change:

Exception while exporting metrics Value out of range: 17131960503145336928
Traceback (most recent call last):
  File "/Users/user/github/open-telemetry/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py", line 541, in _receive_metrics
    self._exporter.export(
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py", line 160, in export
    return self._export(data=metrics_data)
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py", line 263, in _export
    request=self._translate_data(data),
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py", line 150, in _translate_data
    return encode_metrics(data)
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py", line 260, in encode_metrics
    pt.as_int = data_point.value
ValueError: Value out of range: 17131960503145336928

After this change:

Exception while exporting metrics
Traceback (most recent call last):
  File "/Users/user/github/open-telemetry/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py", line 541, in _receive_metrics
    self._exporter.export(
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py", line 165, in export
    return self._export(data=metrics_data)
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py", line 301, in _export
    request=self._translate_data(data),
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py", line 155, in _translate_data
    return encode_metrics(data)
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py", line 195, in encode_metrics
    _encode_resource_metrics(resource_metrics, resource_metrics_dict)
  File "/Users/user/github/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py", line 246, in _encode_resource_metrics
    raise EncodingException(ex, metric) from None
opentelemetry.exporter.otlp.proto.common._internal.metrics_encoder.EncodingException: Metric(name='process.runtime.cpython.context_switches', description='Runtime context switches', unit='switches', data=Sum(data_points=[NumberDataPoint(attributes={'type': 'involuntary'}, start_time_unix_nano=1724856334261458000, time_unix_nano=1724856334261510000, value=0), NumberDataPoint(attributes={'type': 'voluntary'}, start_time_unix_nano=1724856334261468000, time_unix_nano=1724856334261510000, value=15841456515849392318)], aggregation_temporality=<AggregationTemporality.CUMULATIVE: 2>, is_monotonic=True))
Value out of range: 15841456515849392318

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Manually end-to-end tested and unit test coverage added.

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

…curs during encoding

Also remove redundant str(exception) from the exception message
@pmcollins pmcollins marked this pull request as ready for review August 28, 2024 15:51
@pmcollins pmcollins requested a review from a team as a code owner August 28, 2024 15:51
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related but doesn't have to be part of this PR. Would this type of encoding exception be useful for encoding spans and logs as well?

CHANGELOG.md Outdated Show resolved Hide resolved
@lzchen lzchen merged commit 586bb06 into open-telemetry:main Sep 4, 2024
376 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics SDK produces ValueError sometimes
3 participants