|
| 1 | +// Create rum segment returns "Segment created successfully" response |
| 2 | +use chrono::{DateTime, Utc}; |
| 3 | +use datadog_api_client::datadog; |
| 4 | +use datadog_api_client::datadogV2::api_segments::SegmentsAPI; |
| 5 | +use datadog_api_client::datadogV2::model::Segment; |
| 6 | +use datadog_api_client::datadogV2::model::SegmentData; |
| 7 | +use datadog_api_client::datadogV2::model::SegmentDataAttributes; |
| 8 | +use datadog_api_client::datadogV2::model::SegmentDataAttributesDataQuery; |
| 9 | +use datadog_api_client::datadogV2::model::SegmentDataAttributesDataQueryEventPlatformItems; |
| 10 | +use datadog_api_client::datadogV2::model::SegmentDataSource; |
| 11 | +use datadog_api_client::datadogV2::model::SegmentDataType; |
| 12 | + |
| 13 | +#[tokio::main] |
| 14 | +async fn main() { |
| 15 | + let body = Segment::new().data( |
| 16 | + SegmentData::new(SegmentDataType::SEGMENT) |
| 17 | + .attributes( |
| 18 | + SegmentDataAttributes::new( |
| 19 | + SegmentDataAttributesDataQuery::new().event_platform(vec![ |
| 20 | + SegmentDataAttributesDataQueryEventPlatformItems::new( |
| 21 | + "@usr.id".to_string(), |
| 22 | + ) |
| 23 | + .from("2025-08-01".to_string()) |
| 24 | + .name("high_value_users".to_string()) |
| 25 | + .query( |
| 26 | + "@type:view @view.name:/logs @usr.session_duration:>300000".to_string(), |
| 27 | + ) |
| 28 | + .to("2025-09-01".to_string()), |
| 29 | + ]), |
| 30 | + "High-Value Users".to_string(), |
| 31 | + ) |
| 32 | + .created_at( |
| 33 | + DateTime::parse_from_rfc3339("0001-01-01T00:00:00+00:00") |
| 34 | + .expect("Failed to parse datetime") |
| 35 | + .with_timezone(&Utc), |
| 36 | + ) |
| 37 | + .created_by(SegmentDataSource::new( |
| 38 | + "".to_string(), |
| 39 | + "".to_string(), |
| 40 | + "".to_string(), |
| 41 | + )) |
| 42 | + .description( |
| 43 | + "Users who frequently visit logs and have high session duration".to_string(), |
| 44 | + ) |
| 45 | + .modified_at( |
| 46 | + DateTime::parse_from_rfc3339("0001-01-01T00:00:00+00:00") |
| 47 | + .expect("Failed to parse datetime") |
| 48 | + .with_timezone(&Utc), |
| 49 | + ) |
| 50 | + .modified_by(SegmentDataSource::new( |
| 51 | + "".to_string(), |
| 52 | + "".to_string(), |
| 53 | + "".to_string(), |
| 54 | + )) |
| 55 | + .org_id(123456) |
| 56 | + .source(0) |
| 57 | + .tags(vec![ |
| 58 | + "high-value".to_string(), |
| 59 | + "logs".to_string(), |
| 60 | + "active".to_string(), |
| 61 | + ]) |
| 62 | + .version(1), |
| 63 | + ) |
| 64 | + .id("segment-12345".to_string()), |
| 65 | + ); |
| 66 | + let mut configuration = datadog::Configuration::new(); |
| 67 | + configuration.set_unstable_operation_enabled("v2.CreateRumSegment", true); |
| 68 | + let api = SegmentsAPI::with_config(configuration); |
| 69 | + let resp = api.create_rum_segment(body).await; |
| 70 | + if let Ok(value) = resp { |
| 71 | + println!("{:#?}", value); |
| 72 | + } else { |
| 73 | + println!("{:#?}", resp.unwrap_err()); |
| 74 | + } |
| 75 | +} |
0 commit comments