This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve opentracing for incoming HTTP requests #11618
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c76d39
remove `start_active_span_from_request`
richvdh c666b5b
Remove redundant tags from `incoming-federation-request`
richvdh dcb6c6a
Leave request spans open until the request completes
richvdh d44f4eb
opentracing logs for HTTP request events
richvdh 214b570
changelog
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,11 @@ | |
from synapse.http.server import HttpServer, ServletCallback | ||
from synapse.http.servlet import parse_json_object_from_request | ||
from synapse.http.site import SynapseRequest | ||
from synapse.logging import opentracing | ||
from synapse.logging.context import run_in_background | ||
from synapse.logging.opentracing import ( | ||
SynapseTags, | ||
set_tag, | ||
span_context_from_request, | ||
start_active_span, | ||
tags, | ||
start_active_span_follows_from, | ||
whitelisted_homeserver, | ||
) | ||
from synapse.server import HomeServer | ||
|
@@ -279,29 +277,19 @@ async def new_func( | |
logger.warning("authenticate_request failed: %s", e) | ||
raise | ||
|
||
request_tags = { | ||
SynapseTags.REQUEST_ID: request.get_request_id(), | ||
tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER, | ||
tags.HTTP_METHOD: request.get_method(), | ||
tags.HTTP_URL: request.get_redacted_uri(), | ||
tags.PEER_HOST_IPV6: request.getClientIP(), | ||
"authenticated_entity": origin, | ||
"servlet_name": request.request_metrics.name, | ||
} | ||
|
||
# Only accept the span context if the origin is authenticated | ||
# and whitelisted | ||
# update the active opentracing span with the authenticated entity | ||
set_tag("authenticated_entity", origin) | ||
|
||
# if the origin is authenticated and whitelisted, link to its span context | ||
context = None | ||
if origin and whitelisted_homeserver(origin): | ||
context = span_context_from_request(request) | ||
|
||
scope = start_active_span( | ||
"incoming-federation-request", child_of=context, tags=request_tags | ||
scope = start_active_span_follows_from( | ||
"incoming-federation-request", contexts=(context,) if context else () | ||
) | ||
|
||
with scope: | ||
opentracing.inject_response_headers(request.responseHeaders) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own reference, this is also called via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's right. Sorry I didn't make it clear! |
||
|
||
if origin and self.RATELIMIT: | ||
with ratelimiter.ratelimit(origin) as d: | ||
await d | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this changes the "incoming-federation-request" span so that its parent is no longer the outgoing request of the remote server, but rather the regular per-incoming-request span that is started in
AsyncResource
. Instead, the outgoing request span is set as a "reference" on the incoming request span.Given that it's extremely unusual for us to have a single Jaeger instance which contains two federating servers, this seems by far the more useful approach.