Skip to content

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Aug 20, 2025

Switch to OpenTracing's ContextVarsScopeManager instead of our own custom LogContextScopeManager.

This is now possible because the linked Twisted issue from this comment is resolved:

It would be nice just to use opentracing's ContextVarsScopeManager,
but currently that doesn't work due to https://twistedmatrix.com/trac/ticket/10301.

This PR is spawning from exploring different possibilities to solve the scope loss problem I was encountering in #18804 (comment). This appears to solve the problem and I've added the additional test from there to this PR ✅


Related to #10342 (previously matrix-org/synapse#10342) where we also want to change our LoggingContext machinery to base ContextVar based.

Testing strategy

  1. Run a Jaeger instance (https://www.jaegertracing.io/docs/1.6/getting-started/)
    $ docker run -d --name jaeger \
      -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
      -p 5775:5775/udp \
      -p 6831:6831/udp \
      -p 6832:6832/udp \
      -p 5778:5778 \
      -p 16686:16686 \
      -p 14268:14268 \
      -p 9411:9411 \
      jaegertracing/all-in-one:1.59.0
  2. Configure Synapse to use tracing:
    homeserver.yaml
    ## Tracing ##
    opentracing:
     enabled: true
     jaeger_config:
       sampler:
         type: const
         param: 1
       logging:
         false
  3. Make sure the optional opentracing depdency is installed: poetry install --extras all
  4. Run Synapse: poetry run synapse_homeserver --config-path homeserver.yaml
  5. Make some requests: GET http://localhost:8008/_matrix/client/versions
  6. Visit http://localhost:16686/search to view the traces
    • Select the correct service
    • Select a relevant 'Operation' like one of the Servlet's
    • Press 'Find Traces' button

I tested a few endpoints and the traces seem to look normal.

Dev notes

SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.logging.test_opentracing

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

@@ -54,17 +56,18 @@
logger = logging.getLogger(__name__)


class LogContextScopeManagerTestCase(TestCase):
class TracingScopeTestCase(TestCase):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we've removed the LogContextScopeManager now, I've decided to keep these tests around. They appear like good sanity checks to make sure our tracing still works with Twisted regardless of what we try to use.

@MadLittleMods MadLittleMods changed the title Switch to OpenTracing ContextVarsScopeManager Switch to OpenTracing's ContextVarsScopeManager Aug 20, 2025
@MadLittleMods MadLittleMods force-pushed the madlittlemods/switch-to-opentracing-context-vars-scope-manager branch from a9d7008 to b1f308c Compare August 20, 2025 20:47
MadLittleMods added a commit that referenced this pull request Aug 20, 2025
These changes are being introduced in #18849
instead.
@MadLittleMods MadLittleMods marked this pull request as ready for review August 20, 2025 21:09
@MadLittleMods MadLittleMods requested a review from a team as a code owner August 20, 2025 21:09
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@MadLittleMods MadLittleMods merged commit 27fc338 into develop Aug 27, 2025
111 of 117 checks passed
@MadLittleMods MadLittleMods deleted the madlittlemods/switch-to-opentracing-context-vars-scope-manager branch August 27, 2025 16:41
@MadLittleMods
Copy link
Contributor Author

Thanks for the review @anoadragon453 🐍

MadLittleMods added a commit that referenced this pull request Aug 27, 2025
…e while writing bytes to the request (#18804)

This will allow to easily see how much time is taken up by
being able to filter by the `write_bytes_to_request` operation
in Jaeger.

Spawning from #17722

The `write_bytes_to_request` span won't show up in the trace until
#18849 is merged.

Note: It's totally fine for a span child to finish after the parent. See
https://opentracing.io/specification/#references-between-spans which
shows "Child Span D" outliving the "Parent Span"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants