Skip to content
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

Instrument Django app with Sentry and OTel and check differences. #3128

Open
antonpirker opened this issue Jun 4, 2024 · 6 comments
Open

Comments

@antonpirker
Copy link
Member

antonpirker commented Jun 4, 2024

Instrument a Django application once with Sentry and once with Sentry using OpenTelementry for span creation. We want to compare the span waterfalls, to see the differences and what needs to be done to have feature parity.

Test setup:

Application: https://github.com/getsentry/demo-movie-search/tree/main/backend/django
A request to the /api/shows/{pk}/ API endpoint will do:

  • Run a Django view with multiple middleware (and triggering Django signals)
  • Run multiple database queries (including an N+1 query) to Postgres
  • Start a Celery task in the background
  • Run multiple queries to a Redis server

This resembles a common setup in production Django applications, that is used all over the planet.

Scenario 1) Sentry:

sentry_sdk.init(
    dsn=sentry_dsn,
    release=sentry_release,
    environment=sentry_environment,
    traces_sample_rate=sentry_traces_sample_rate,
    send_default_pii=sentry_default_pii,
    debug=sentry_debug,
)

This will load Sentries integrations (like Django, Celery, ...) by default and those Sentry integrations will create spans. Opentelementry is not used.

Scenario 2) Sentry using OpenTelementry:

sentry_sdk.init(
    dsn=sentry_dsn,
    release=sentry_release,
    environment=sentry_environment,
    traces_sample_rate=sentry_traces_sample_rate,
    send_default_pii=sentry_default_pii,
    debug=sentry_debug,
    _experiments={
        "otel_powered_performance": True
    },
)

This will disable all Sentry span creation and spans will only be created by the OpenTelemetry SDK.

@antonpirker
Copy link
Member Author

antonpirker commented Jun 27, 2024

Scenario 1) Sentry

Image

Trace in Sentry.io

@antonpirker
Copy link
Member Author

antonpirker commented Jun 27, 2024

Scenario 2) Sentry using Opentelementry

Image

Trace in Sentry.io

@antonpirker
Copy link
Member Author

antonpirker commented Jun 27, 2024

Things that I noticed:

  • Otel does not create Spans for middleware, view rendering, or Django signals (that is the Missing Instrumentation block in Otel trace)
  • One can see trigger_notifications (the Celery task) in otel spans (which is cool), but there is not much in it.

@antonpirker antonpirker changed the title Instrument Django app with OTel and Sentry and check differences. Instrument Django app with Sentry and OTel and check differences. Jun 27, 2024
@antonpirker
Copy link
Member Author

One thing of note: Database spans in OTel include a special structured comment that includes tracing and other information:
Image

@antonpirker
Copy link
Member Author

OTel database spans also include information about the HTTP server they where running in:
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants