Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Stylish imports
Browse files Browse the repository at this point in the history
  • Loading branch information
JorikSchellekens committed Aug 14, 2019
1 parent 7674ae0 commit 6ccc3b6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from twisted.internet.abstract import isIPAddress
from twisted.python import failure

import synapse.logging.opentracing as opentracing
from synapse.api.constants import EventTypes, Membership
from synapse.api.errors import (
AuthError,
Expand All @@ -44,6 +43,7 @@
from synapse.federation.units import Edu, Transaction
from synapse.http.endpoint import parse_server_name
from synapse.logging.context import nested_logging_context
from synapse.logging.opentracing import start_active_span_from_edu
from synapse.logging.utils import log_function
from synapse.replication.http.federation import (
ReplicationFederationSendEduRestServlet,
Expand Down Expand Up @@ -809,7 +809,7 @@ def on_edu(self, edu_type, origin, content):
if not handler:
logger.warn("No handler registered for EDU type %s", edu_type)

with opentracing.start_active_span_from_edu(content, "handle_edu"):
with start_active_span_from_edu(content, "handle_edu"):
try:
yield handler(origin, content)
except SynapseError as e:
Expand Down
8 changes: 3 additions & 5 deletions synapse/federation/sender/per_destination_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from twisted.internet import defer

import synapse.logging.opentracing as opentracing
from synapse.api.errors import (
FederationDeniedError,
HttpResponseException,
Expand All @@ -30,6 +29,7 @@
from synapse.events import EventBase
from synapse.federation.units import Edu
from synapse.handlers.presence import format_user_presence_state
from synapse.logging.opentracing import extract_text_map, start_active_span_follows_from
from synapse.metrics import sent_transactions_counter
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.storage import UserPresenceState
Expand Down Expand Up @@ -211,17 +211,15 @@ def _transaction_transmission_loop(self):
# are never received on the remote the span effectively has no causality.

span_contexts = [
opentracing.extract_text_map(
extract_text_map(
json.loads(
edu.get_dict().get("content", {}).get("context", "{}")
)
)
for edu in pending_edus
]

with opentracing.start_active_span_follows_from(
"send_transaction", span_contexts
):
with start_active_span_follows_from("send_transaction", span_contexts):
# BEGIN CRITICAL SECTION
#
# In order to avoid a race condition, we need to make sure that
Expand Down
12 changes: 6 additions & 6 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import re

import synapse
import synapse.logging.opentracing as opentracing
from synapse.api.errors import Codes, FederationDeniedError, SynapseError
from synapse.api.room_versions import RoomVersions
from synapse.api.urls import (
Expand All @@ -37,6 +36,7 @@
parse_string_from_args,
)
from synapse.logging.context import run_in_background
from synapse.logging.opentracing import start_active_span_from_context, tags
from synapse.types import ThirdPartyInstanceID, get_domain_from_id
from synapse.util.ratelimitutils import FederationRateLimiter
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -287,15 +287,15 @@ async def new_func(request, *args, **kwargs):
raise

# Start an opentracing span
with opentracing.start_active_span_from_context(
with start_active_span_from_context(
request.requestHeaders,
"incoming-federation-request",
tags={
"request_id": request.get_request_id(),
opentracing.tags.SPAN_KIND: opentracing.tags.SPAN_KIND_RPC_SERVER,
opentracing.tags.HTTP_METHOD: request.get_method(),
opentracing.tags.HTTP_URL: request.get_redacted_uri(),
opentracing.tags.PEER_HOST_IPV6: request.getClientIP(),
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,
},
):
Expand Down
15 changes: 10 additions & 5 deletions synapse/handlers/devicemessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@

from twisted.internet import defer

import synapse.logging.opentracing as opentracing
from synapse.api.errors import SynapseError
from synapse.logging.opentracing import (
get_active_span_text_map,
set_tag,
start_active_span,
whitelisted_homeserver,
)
from synapse.types import UserID, get_domain_from_id
from synapse.util.stringutils import random_string

Expand Down Expand Up @@ -103,19 +108,19 @@ def send_device_message(self, sender_user_id, message_type, messages):

message_id = random_string(16)

context = opentracing.get_active_span_text_map()
context = get_active_span_text_map()

remote_edu_contents = {}
for destination, messages in remote_messages.items():
with opentracing.start_active_span("to_device_for_user"):
opentracing.set_tag("destination", destination)
with start_active_span("to_device_for_user"):
set_tag("destination", destination)
remote_edu_contents[destination] = {
"messages": messages,
"sender": sender_user_id,
"type": message_type,
"message_id": message_id,
"org.matrix.context": json.dumps(context)
if opentracing.whitelisted_homeserver(destination)
if whitelisted_homeserver(destination)
else None,
}

Expand Down
23 changes: 13 additions & 10 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from twisted.web._newclient import ResponseDone
from twisted.web.http_headers import Headers

import synapse.logging.opentracing as opentracing
import synapse.metrics
import synapse.util.retryutils
from synapse.api.errors import (
Expand All @@ -50,6 +49,12 @@
from synapse.http.client import BlacklistingAgentWrapper, IPBlacklistingResolver
from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent
from synapse.logging.context import make_deferred_yieldable
from synapse.logging.opentracing import (
inject_active_span_byte_dict,
set_tag,
start_active_span,
tags,
)
from synapse.util.async_helpers import timeout_deferred
from synapse.util.metrics import Measure

Expand Down Expand Up @@ -341,20 +346,20 @@ def _send_request(
query_bytes = b""

# Retreive current span
scope = opentracing.start_active_span(
scope = start_active_span(
"outgoing-federation-request",
tags={
opentracing.tags.SPAN_KIND: opentracing.tags.SPAN_KIND_RPC_CLIENT,
opentracing.tags.PEER_ADDRESS: request.destination,
opentracing.tags.HTTP_METHOD: request.method,
opentracing.tags.HTTP_URL: request.path,
tags.SPAN_KIND: tags.SPAN_KIND_RPC_CLIENT,
tags.PEER_ADDRESS: request.destination,
tags.HTTP_METHOD: request.method,
tags.HTTP_URL: request.path,
},
finish_on_close=True,
)

# Inject the span into the headers
headers_dict = {}
opentracing.inject_active_span_byte_dict(headers_dict, request.destination)
inject_active_span_byte_dict(headers_dict, request.destination)

headers_dict[b"User-Agent"] = [self.version_string_bytes]

Expand Down Expand Up @@ -436,9 +441,7 @@ def _send_request(
response.phrase.decode("ascii", errors="replace"),
)

opentracing.set_tag(
opentracing.tags.HTTP_STATUS_CODE, response.code
)
set_tag(tags.HTTP_STATUS_CODE, response.code)

if 200 <= response.code < 300:
pass
Expand Down

0 comments on commit 6ccc3b6

Please sign in to comment.