Open
Conversation
This commit introduces OpenTelemetry metrics collection for the HTTP client. The following metrics are now collected: - http.client.request.count (Counter): Total number of HTTP requests. - http.client.request.duration (Histogram): Duration of HTTP requests. - http.client.request.errors (Counter): Number of HTTP requests that resulted in an error. Metrics can be enabled or disabled using the `WithMetricsEnabled` option when creating a new `HTTPClient`. An example demonstrating how to use the metrics feature has been added in `example/httpMetrics/main.go`. Unit tests have been added to verify the correctness of the metrics collection.
This commit refactors the internal implementation of OpenTelemetry metrics in the HTTP client to be more scalable and maintainable. Key changes: - Introduced a `MetricConfig` struct and a default list of metric configurations. - The `HTTPClient` now stores initialized metric instruments in a map (`instruments`) keyed by metric name, instead of individual struct fields. - Metric initialization in `NewHTTPClient` is now driven by iterating through the `defaultMetricConfigs`. - Metric recording in the `Do` method now retrieves instruments from the `instruments` map. This change does not alter your user-facing API for enabling metrics or the names and attributes of the metrics themselves. Existing tests and documentation remain valid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.