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

Call scopeInfoMetrics only once even if it returns an error #4499

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Removed the deprecated internal packages in `go.opentelemetry.io/otel/exporters/otlp` and its sub-packages. (#4469)
- Dropped guaranteed support for versions of Go less than 1.20. (#4481)

### Fixed

- In `go.opentelemetry.op/otel/exporters/prometheus`, don't try to create the prometheus metric on every `Collect` if we know the scope is invalid. (#4499)

## [1.17.0/0.40.0/0.0.5] 2023-08-28

### Added
Expand Down
10 changes: 9 additions & 1 deletion exporters/prometheus/exporter.go
Expand Up @@ -87,6 +87,7 @@
disableTargetInfo bool
targetInfo prometheus.Metric
scopeInfos map[instrumentation.Scope]prometheus.Metric
scopeInfoErrs map[instrumentation.Scope]error
metricFamilies map[string]*dto.MetricFamily
}

Expand All @@ -110,6 +111,7 @@
withoutCounterSuffixes: cfg.withoutCounterSuffixes,
disableScopeInfo: cfg.disableScopeInfo,
scopeInfos: make(map[instrumentation.Scope]prometheus.Metric),
scopeInfoErrs: make(map[instrumentation.Scope]error),
metricFamilies: make(map[string]*dto.MetricFamily),
namespace: cfg.namespace,
}
Expand Down Expand Up @@ -469,8 +471,14 @@
return scopeInfo, nil
}

scopeInfo, err := createScopeInfoMetric(scope)
err, ok := c.scopeInfoErrs[scope]
if ok {
return nil, fmt.Errorf("cannot retrieve scope info metric: %w", err)
pellared marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 477 in exporters/prometheus/exporter.go

View check run for this annotation

Codecov / codecov/patch

exporters/prometheus/exporter.go#L476-L477

Added lines #L476 - L477 were not covered by tests

scopeInfo, err = createScopeInfoMetric(scope)
if err != nil {
c.scopeInfoErrs[scope] = err
return nil, fmt.Errorf("cannot create scope info metric: %w", err)
}

Expand Down