Skip to content

Scope::getTransaction returns null when Transaction isn't sampled #1333

@blackwolf12333

Description

@blackwolf12333

Environment

How do you use Sentry?
Sentry SaaS (sentry.io)

Which SDK and version?
[email protected]

Steps to Reproduce

  1. initialize sentry with a very low sample rate for easier repro
  2. call $transaction = startTransaction
  3. call SentrySdk::getCurrentHub()->setSpan($transaction)
  4. call SentrySdk::getCurrentHub()->getTransaction()

Expected Result

I expected to get the instance of the Transaction I just started.

Actual Result

getTransaction returned null because when you call startTransaction and this transaction isn't getting sampled it does not initialize the SpanRecorder (Hub.php:256). However, getTransaction gets the transaction from Scope which checks for an active SpanRecorder and returns null otherwise.

This behavior is not documented anywhere, I think it would suffice to add a note to the Hub::getTransaction method that if it's not sampled it will return null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions