Sentry 開發(fā)者貢獻指南 - Web API
Sentry API 用于向 Sentry collector 提交事件以及導出和管理數(shù)據(jù)。本文檔僅涉及 Web API。
版本控制
Web API 的當前版本稱為 v0,被認為處于草稿階段。
身份驗證
Auth Tokens
身份驗證令牌使用 auth 頭傳遞,并用于通過 API 以用戶或組織帳戶身份進行身份驗證。在我們的文檔中,我們有幾個出現(xiàn)在花括號或 V 形之間的占位符,例如 {API_KEY} 或
例如,當文檔顯示:
- curl -H 'Authorization: Bearer {TOKEN}' https://sentry.io/api/0/projects/
如果您的身份驗證令牌是 1a2b3c,那么命令應該是:
- curl -H 'Authorization: Bearer 1a2b3c' https://sentry.io/api/0/projects/
您可以通過創(chuàng)建一個內部集成在 Sentry 中創(chuàng)建身份驗證令牌。這也適用于自托管的 Sentry。
https://docs.sentry.io/product/integrations/integration-platform/#internal-integrations
DSN Authentication
某些 API 端點可能允許基于 DSN 的身份驗證。這通常非常有限,并且端點將描述其是否受支持。這與 Bearer token 身份驗證類似,但使用您的 DSN(Client Key)。
- curl -H 'Authorization: DSN {DSN}' https://sentry.io/api/0/projects/
API Keys
API keys 是一種傳統(tǒng)的身份驗證方法。它們仍然會被支持,但對于新帳戶是禁用的。您應該盡可能使用 authentication tokens。
API keys 使用 HTTP Basic auth 傳遞,其中用戶名是您的 api key,密碼是空值。
例如,要獲取有關您的 key 綁定到的項目的信息,您可以做出如下請求:
- curl -u {API_KEY}: https://sentry.io/api/0/projects/
您必須為密碼傳遞一個值,這就是我們示例中出現(xiàn) : 的原因。
分頁結果
API 中的分頁是通過 Link 頭標準處理的:
- curl -i https://sentry.io/api/0/projects/1/groups/
- HTTP/1.0 200 OK
- Date: Sat, 14 Feb 2015 18:47:20 GMT
- Content-Type: application/json
- Content-Language: en
- Allow: GET, HEAD, OPTIONS
- Link: <https://sentry.io/api/0/projects/1/groups/?&cursor=1420837590:0:1>;
- rel="previous"; results="false",
- <https://sentry.io/api/0/projects/1/groups/?&cursor=1420837533:0:0>;
- rel="next"; results="true"
HTTP/1.0 200 OKDate: Sat, 14 Feb 2015 18:47:20 GMTContent-Type: application/jsonContent-Language: enAllow: GET, HEAD, OPTIONSLink:
如果受到支持,將始終為上一頁和下一頁返回游標,即使這些頁面上沒有結果也是如此。這允許您對 API 進行查詢以獲取尚未發(fā)現(xiàn)的結果。一個使用這個的例子是當你實現(xiàn)輪詢行為并且你想看看是否有任何新數(shù)據(jù)。我們返回 results="[true|false]" 指示符以確定您是否真的需要分頁。
分頁示例
以下是使用此 API 端點的分頁示例:
https://docs.sentry.io/api/events/list-an-issues-events/
此示例中的 HTTP 請求針對該問題返回 100 個事件,并在響應中包含以下 link 頭:
- <https://sentry.io/api/0/issues/123456/events/?&cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io/api/0/issues/123456/events/?&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"
link 響應中的一個 URL 具有 rel=next,表示下一個結果頁面。它也有 results=true,這意味著有更多的結果。
基于此,下一個請求是 GET
此請求將再次返回該問題的下 100 個事件,并帶有以下 link 頭:
- <https://sentry.io/api/0/issues/123456/events/?&cursor=0:0:1>; rel="previous"; results="true"; cursor="0:0:1", <https://sentry.io/api/0/issues/123456/events/?&cursor=0:200:0>; rel="next"; results="true"; cursor="0:200:0"
重復該過程,直到帶有 rel=next 的 URL 具有標志 results=false 以指示最后一頁。
cursor 的三個值是:游標標識符(整數(shù),通常為 0)、行 offset 和 is_prev(1 或 0)。
權限和范圍
如果你是建立在 Sentry 的 API 之上(例如使用 Auth Tokens),你將需要特定的作用域來訪問不同的 API 端點。
https://docs.sentry.io/api/auth/
要設置 integration token 的作用域,請從下拉菜單中選擇作用域。這些可以稍后編輯。
https://docs.sentry.io/product/integrations/integration-platform/#permissions
要設置 auth token 的作用域,請在創(chuàng)建 auth token 時選中必要的復選框。
https://sentry.io/api/
如果您正在尋找有關 membership 角色的信息,請訪問 membership 文檔。
https://docs.sentry.io/product/accounts/membership/
組織
項目
project:releases 范圍將允許您訪問 project 和 organization release 端點。API 文檔的 Releases 部分列出了可用的端點。
https://docs.sentry.io/api/releases/
團隊
成員
問題和事件
PUT/DELETE 方法僅適用于更新/刪除問題。Sentry 中的事件是不可變的,只能通過刪除整個問題來刪除。
版本
請注意,如果您使用 sentry-cli 來管理您的版本,您將需要一個也具有 org:read 范圍的 token。
請求
所有 API 請求都應該以 /api/0/ 前綴發(fā)出,并將返回 JSON 作為響應:
- curl -i https://sentry.io/api/0/
- HTTP/1.0 200 OK
- Date: Sat, 14 Feb 2015 18:47:20 GMT
- Content-Type: application/json
- Content-Language: en
- Allow: GET, HEAD, OPTIONS
- {"version": "0"}
HTTP/1.0 200 OKDate: Sat, 14 Feb 2015 18:47:20 GMTContent-Type: application/jsonContent-Language: enAllow: GET, HEAD, OPTIONS{"version": "0"}
HTTP 動詞
Sentry 試圖堅持使用適當?shù)?HTTP 動詞,但我們總是優(yōu)先考慮可用性而不是正確性。
參數(shù)和數(shù)據(jù)
URL 中未包含的任何參數(shù)都應編碼為 JSON,其 Content-Type 為 'application/json':
- curl -i https://sentry.io/api/0/projects/1/groups/ \
- -d '{"status": "resolved"}' \
- -H 'Content-Type: application/json'
有時通過查詢字符串指定附加參數(shù),即使是 POST、PUT 和 DELETE 請求:
- curl -i https://sentry.io/api/0/projects/1/groups/?status=unresolved \
- -d '{"status": "resolved"}' \
- -H 'Content-Type: application/json'