Custom Instrumentation
Learn how to capture performance data on any action in your app.
To capture transactions and spans customized to your organization's needs, you must first set up tracing.
To instrument certain regions of your code, you can create transactions to capture them.
# 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.
# 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
.
$span = [Sentry.SentrySdk]::GetSpan()
if ($null -eq $span)
{
$span = Start-SentryTransaction 'task' 'op'
}
else
{
$span = $span.StartChild('subtask')
}
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").