diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8779352da19e..955beb4aa08e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -234,7 +234,7 @@ jobs: working-directory: /src - name: Summarise results.tap if: ${{ always() }} - run: /scripts/tap_to_gha.pl /logs/results.tap + run: /sytest/scripts/tap_to_gha.pl /logs/results.tap - name: Upload SyTest logs uses: actions/upload-artifact@v2 if: ${{ always() }} diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index 428831dad6ad..82aa26e9623a 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -220,9 +220,12 @@ class _DummyTagNames: import opentracing tags = opentracing.tags + Span = opentracing.Span except ImportError: opentracing = None tags = _DummyTagNames + Span = None + try: from jaeger_client import Config as JaegerConfig @@ -272,6 +275,12 @@ class SynapseTags: REQUEST_TAG = "request_tag" +class SynapseBaggage: + """labels for synapse's baggage items""" + + DEBUG_TRACING = "s" + + # Block everything by default # A regex which matches the server_names to expose traces for. # None means 'block everything'. @@ -404,6 +413,13 @@ def whitelisted_homeserver(destination): # Start spans and scopes + +@only_if_tracing +def active_span(): + """Returns the active span, if any""" + return opentracing.tracer.active_span + + # Could use kwargs but I want these to be explicit def start_active_span( operation_name, @@ -561,6 +577,22 @@ def set_operation_name(operation_name): opentracing.tracer.active_span.set_operation_name(operation_name) +@ensure_active_span("set baggage on the trace") +def set_baggage_item(key, value): + """Stores a Baggage item on the active span as a key/value pair. + + Baggage is arbitrary data which is attached to a span, and inherited by + children of that span, including spans on remote servers. + """ + return opentracing.tracer.active_span.set_baggage_item(key, value) + + +@ensure_active_span("get baggage on the trace") +def get_baggage_item(key): + """Get a Baggage item from the active span.""" + return opentracing.tracer.active_span.set_baggage_item(key) + + # Injection and extraction diff --git a/synapse/storage/database.py b/synapse/storage/database.py index a761ad603bbb..4645415d6bde 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -40,6 +40,7 @@ from synapse.api.errors import StoreError from synapse.config.database import DatabaseConnectionConfig +from synapse.logging import opentracing from synapse.logging.context import ( LoggingContext, current_context, @@ -707,6 +708,10 @@ async def runWithConnection( start_time = monotonic_time() + # if we have an active opentracing span, and that span has been prioritised, + # start a new span for the query. + opentracing.trace() + def inner_func(conn, *args, **kwargs): # We shouldn't be in a transaction. If we are then something # somewhere hasn't committed after doing work. (This is likely only