This issue is more about the general design principle on all Sentry SDKs instead of just sentry-ruby. I want to discuss the necessity of falling back to Sentry.get_current_hub when the hub is not provided.
In sentry-python, it's done in Transaction.finish:
https://github.com/getsentry/sentry-python/blob/19fa43fec5a20b3561a16970ce395c93ac1be57d/sentry_sdk/tracing.py#L409-L417
In sentry-javascript, it looks to be done in the constructor?
https://github.com/getsentry/sentry-javascript/blob/fbdc8753ab5e54fb8c83101de78a805ec7335522/packages/tracing/src/transaction.ts#L22-L46
And currently, sentry-ruby does it like this
def initialize(name: nil, parent_sampled: nil, hub: Sentry.get_current_hub, **options)
Shouldn't we make the hub argument a hard requirement when initializing a Transaction object? Which means, we should never need to fallback to the current active hub.
I think we'd agree that a Transaction object should never be initialized manually by the user, which is also stated in sentry-javascript's comment:
* This constructor should never be called manually. Those instrumenting tracing should use
* `Sentry.startTransaction()`, and internal methods should use `hub.startTransaction()`.
If that's the case, hub.startTransaction() should always be able to provide a hub to the transaction, and thus never need to fallback to getCurrentHub().
So what I'm proposing are:
- Stop making the
hub argument optional for the Transaction constructor.
- Remove all the fallback logic from the constructor or
Transaction.finish. Because it must present and must be a Hub instance.
Wdyt?
This issue is more about the general design principle on all Sentry SDKs instead of just
sentry-ruby. I want to discuss the necessity of falling back toSentry.get_current_hubwhen thehubis not provided.In
sentry-python, it's done inTransaction.finish:https://github.com/getsentry/sentry-python/blob/19fa43fec5a20b3561a16970ce395c93ac1be57d/sentry_sdk/tracing.py#L409-L417
In
sentry-javascript, it looks to be done in the constructor?https://github.com/getsentry/sentry-javascript/blob/fbdc8753ab5e54fb8c83101de78a805ec7335522/packages/tracing/src/transaction.ts#L22-L46
And currently,
sentry-rubydoes it like thisShouldn't we make the
hubargument a hard requirement when initializing aTransactionobject? Which means, we should never need to fallback to the current active hub.I think we'd agree that a
Transactionobject should never be initialized manually by the user, which is also stated insentry-javascript's comment:If that's the case,
hub.startTransaction()should always be able to provide ahubto the transaction, and thus never need to fallback togetCurrentHub().So what I'm proposing are:
hubargument optional for theTransactionconstructor.Transaction.finish. Because it must present and must be aHubinstance.Wdyt?