[Observability] feat: add metrics of http response #18499
Merged
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.
Summary
This pull request enhances the OpenTelemetry instrumentation in the
ext_otel.py
file by introducing a new HTTP response counter to track the total number of HTTP responses by status code. It also updates the imports to include the requiredget_meter
function for metrics.Enhancements to OpenTelemetry instrumentation:
Added HTTP response counter for metrics tracking: Introduced a new counter
_http_response_counter
using theget_meter
function to track the total number of HTTP responses, categorized by status code and status class. This counter is updated in theresponse_hook
function. ([api/extensions/ext_otel.pyR115-R131](https://github.com/langgenius/dify/pull/18499/files#diff-d9b99e6e386de2f18f686daf1e6fcb87ca02c20900826cbdc5892a5e81f362b6R115-R131)
)Updated imports for metrics: Added the
get_meter
import fromopentelemetry.metrics
to support the new HTTP response counter functionality. ([api/extensions/ext_otel.pyL17-R17](https://github.com/langgenius/dify/pull/18499/files#diff-d9b99e6e386de2f18f686daf1e6fcb87ca02c20900826cbdc5892a5e81f362b6L17-R17)
)We can use
sum(increase(http_server_response_count{status_class=~"4xx|5xx"}[30m])) / sum(increase(http_server_response_count[30m])) * 100
to measure the error rate after setting up this metric.Screenshots
Checklist
Important
Please review the checklist below before submitting your pull request.
dev/reformat
(backend) andcd web && npx lint-staged
(frontend) to appease the lint gods