-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: add plugin execution tracing to OpenTelemetry plugin #12681
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
Open
aliibii
wants to merge
3
commits into
apache:master
Choose a base branch
from
aliibii:feat/opentelemetry-plugin-tracing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,138
−4
Conversation
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
f456f22 to
8393636
Compare
8393636 to
70731ad
Compare
087aa81 to
d478351
Compare
This commit adds plugin execution tracing capability to the OpenTelemetry plugin, allowing users to trace individual plugin phases (rewrite, access, header_filter, body_filter, log) as child spans of the main request trace. Changes: - Added trace_plugins configuration option (default: false, opt-in) - Added plugin_span_kind configuration for observability provider compatibility - Enhanced plugin execution with OpenTelemetry span creation and finishing - Added comprehensive request context attributes to plugin spans - Updated documentation with examples and usage instructions - Added comprehensive test suite for the new functionality Features: - Plugin Phase Tracing: Creates child spans for each plugin phase execution - Rich Context: Includes HTTP method, URI, hostname, user agent, route info, and service info - Configurable: Can be enabled/disabled via trace_plugins configuration - Span Kind Control: Supports internal (default) and server span kinds for observability provider compatibility - Proper Hierarchy: Plugin spans are correctly nested under main request spans - Performance: Minimal overhead when disabled (default behavior) Configuration: - trace_plugins: boolean (default: false) - Enable/disable plugin tracing - plugin_span_kind: string (default: 'internal') - Span kind for plugin spans - 'internal': Standard internal operation (may be excluded from metrics) - 'server': Server-side operation (typically included in service-level metrics) This addresses GitHub issue apache#12510 and provides end-to-end tracing visibility for APISIX plugin execution phases.
d478351 to
8af172f
Compare
Member
|
2cba5ed to
a81fd3e
Compare
Contributor
|
Hi @aliibii, thanks for your contribution. Could you please fix the failed CI? |
Contributor
|
Hi @aliibii, following up on the previous review comments. Let us know if you have an update. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
plugin
size:XXL
This PR changes 1000+ lines, ignoring generated files.
wait for update
wait for the author's response in this issue/PR
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.
Description
This commit adds plugin execution tracing capability to the OpenTelemetry plugin, allowing users to trace individual plugin phases (rewrite, access, header_filter, body_filter, log) as child spans of the main request trace.
Changes:
New OpenTelemetry API functions available to plugins via
api_ctx.otel:api_ctx.otel.start_span(span_info)- Create custom spansapi_ctx.otel.stop_span(span_ctx, error_msg)- Finish spans with error handlingapi_ctx.otel.current_span()- Get current span contextapi_ctx.otel.get_plugin_context(plugin_name, phase)- Get plugin phase span contextapi_ctx.otel.with_span(span_info, fn)- Create span, execute function, and automatically finish spanspan_ctxas its first parameter, allowing access to the span for setting attributesFeatures:
with_spanprovides automatic span lifecycle management with error handlingWhich issue(s) this PR fixes:
Resolves #12510
Checklist