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

Improve error handling #492

Merged
merged 1 commit into from Sep 30, 2022

Conversation

dashpole
Copy link
Contributor

This has a number of improvements:

  • If we fail to write metric descriptors, we now still try to send the timeseries.
  • If we fail to write one metric descriptor, we now still try to send other metric descriptors
  • If we fail to convert one metric point in a metric, we now still send the other valid points
  • [Breaking] If we encounter errors during conversion, we no longer pass the error to a user-provided error handler. Instead, we return the error to the periodic reader. The reader will handle the error with otel.Handle, and users can set the otel error handler the same way they used to configure our error handler.
  • Use multierr.Append or multierr.Combine instead of []error to simplify code. This is slightly more efficient, and handles nil errors by not appending, so we aren't required to check for nil anymore.

@@ -148,14 +147,10 @@ func newMetricExporter(o *options) (*metricExporter, error) {

// Export exports OpenTelemetry Metrics to Google Cloud Monitoring.
func (me *metricExporter) Export(ctx context.Context, rm metricdata.ResourceMetrics) error {
if err := me.exportMetricDescriptor(ctx, rm); err != nil {
return err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this return would've prevented sending TS if we failed to write descriptors.

for kmd, md := range mds {
err := me.createMetricDescriptorIfNeeded(ctx, md)
if err != nil {
return err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this return would've prevented other descriptors from being written


for _, scope := range rm.ScopeMetrics {
for _, metrics := range scope.Metrics {
ts, err := me.recordToTspb(metrics, mr, scope.Scope)
if err != nil {
errs = append(errs, err)
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this else prevented appending timeseries if recordToTspb returned a partial error (an error, and some timeseries)


if aggError != nil {
if me.o.onError != nil {
me.o.onError(aggError)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is removed in-favor of returning the error.

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.

None yet

2 participants