Module: Ask::Sentry
- Defined in:
- lib/ask/sentry/client.rb,
lib/ask/sentry/context.rb,
lib/ask/sentry/version.rb,
lib/ask/sentry/error_guide.rb
Defined Under Namespace
Modules: Errors Classes: ClientProxy
Constant Summary collapse
- DESCRIPTION =
Human-readable description of the Sentry service context.
"Sentry — error tracking via the Sentry API"- DOCS_URL =
Base URL for Sentry REST API documentation.
"https://docs.sentry.io/api/"- OPENAPI_URL =
URL for the Sentry OpenAPI specification.
"https://sentry.io/api/0/"- AUTH_NAME =
Credential name used with Ask::Auth.resolve.
:sentry_token- AUTH_HOW =
Instructions for obtaining a Sentry auth token.
"https://sentry.io/settings/account/api/auth-tokens/"- GEM_NAME =
Gem name for the HTTP client.
"faraday"- GEM_VERSION =
Required gem version constraint.
"~> 2.0"- GEM_DOCS =
URL for Faraday library documentation.
"https://lostisland.github.io/faraday"- QUICK_START =
Quick-start Ruby code snippet for agents to copy-paste.
<<~RUBY client = Ask::Sentry.client issues = client.get("/api/0/projects/ORG/PROJECT/issues/", limit: 10) # Or use the helper: Ask::Sentry.recent_errors(organization: "myorg", project: "myapp", limit: 10) RUBY
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.client ⇒ ClientProxy
Returns an authenticated Faraday client configured for the Sentry REST API.
-
.issue_events(issue_id, limit: 10) ⇒ Faraday::Response
Convenience wrapper to fetch events for a specific issue.
-
.recent_errors(organization:, project:, limit: 10) ⇒ Faraday::Response
Convenience wrapper to fetch recent errors for a given organization and project.
Class Method Details
.client ⇒ ClientProxy
Returns an authenticated Faraday client configured for the Sentry REST API.
Resolves the Sentry token via Ask::Auth.resolve(:sentry_token) and configures the client with sensible defaults:
-
base URL:
https://sentry.io/api/0/ -
Authorization: Bearer token -
middleware: Faraday retry middleware (3 retries, exponential backoff)
The client is wrapped in a ClientProxy that converts HTTP 401 responses into Ask::Auth::InvalidCredential.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ask/sentry/client.rb', line 28 def self.client token = Ask::Auth.resolve(:sentry_token) client = Faraday.new(url: "https://sentry.io/api/0/") do |f| f.request :authorization, :Bearer, token f.headers["Content-Type"] = "application/json" f.request :retry, max: 3, interval: 1, backoff_factor: 2, retry_statuses: [429, 500, 502, 503] f.adapter Faraday.default_adapter end ClientProxy.new(client) end |
.issue_events(issue_id, limit: 10) ⇒ Faraday::Response
Convenience wrapper to fetch events for a specific issue.
59 60 61 62 63 |
# File 'lib/ask/sentry/client.rb', line 59 def self.issue_events(issue_id, limit: 10) client.get("issues/#{issue_id}/events/") do |req| req.params[:limit] = limit end end |
.recent_errors(organization:, project:, limit: 10) ⇒ Faraday::Response
Convenience wrapper to fetch recent errors for a given organization and project.
48 49 50 51 52 |
# File 'lib/ask/sentry/client.rb', line 48 def self.recent_errors(organization:, project:, limit: 10) client.get("projects/#{organization}/#{project}/issues/") do |req| req.params[:limit] = limit end end |