@@ -1226,6 +1226,29 @@ impl<'a> AuthenticatedApi<'a> {
12261226 Ok ( rv)
12271227 }
12281228
1229+ /// Fetch organization events from the specified dataset
1230+ pub fn fetch_organization_events (
1231+ & self ,
1232+ org : & str ,
1233+ options : & FetchEventsOptions ,
1234+ ) -> ApiResult < Vec < LogEntry > > {
1235+ let params = options. to_query_params ( ) ;
1236+ let url = format ! (
1237+ "/organizations/{}/events/?{}" ,
1238+ PathArg ( org) ,
1239+ params. join( "&" )
1240+ ) ;
1241+
1242+ let resp = self . get ( & url) ?;
1243+
1244+ if resp. status ( ) == 404 {
1245+ return Err ( ApiErrorKind :: OrganizationNotFound . into ( ) ) ;
1246+ }
1247+
1248+ let logs_response: LogsResponse = resp. convert ( ) ?;
1249+ Ok ( logs_response. data )
1250+ }
1251+
12291252 /// List all issues associated with an organization and a project
12301253 pub fn list_organization_project_issues (
12311254 & self ,
@@ -1390,6 +1413,71 @@ impl<'a> AuthenticatedApi<'a> {
13901413 }
13911414}
13921415
1416+ /// Available datasets for fetching organization events
1417+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
1418+ pub enum Dataset {
1419+ /// Our logs dataset
1420+ Logs ,
1421+ }
1422+
1423+ impl Dataset {
1424+ /// Returns the string representation of the dataset
1425+ fn as_str ( & self ) -> & ' static str {
1426+ match self {
1427+ Dataset :: Logs => "logs" ,
1428+ }
1429+ }
1430+ }
1431+
1432+ impl fmt:: Display for Dataset {
1433+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1434+ write ! ( f, "{}" , self . as_str( ) )
1435+ }
1436+ }
1437+
1438+ /// Options for fetching organization events
1439+ pub struct FetchEventsOptions < ' a > {
1440+ /// Dataset to fetch events from
1441+ pub dataset : Dataset ,
1442+ /// Fields to include in the response
1443+ pub fields : & ' a [ & ' a str ] ,
1444+ /// Project ID to filter events by
1445+ pub project_id : & ' a str ,
1446+ /// Cursor for pagination
1447+ pub cursor : Option < & ' a str > ,
1448+ /// Query string to filter events
1449+ pub query : & ' a str ,
1450+ /// Number of events per page
1451+ pub per_page : usize ,
1452+ /// Time period for stats
1453+ pub stats_period : & ' a str ,
1454+ /// Sort order
1455+ pub sort : & ' a str ,
1456+ }
1457+
1458+ impl < ' a > FetchEventsOptions < ' a > {
1459+ /// Generate query parameters as a vector of strings
1460+ pub fn to_query_params ( & self ) -> Vec < String > {
1461+ let mut params = vec ! [ format!( "dataset={}" , QueryArg ( self . dataset. as_str( ) ) ) ] ;
1462+
1463+ for field in self . fields {
1464+ params. push ( format ! ( "field={}" , QueryArg ( field) ) ) ;
1465+ }
1466+
1467+ if let Some ( cursor) = self . cursor {
1468+ params. push ( format ! ( "cursor={}" , QueryArg ( cursor) ) ) ;
1469+ }
1470+
1471+ params. push ( format ! ( "project={}" , QueryArg ( self . project_id) ) ) ;
1472+ params. push ( format ! ( "query={}" , QueryArg ( self . query) ) ) ;
1473+ params. push ( format ! ( "per_page={}" , self . per_page) ) ;
1474+ params. push ( format ! ( "statsPeriod={}" , QueryArg ( self . stats_period) ) ) ;
1475+ params. push ( format ! ( "sort={}" , QueryArg ( self . sort) ) ) ;
1476+
1477+ params
1478+ }
1479+ }
1480+
13931481impl RegionSpecificApi < ' _ > {
13941482 fn request ( & self , method : Method , url : & str ) -> ApiResult < ApiRequest > {
13951483 self . api
@@ -1609,8 +1697,6 @@ impl ApiRequest {
16091697 pipeline_env : Option < String > ,
16101698 global_headers : Option < Vec < String > > ,
16111699 ) -> ApiResult < Self > {
1612- debug ! ( "request {} {}" , method, url) ;
1613-
16141700 let mut headers = curl:: easy:: List :: new ( ) ;
16151701 headers. append ( "Expect:" ) . ok ( ) ;
16161702
@@ -1740,7 +1826,6 @@ impl ApiRequest {
17401826 let body = self . body . as_deref ( ) ;
17411827 let ( status, headers) =
17421828 send_req ( & mut self . handle , out, body, self . progress_bar_mode . clone ( ) ) ?;
1743- debug ! ( "response status: {}" , status) ;
17441829 Ok ( ApiResponse {
17451830 status,
17461831 headers,
@@ -2343,7 +2428,7 @@ pub struct ProcessedEvent {
23432428 pub tags : Option < Vec < ProcessedEventTag > > ,
23442429}
23452430
2346- #[ derive( Clone , Debug , Deserialize ) ]
2431+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
23472432pub struct ProcessedEventUser {
23482433 #[ serde( skip_serializing_if = "Option::is_none" ) ]
23492434 pub id : Option < String > ,
@@ -2377,7 +2462,7 @@ impl fmt::Display for ProcessedEventUser {
23772462 }
23782463}
23792464
2380- #[ derive( Clone , Debug , Deserialize ) ]
2465+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
23812466pub struct ProcessedEventTag {
23822467 pub key : String ,
23832468 pub value : String ,
@@ -2401,3 +2486,20 @@ pub struct Region {
24012486pub struct RegionResponse {
24022487 pub regions : Vec < Region > ,
24032488}
2489+
2490+ /// Response structure for logs API
2491+ #[ derive( Debug , Deserialize ) ]
2492+ struct LogsResponse {
2493+ data : Vec < LogEntry > ,
2494+ }
2495+
2496+ /// Log entry structure from the logs API
2497+ #[ derive( Debug , Deserialize ) ]
2498+ pub struct LogEntry {
2499+ #[ serde( rename = "sentry.item_id" ) ]
2500+ pub item_id : String ,
2501+ pub trace : Option < String > ,
2502+ pub severity : Option < String > ,
2503+ pub timestamp : String ,
2504+ pub message : Option < String > ,
2505+ }
0 commit comments