Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of what's changed. Looking for a more digestible summary? See the guide in the docs with the most common migration patterns.
- Added
add_attachment()as a top level API, so you can do now:sentry_sdk.add_attachment(...)(up until now it was only available on theScope)
-
The SDK now supports Python 3.7 and higher.
-
The default of
traces_sample_ratechanged to0. Meaning: Incoming traces will be continued by default. For example, if your frontend sends asentry-trace/baggageheaders pair, your SDK will create Spans and send them to Sentry. (The default used to beNonemeaning by default no Spans where created, no matter what headers the frontend sent to your project.) See also: https://docs.sentry.io/platforms/python/configuration/options/#traces_sample_rate -
Tag values on event dictionaries, which are passed to
before_sendandbefore_send_transaction, now are alwaysstrvalues. Previously, despite tag values being typed asstr, they often had different values. Therefore, if you have configured anybefore_sendandbefore_send_transactionfunctions which perform some logic based on tag values, you need to check and if needed update those functions to correctly handlestrvalues. -
sentry_sdk.start_spannow only takes keyword arguments. -
sentry_sdk.start_transaction/sentry_sdk.start_spanno longer takes the following arguments:span,parent_sampled,trace_id,span_idorparent_span_id. -
You can no longer change the sampled status of a span with
span.sampled = Falseafter starting it. -
The
Span()constructor does not accept ahubparameter anymore. -
The
sentry_sdk.Scope()constructor no longer accepts aclientparameter. -
Span.finish()does not accept ahubparameter anymore. -
Span.finish()no longer returns theevent_idif the event is sent to sentry. -
The
Profile()constructor does not accept ahubparameter anymore. -
A
Profileobject does not have a.hubproperty anymore. -
MAX_PROFILE_DURATION_NS,PROFILE_MINIMUM_SAMPLES,Profile,Scheduler,ThreadScheduler,GeventScheduler,has_profiling_enabled,setup_profiler,teardown_profilerare no longer accessible fromsentry_sdk.profiler. They're still accessible fromsentry_sdk.profiler.transaction_profiler. -
DEFAULT_SAMPLING_FREQUENCY,MAX_STACK_DEPTH,get_frame_name,extract_frame,extract_stack,frame_idare no longer accessible fromsentry_sdk.profiler. They're still accessible fromsentry_sdk.profiler.utils. -
sentry_sdk.continue_traceno longer returns aTransactionand is now a context manager. -
Redis integration: In Redis pipeline spans there is no
span["data"]["redis.commands"]that contains a dict{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}but insteadspan["data"]["redis.commands.count"](containing3) andspan["data"]["redis.commands.first_ten"](containing["cmd1", "cmd2", ...]). -
clickhouse-driver integration: The query is now available under the
db.query.textspan attribute (only ifsend_default_piiisTrue). -
sentry_sdk.initnow returnsNoneinstead of a context manager. -
The
sampling_contextargument oftraces_samplerandprofiles_samplernow additionally contains all span attributes known at span start. -
We updated how we handle
ExceptionGroups. You will now get more data if ExceptionGroups are appearing in chained exceptions. It could happen that after updating the SDK the grouping of issues change because of this. So eventually you will see the same exception in two Sentry issues (one from before the update, one from after the update) -
The integration for Python
loggingmodule does not send Sentry issues by default anymore when callinglogging.error(),logging.critical()orlogging.exception(). If you want to preserve the old behavior usesentry_sdk.init(integrations=[LoggingIntegration(event_level="ERROR")]). -
The
SentrySpanProcessorandSentryPropagatorare exported fromsentry_sdk.opentelemetryinstead ofsentry_sdk.integrations.opentelemetry. -
The integration-specific content of the
sampling_contextargument oftraces_samplerandprofiles_samplernow looks different.-
The Celery integration doesn't add the
celery_jobdictionary anymore. Instead, the individual keys are now available as:Dictionary keys Sampling context key Example celery_job["args"]celery.job.args.{index}celery.job.args.0celery_job["kwargs"]celery.job.kwargs.{kwarg}celery.job.kwargs.kwarg_namecelery_job["task"]celery.job.taskNote that all of these are serialized, i.e., not the original
argsandkwargsbut rather OpenTelemetry-friendly span attributes. -
The AIOHTTP integration doesn't add the
aiohttp_requestobject anymore. Instead, some of the individual properties of the request are accessible, if available, as follows:Request property Sampling context key(s) pathurl.pathquery_stringurl.querymethodhttp.request.methodhostserver.address,server.portschemeurl.schemefull URL url.fullrequest.headershttp.request.header.{header} -
The Tornado integration doesn't add the
tornado_requestobject anymore. Instead, some of the individual properties of the request are accessible, if available, as follows:Request property Sampling context key(s) pathurl.pathqueryurl.queryprotocolurl.schememethodhttp.request.methodhostserver.address,server.portversionnetwork.protocol.name,network.protocol.versionfull URL url.fullrequest.headershttp.request.header.{header} -
The WSGI integration doesn't add the
wsgi_environobject anymore. Instead, the individual properties of the environment are accessible, if available, as follows:Env property Sampling context key(s) PATH_INFOurl.pathQUERY_STRINGurl.queryREQUEST_METHODhttp.request.methodSERVER_NAMEserver.addressSERVER_PORTserver.portSERVER_PROTOCOLserver.protocol.name,server.protocol.versionwsgi.url_schemeurl.schemefull URL url.fullHTTP_*http.request.header.{header} -
The ASGI integration doesn't add the
asgi_scopeobject anymore. Instead, the individual properties of the scope, if available, are accessible as follows:Scope property Sampling context key(s) typenetwork.protocol.nameschemeurl.schemepathurl.pathqueryurl.queryhttp_versionnetwork.protocol.versionmethodhttp.request.methodserverserver.address,server.portclientclient.address,client.portfull URL url.fullheadershttp.request.header.{header} -
The RQ integration doesn't add the
rq_jobobject anymore. Instead, the individual properties of the job and the queue, if available, are accessible as follows:RQ property Sampling context key Example rq_job.argsrq.job.args.{index}rq.job.args.0rq_job.kwargsrq.job.kwargs.{kwarg}rq.job.args.my_kwargrq_job.funcrq.job.funcqueue.namemessaging.destination.namerq_job.idmessaging.message.idNote that
rq.job.args,rq.job.kwargs, andrq.job.funcare serialized and not the actual objects on the job. -
The AWS Lambda integration doesn't add the
aws_eventandaws_contextobjects anymore. Instead, the following, if available, is accessible:AWS property Sampling context key(s) aws_event["httpMethod"]http.request.methodaws_event["queryStringParameters"]url.queryaws_event["path"]url.pathfull URL url.fullaws_event["headers"]["X-Forwarded-Proto"]network.protocol.nameaws_event["headers"]["Host"]server.addressaws_context["function_name"]faas.nameaws_event["headers"]http.request.headers.{header} -
The GCP integration doesn't add the
gcp_envandgcp_eventkeys anymore. Instead, the following, if available, is accessible:Old sampling context key New sampling context key gcp_env["function_name"]faas.namegcp_env["function_region"]faas.regiongcp_env["function_project"]gcp.function.projectgcp_env["function_identity"]gcp.function.identitygcp_env["function_entry_point"]gcp.function.entry_pointgcp_event.methodhttp.request.methodgcp_event.query_stringurl.querygcp_event.headershttp.request.header.{header}
-
- Dropped support for Python 3.6.
- The
enable_tracinginitoption has been removed. Configuretraces_sample_ratedirectly. - The
propagate_tracesinitoption has been removed. Usetrace_propagation_targetsinstead. - The
custom_sampling_contextparameter ofstart_transactionhas been removed. Useattributesinstead to set key-value pairs of data that should be accessible in the traces sampler. Note that span attributes need to conform to the OpenTelemetry specification, meaning only certain types can be set as values. set_measurementhas been removed.- The PyMongo integration no longer sets tags. The data is still accessible via span attributes.
- The PyMongo integration doesn't set
operation_idsanymore. The individual IDs (operation_id,request_id,session_id) are now accessible as separate span attributes. sentry_sdk.metricsand associated metrics APIs have been removed as Sentry no longer accepts metrics data in this form. See https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics- The experimental options
enable_metrics,before_emit_metricandmetric_code_locationshave been removed. - When setting span status, the HTTP status code is no longer automatically added as a tag.
- Class
Hubhas been removed. - Class
_ScopeManagerhas been removed. - The context manager
auto_session_tracking()has been removed. Usetrack_session()instead. - The context manager
auto_session_tracking_scope()has been removed. Usetrack_session()instead. - Utility function
is_auto_session_tracking_enabled()has been removed. There is no public replacement. There is a private_is_auto_session_tracking_enabled()(if you absolutely need this function) It accepts ascopeparameter instead of the previously usedhubparameter. - Utility function
is_auto_session_tracking_enabled_scope()has been removed. There is no public replacement. There is a private_is_auto_session_tracking_enabled()(if you absolutely need this function). - Setting
scope.levelhas been removed. Usescope.set_levelinstead. span.containing_transactionhas been removed. Usespan.root_spaninstead.continue_from_headers,continue_from_environandfrom_traceparenthave been removed, please use top-level APIsentry_sdk.continue_traceinstead.PropagationContextconstructor no longer takes adynamic_sampling_contextbut takes abaggageobject instead.ThreadingIntegrationno longer takes thepropagate_hubargument.Baggage.populate_from_transactionhas been removed.debug.configure_debug_hubwas removed.profiles_sample_rateandprofiler_modewere removed from options available via_experiments. Use the top-levelprofiles_sample_rateandprofiler_modeoptions instead.Transport.capture_eventhas been removed. UseTransport.capture_envelopeinstead.- Function transports are no longer supported. Subclass the
Transportinstead. start_transaction(start_span) no longer takes the following arguments:trace_id,baggage: usecontinue_tracefor propagation from headers or environment variablessame_process_as_parentspan_idparent_span_id: you can supply aparent_spaninstead
- The
Scope.transactionproperty has been removed. To obtain the root span (previously transaction), useScope.root_span. To set the root span's (transaction's) name, useScope.set_transaction_name(). - The
Scope.span =setter has been removed. Please use the newspan.activate()api instead if you want to activate a new span manually instead of using thestart_spancontext manager. - Passing a list or
Noneforfailed_request_status_codesin the Starlette integration is no longer supported. Pass a set of integers instead. - The
spanargument ofScope.trace_propagation_metais no longer supported. - Setting
Scope.userdirectly is no longer supported. UseScope.set_user()instead. - Dropped support for Django versions below 2.0.
- Dropped support for trytond versions below 5.0.
- Dropped support for Falcon versions below 3.0.
- Dropped support for eventlet completely.
sentry_sdk.start_transaction()is deprecated. Usesentry_sdk.start_span()instead.Span.set_data()is deprecated. UseSpan.set_attribute()instead.
Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of what's changed. Looking for a more digestible summary? See the guide in the docs with the most common migration patterns.
- Additional integrations will now be activated automatically if the SDK detects the respective package is installed: Ariadne, ARQ, asyncpg, Chalice, clickhouse-driver, GQL, Graphene, huey, Loguru, PyMongo, Quart, Starlite, Strawberry.
- While refactoring the inner workings of the SDK we added new top-level APIs for custom instrumentation called
new_scopeandisolation_scope. See the Deprecated section to see how they map to the existing APIs.
-
The Pyramid integration will not capture errors that might happen in
authenticated_userid()in a customAuthenticationPolicyclass. -
The method
need_code_loationof theMetricsAggregatorwas renamed toneed_code_location. -
The
BackgroundWorkerthread used to process events was renamed fromraven-sentry.BackgroundWorkertosentry-sdk.BackgroundWorker. -
The
reraisefunction was moved fromsentry_sdk._compattosentry_sdk.utils. -
The
_ScopeManagerwas moved fromsentry_sdk.hubtosentry_sdk.scope. -
The signature for the metrics callback function set with
before_emit_metrichas changed frombefore_emit_metric(key, tags)tobefore_emit_metric(key, value, unit, tags) -
Moved the contents of
tracing_utils_py3.pytotracing_utils.py. Thestart_child_span_decoratoris now insentry_sdk.tracing_utils. -
The actual implementation of
get_current_spanwas moved tosentry_sdk.tracing_utils.sentry_sdk.get_current_spanis still accessible as part of the top-level API. -
sentry_sdk.tracing_utils.add_query_source(): Removed thehubparameter. It is not necessary anymore. -
sentry_sdk.tracing_utils.record_sql_queries(): Removed thehubparameter. It is not necessary anymore. -
sentry_sdk.tracing_utils.get_current_span()does now take ascopeinstead of ahubas parameter. -
sentry_sdk.tracing_utils.should_propagate_trace()now takes aClientinstead of aHubas first parameter. -
sentry_sdk.utils.is_sentry_url()now takes aClientinstead of aHubas first parameter. -
sentry_sdk.utils._get_contextvarsdoes not return a tuple with three values, but a tuple with two values. Thecopy_contextwas removed. -
You no longer have to use
configure_scopeto mutate a transaction. Instead, you simply get the current scope to mutate the transaction. Here is a recipe on how to change your code to make it work: Your existing implementation:transaction = sentry_sdk.transaction(...) # later in the code execution: with sentry_sdk.configure_scope() as scope: scope.set_transaction_name("new-transaction-name")
needs to be changed to this:
transaction = sentry_sdk.transaction(...) # later in the code execution: scope = sentry_sdk.get_current_scope() scope.set_transaction_name("new-transaction-name")
-
The classes listed in the table below are now abstract base classes. Therefore, they can no longer be instantiated. Subclasses can only be instantiated if they implement all of the abstract methods.
Show table
Class Abstract methods sentry_sdk.integrations.Integrationsetup_oncesentry_sdk.metrics.Metricadd,serialize_value, andweightsentry_sdk.profiler.Schedulersetupandteardownsentry_sdk.transport.Transportcapture_envelope
- Removed support for Python 2 and Python 3.5. The SDK now requires at least Python 3.6.
- Removed support for Celery 3.*.
- Removed support for Django 1.8, 1.9, 1.10.
- Removed support for Flask 0.*.
- Removed support for gRPC < 1.39.
- Removed support for Tornado < 6.
- Removed support for sending events to the
/storeendpoint. Everything is now sent to the/envelopeendpoint. If you're on SaaS you don't have to worry about this, but if you're running Sentry yourself you'll need version20.6.0or higher of self-hosted Sentry. - The deprecated
with_localsconfiguration option was removed. Useinclude_local_variablesinstead. See https://docs.sentry.io/platforms/python/configuration/options/#include-local-variables. - The deprecated
request_bodiesconfiguration option was removed. Usemax_request_body_size. See https://docs.sentry.io/platforms/python/configuration/options/#max-request-body-size. - Removed support for
user.segment. It was also removed from the trace header as well as from the dynamic sampling context. - Removed support for the
installmethod for custom integrations. Please usesetup_onceinstead. - Removed
sentry_sdk.tracing.Span.new_span. Usesentry_sdk.tracing.Span.start_childinstead. - Removed
sentry_sdk.tracing.Transaction.new_span. Usesentry_sdk.tracing.Transaction.start_childinstead. - Removed support for creating transactions via
sentry_sdk.tracing.Span(transaction=...). To create a transaction, please usesentry_sdk.tracing.Transaction(name=...). - Removed
sentry_sdk.utils.Auth.store_api_url. sentry_sdk.utils.Auth.get_api_url's now accepts asentry_sdk.consts.EndpointTypeenum instead of a string as its only parameter. We recommend omitting this argument when calling the function, since the parameter's default value is the only possiblesentry_sdk.consts.EndpointTypevalue. The parameter exists for future compatibility.- Removed
tracing_utils_py2.py. Thestart_child_span_decoratoris now insentry_sdk.tracing_utils. - Removed the
sentry_sdk.profiler.Scheduler.stop_profilingmethod. Any calls to this method can simply be removed, since this was a no-op method. - Removed the experimental
metrics_summary_sample_rateconfig option. - Removed the experimental
should_summarize_metricconfig option.
-
Using the
Hubdirectly as well as using hub-based APIs has been deprecated. Where available, use the top-level API instead; otherwise use the scope API or the client API.Before:
with hub.start_span(...): # do something
After:
import sentry_sdk with sentry_sdk.start_span(...): # do something
-
Hub cloning is deprecated.
Before:
with Hub(Hub.current) as hub: # do something with the cloned hub
After:
import sentry_sdk with sentry_sdk.isolation_scope() as scope: # do something with the forked scope
-
configure_scopeis deprecated. Modify the current or isolation scope directly instead.Before:
with configure_scope() as scope: # do something with `scope`
After:
from sentry_sdk import get_current_scope scope = get_current_scope() # do something with `scope`
Or:
from sentry_sdk import get_isolation_scope scope = get_isolation_scope() # do something with `scope`
When to use
get_current_scope()andget_isolation_scope()depends on how long the change to the scope should be in effect. If you want the changed scope to affect the whole request-response cycle or the whole execution of task, use the isolation scope. If it's more localized, use the current scope. -
push_scopeis deprecated. Fork the current or the isolation scope instead.Before:
with push_scope() as scope: # do something with `scope`
After:
import sentry_sdk with sentry_sdk.new_scope() as scope: # do something with `scope`
Or:
import sentry_sdk with sentry_sdk.isolation_scope() as scope: # do something with `scope`
new_scope()will fork the current scope, whileisolation_scope()will fork the isolation scope. The lifecycle of a single isolation scope roughly translates to the lifecycle of a transaction in most cases, so if you're looking to create a new separated scope for a whole request-response cycle or task execution, go forisolation_scope(). If you want to wrap a smaller unit code, fork the current scope instead withnew_scope(). -
Accessing the client via the hub has been deprecated. Use the top-level
sentry_sdk.get_client()to get the current client. -
profiler_modeandprofiles_sample_ratehave been deprecated as_experimentsoptions. Use them as top level options instead:sentry_sdk.init( ..., profiler_mode="thread", profiles_sample_rate=1.0, )
-
Deprecated
sentry_sdk.transport.Transport.capture_event. Please usesentry_sdk.transport.Transport.capture_envelope, instead. -
Passing a function to
sentry_sdk.init'stransportkeyword argument has been deprecated. If you wish to provide a custom transport, please pass asentry_sdk.transport.Transportinstance or a subclass. -
The parameter
propagate_hubinThreadingIntegration()was deprecated and renamed topropagate_scope.