Sentry SDK
1 Introduction
This library provides an interface for capturing and sending errors to either a managed or a self-hosted Sentry instance.
2 Quickstart
Install the package from the package server with
$ raco pkg install sentry |
Call make-sentry to create an instance of the sentry client. Keep a reference to the client around for as long as your application needs to run and you can start sending exceptions by calling sentry-capture-exception!:
(require sentry) (define client (make-sentry "https://key@sentry.io/12")) (parameterize ([current-sentry client]) (sentry-capture-exception! (make-exn:fail "an error" (current-continuation-marks)))) (sentry-stop client)
3 Reference
(require sentry) | package: sentry-lib |
3.1 Core API
Added in version 0.5 of package sentry-lib.
parameter
(current-sentry) → (or/c #f sentry?)
(current-sentry client) → void? client : (or/c #f sentry?)
procedure
(make-sentry dsn [ #:sampler sampler #:backlog backlog #:release release #:environment environment #:connect-timeout-ms connect-timeout #:send-timeout-ms send-timeout #:max-breadcrumbs max-breadcrumbs]) → sentry? dsn : string?
sampler : (-> (or/c event? transaction?) (real-in 0.0 1.0)) = (lambda (_) 1.0) backlog : exact-positive-integer? = 128
release : (or/c #f non-empty-string?) = (getenv "SENTRY_RELEASE")
environment : (or/c #f non-empty-string?) = (getenv "SENTRY_ENVIRONMENT") connect-timeout : exact-positive-integer? = 5000 send-timeout : exact-positive-integer? = 5000 max-breadcrumbs : exact-positive-integer? = 50
The #:backlog argument controls the size of the error queue. Events are dropped when the queue is full.
When the #:release argument is set, every event is tagged with the given value. Ditto for the #:environment argument.
The reutrned client logs messages to the 'sentry topic.
The #:sampler argument determines what chance an event has to be sent to the server. The default implementation samples 100% of all events.
Changed in version 0.5 of package sentry-lib: Added the #:sampler argument.
procedure
(sentry-capture-exception! e [ client #:level level #:timestamp timestamp #:server-name server-name #:environment environment #:release release #:request request #:tags tags #:user user]) → (evt/c void?) e : exn? client : (or/c #f sentry?) = (current-sentry) level : (or/c 'fatal 'error 'warning 'info 'debug) = 'error timestamp : (or/c date*? moment?) = (current-utc-date) server-name : (or/c #f non-empty-string?) = #f environment : (or/c #f non-empty-string?) = #f release : (or/c #f non-empty-string?) = #f request : (or/c #f request?) = #f tags : (hash/c non-empty-string? string?) = (hash) user : sentry-user? = (current-sentry-user)
procedure
(sentry-stop [client]) → void?
client : sentry? = (current-sentry)
3.2 Users
procedure
(sentry-user? v) → boolean?
v : any/c
parameter
(current-sentry-user) → (or/c #f sentry-user?)
(current-sentry-user user) → void? user : (or/c #f sentry-user?)
procedure
(make-sentry-user #:id id [ #:username username #:email email #:ip-address ip-address #:subscription subscription]) → sentry-user? id : non-empty-string? username : (or/c #f non-empty-string?) = #f email : (or/c #f non-empty-string?) = #f ip-address : (or/c #f non-empty-string?) = #f subscription : (or/c #f non-empty-string?) = #f
3.3 Tracing
(require sentry/tracing) | package: sentry-lib |
A transaction tracks a set of spans and delivers them to Sentry when the transaction completes. A span measures and records information about a block of code.
procedure
(transaction? v) → boolean?
v : any/c
parameter
(current-transaction) → (or/c #f transaction?)
(current-transaction t) → void? t : (or/c #f transaction?)
procedure
(call-with-transaction name proc [ #:data data #:source source #:trace-id trace-id #:parent-id parent-id #:operation operation #:description description]) → any name : string? proc : (-> transaction? any) data : (or/c #f (hash/c symbol? jsexpr?)) = #f source : symbol? = 'custom trace-id : (or/c #f string?) = #f parent-id : (or/c #f string?) = #f operation : symbol? = 'function description : (or/c #f string?) = #f
The value passed to the name argument should follow the conventions defined for the value passed to the #:source argument. The supported #:source values can be found in Sentry’s Transaction Annotations documentation.
The #:trace-id and #:parent-id may be used to propagate distributed tracing ids to the new transaction. See Sentry’s documentation on the sentry-trace header for details. If not provided, and the call is nested within another transaction, then the parent transaction’s values are inherited. If there is no parent transaction, then new trace and span ids are generated automatically.
The #:operation should be one of the values listed in Sentry’s Span Operations documentation.
The #:description may be an arbitrary string describing the transaction in detail.
parameter
(current-span) → (or/c #f span?)
(current-span s) → void? s : (or/c #f span?)
procedure
(call-with-span proc [ #:operation operation #:description description #:origin origin #:data data]) → any proc : (-> span? any) operation : symbol? = 'function description : (or/c #f string?) = #f origin : symbol? = 'manual data : (or/c #f (hash/c symbol? jsexpr?)) = #f
The #:operation should be one of the values listed in Sentry’s Span Operations documentation.
The #:description may be an arbitrary string describing the operation in detail.
procedure
(get-span-id v) → string?
v : (or/c span? transaction?)
procedure
(get-trace-id v) → string?
v : (or/c span? transaction?)
3.3.1 Database Queries
procedure
(trace-connection c) → connection?
c : connection?