Custom Instrumentation

To instrument certain regions of your code, you can create transactions to capture them.

Copied
# Transaction can be started by providing, at minimum, the name and the operation
$transaction = Start-SentryTransaction 'test-transaction-name' 'test-transaction-operation'

# ...
# (Perform the operation represented by the span/transaction)
# ...

$transaction.Finish() # Mark the transaction as finished and send it to Sentry

You can add individual spans to a transaction by calling the StartChild method on a transaction. This method returns a new SentrySpan object that you can use to record the duration of the operation that the span represents. When you're done with the operation, you can call the Finish method on the span to mark it as finished.

Copied
# Transaction can be started by providing, at minimum, the name and the operation
$transaction = Start-SentryTransaction 'test-transaction-name' 'test-transaction-operation'

# Transactions can have child spans (and those spans can have child spans as well)
$span = $transaction.StartChild("test-child-operation")
# ...
# (Perform the operation represented by the span/transaction)
# ...
$span.Finish() # Mark the span as finished

$span = $transaction.StartChild("another-span")
# ...
$span.Finish()


$transaction.Finish() # Mark the transaction as finished and send it to Sentry

In cases where you want to attach Spans to an already ongoing Transaction you can use SentrySdk.GetSpan(). If there is a running Transaction or Span currently on the scope, this method will return a SentryTransaction or SentrySpan; otherwise, it returns $null.

Copied
$span = [Sentry.SentrySdk]::GetSpan()

if ($null -eq $span)
{
    $span = Start-SentryTransaction 'task' 'op'
}
else
{
    $span = $span.StartChild('subtask')
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").