datadog_api_client/datadogV2/api/
api_logs_custom_destinations.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use crate::datadog;
5use flate2::{
6    write::{GzEncoder, ZlibEncoder},
7    Compression,
8};
9use reqwest::header::{HeaderMap, HeaderValue};
10use serde::{Deserialize, Serialize};
11use std::io::Write;
12
13/// CreateLogsCustomDestinationError is a struct for typed errors of method [`LogsCustomDestinationsAPI::create_logs_custom_destination`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateLogsCustomDestinationError {
17    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21/// DeleteLogsCustomDestinationError is a struct for typed errors of method [`LogsCustomDestinationsAPI::delete_logs_custom_destination`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum DeleteLogsCustomDestinationError {
25    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29/// GetLogsCustomDestinationError is a struct for typed errors of method [`LogsCustomDestinationsAPI::get_logs_custom_destination`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetLogsCustomDestinationError {
33    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// ListLogsCustomDestinationsError is a struct for typed errors of method [`LogsCustomDestinationsAPI::list_logs_custom_destinations`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum ListLogsCustomDestinationsError {
41    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// UpdateLogsCustomDestinationError is a struct for typed errors of method [`LogsCustomDestinationsAPI::update_logs_custom_destination`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum UpdateLogsCustomDestinationError {
49    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// Custom Destinations forward all the logs ingested to an external destination.
54///
55/// **Note**: Log forwarding is not available for the Government (US1-FED) site. Contact your account representative for more information.
56///
57/// See the [Custom Destinations Page](<https://app.datadoghq.com/logs/pipelines/log-forwarding/custom-destinations>)
58/// for a list of the custom destinations currently configured in web UI.
59#[derive(Debug, Clone)]
60pub struct LogsCustomDestinationsAPI {
61    config: datadog::Configuration,
62    client: reqwest_middleware::ClientWithMiddleware,
63}
64
65impl Default for LogsCustomDestinationsAPI {
66    fn default() -> Self {
67        Self::with_config(datadog::Configuration::default())
68    }
69}
70
71impl LogsCustomDestinationsAPI {
72    pub fn new() -> Self {
73        Self::default()
74    }
75    pub fn with_config(config: datadog::Configuration) -> Self {
76        let mut reqwest_client_builder = reqwest::Client::builder();
77
78        if let Some(proxy_url) = &config.proxy_url {
79            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
80            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
81        }
82
83        let mut middleware_client_builder =
84            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
85
86        if config.enable_retry {
87            struct RetryableStatus;
88            impl reqwest_retry::RetryableStrategy for RetryableStatus {
89                fn handle(
90                    &self,
91                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
92                ) -> Option<reqwest_retry::Retryable> {
93                    match res {
94                        Ok(success) => reqwest_retry::default_on_request_success(success),
95                        Err(_) => None,
96                    }
97                }
98            }
99            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
100                .build_with_max_retries(config.max_retries);
101
102            let retry_middleware =
103                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
104                    backoff_policy,
105                    RetryableStatus,
106                );
107
108            middleware_client_builder = middleware_client_builder.with(retry_middleware);
109        }
110
111        let client = middleware_client_builder.build();
112
113        Self { config, client }
114    }
115
116    pub fn with_client_and_config(
117        config: datadog::Configuration,
118        client: reqwest_middleware::ClientWithMiddleware,
119    ) -> Self {
120        Self { config, client }
121    }
122
123    /// Create a custom destination in your organization.
124    pub async fn create_logs_custom_destination(
125        &self,
126        body: crate::datadogV2::model::CustomDestinationCreateRequest,
127    ) -> Result<
128        crate::datadogV2::model::CustomDestinationResponse,
129        datadog::Error<CreateLogsCustomDestinationError>,
130    > {
131        match self
132            .create_logs_custom_destination_with_http_info(body)
133            .await
134        {
135            Ok(response_content) => {
136                if let Some(e) = response_content.entity {
137                    Ok(e)
138                } else {
139                    Err(datadog::Error::Serde(serde::de::Error::custom(
140                        "response content was None",
141                    )))
142                }
143            }
144            Err(err) => Err(err),
145        }
146    }
147
148    /// Create a custom destination in your organization.
149    pub async fn create_logs_custom_destination_with_http_info(
150        &self,
151        body: crate::datadogV2::model::CustomDestinationCreateRequest,
152    ) -> Result<
153        datadog::ResponseContent<crate::datadogV2::model::CustomDestinationResponse>,
154        datadog::Error<CreateLogsCustomDestinationError>,
155    > {
156        let local_configuration = &self.config;
157        let operation_id = "v2.create_logs_custom_destination";
158
159        let local_client = &self.client;
160
161        let local_uri_str = format!(
162            "{}/api/v2/logs/config/custom-destinations",
163            local_configuration.get_operation_host(operation_id)
164        );
165        let mut local_req_builder =
166            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
167
168        // build headers
169        let mut headers = HeaderMap::new();
170        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
171        headers.insert("Accept", HeaderValue::from_static("application/json"));
172
173        // build user agent
174        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
175            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
176            Err(e) => {
177                log::warn!("Failed to parse user agent header: {e}, falling back to default");
178                headers.insert(
179                    reqwest::header::USER_AGENT,
180                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
181                )
182            }
183        };
184
185        // build auth
186        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
187            headers.insert(
188                "DD-API-KEY",
189                HeaderValue::from_str(local_key.key.as_str())
190                    .expect("failed to parse DD-API-KEY header"),
191            );
192        };
193        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
194            headers.insert(
195                "DD-APPLICATION-KEY",
196                HeaderValue::from_str(local_key.key.as_str())
197                    .expect("failed to parse DD-APPLICATION-KEY header"),
198            );
199        };
200
201        // build body parameters
202        let output = Vec::new();
203        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
204        if body.serialize(&mut ser).is_ok() {
205            if let Some(content_encoding) = headers.get("Content-Encoding") {
206                match content_encoding.to_str().unwrap_or_default() {
207                    "gzip" => {
208                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
209                        let _ = enc.write_all(ser.into_inner().as_slice());
210                        match enc.finish() {
211                            Ok(buf) => {
212                                local_req_builder = local_req_builder.body(buf);
213                            }
214                            Err(e) => return Err(datadog::Error::Io(e)),
215                        }
216                    }
217                    "deflate" => {
218                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
219                        let _ = enc.write_all(ser.into_inner().as_slice());
220                        match enc.finish() {
221                            Ok(buf) => {
222                                local_req_builder = local_req_builder.body(buf);
223                            }
224                            Err(e) => return Err(datadog::Error::Io(e)),
225                        }
226                    }
227                    "zstd1" => {
228                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
229                        let _ = enc.write_all(ser.into_inner().as_slice());
230                        match enc.finish() {
231                            Ok(buf) => {
232                                local_req_builder = local_req_builder.body(buf);
233                            }
234                            Err(e) => return Err(datadog::Error::Io(e)),
235                        }
236                    }
237                    _ => {
238                        local_req_builder = local_req_builder.body(ser.into_inner());
239                    }
240                }
241            } else {
242                local_req_builder = local_req_builder.body(ser.into_inner());
243            }
244        }
245
246        local_req_builder = local_req_builder.headers(headers);
247        let local_req = local_req_builder.build()?;
248        log::debug!("request content: {:?}", local_req.body());
249        let local_resp = local_client.execute(local_req).await?;
250
251        let local_status = local_resp.status();
252        let local_content = local_resp.text().await?;
253        log::debug!("response content: {}", local_content);
254
255        if !local_status.is_client_error() && !local_status.is_server_error() {
256            match serde_json::from_str::<crate::datadogV2::model::CustomDestinationResponse>(
257                &local_content,
258            ) {
259                Ok(e) => {
260                    return Ok(datadog::ResponseContent {
261                        status: local_status,
262                        content: local_content,
263                        entity: Some(e),
264                    })
265                }
266                Err(e) => return Err(datadog::Error::Serde(e)),
267            };
268        } else {
269            let local_entity: Option<CreateLogsCustomDestinationError> =
270                serde_json::from_str(&local_content).ok();
271            let local_error = datadog::ResponseContent {
272                status: local_status,
273                content: local_content,
274                entity: local_entity,
275            };
276            Err(datadog::Error::ResponseError(local_error))
277        }
278    }
279
280    /// Delete a specific custom destination in your organization.
281    pub async fn delete_logs_custom_destination(
282        &self,
283        custom_destination_id: String,
284    ) -> Result<(), datadog::Error<DeleteLogsCustomDestinationError>> {
285        match self
286            .delete_logs_custom_destination_with_http_info(custom_destination_id)
287            .await
288        {
289            Ok(_) => Ok(()),
290            Err(err) => Err(err),
291        }
292    }
293
294    /// Delete a specific custom destination in your organization.
295    pub async fn delete_logs_custom_destination_with_http_info(
296        &self,
297        custom_destination_id: String,
298    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteLogsCustomDestinationError>>
299    {
300        let local_configuration = &self.config;
301        let operation_id = "v2.delete_logs_custom_destination";
302
303        let local_client = &self.client;
304
305        let local_uri_str = format!(
306            "{}/api/v2/logs/config/custom-destinations/{custom_destination_id}",
307            local_configuration.get_operation_host(operation_id),
308            custom_destination_id = datadog::urlencode(custom_destination_id)
309        );
310        let mut local_req_builder =
311            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
312
313        // build headers
314        let mut headers = HeaderMap::new();
315        headers.insert("Accept", HeaderValue::from_static("*/*"));
316
317        // build user agent
318        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
319            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
320            Err(e) => {
321                log::warn!("Failed to parse user agent header: {e}, falling back to default");
322                headers.insert(
323                    reqwest::header::USER_AGENT,
324                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
325                )
326            }
327        };
328
329        // build auth
330        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
331            headers.insert(
332                "DD-API-KEY",
333                HeaderValue::from_str(local_key.key.as_str())
334                    .expect("failed to parse DD-API-KEY header"),
335            );
336        };
337        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
338            headers.insert(
339                "DD-APPLICATION-KEY",
340                HeaderValue::from_str(local_key.key.as_str())
341                    .expect("failed to parse DD-APPLICATION-KEY header"),
342            );
343        };
344
345        local_req_builder = local_req_builder.headers(headers);
346        let local_req = local_req_builder.build()?;
347        log::debug!("request content: {:?}", local_req.body());
348        let local_resp = local_client.execute(local_req).await?;
349
350        let local_status = local_resp.status();
351        let local_content = local_resp.text().await?;
352        log::debug!("response content: {}", local_content);
353
354        if !local_status.is_client_error() && !local_status.is_server_error() {
355            Ok(datadog::ResponseContent {
356                status: local_status,
357                content: local_content,
358                entity: None,
359            })
360        } else {
361            let local_entity: Option<DeleteLogsCustomDestinationError> =
362                serde_json::from_str(&local_content).ok();
363            let local_error = datadog::ResponseContent {
364                status: local_status,
365                content: local_content,
366                entity: local_entity,
367            };
368            Err(datadog::Error::ResponseError(local_error))
369        }
370    }
371
372    /// Get a specific custom destination in your organization.
373    pub async fn get_logs_custom_destination(
374        &self,
375        custom_destination_id: String,
376    ) -> Result<
377        crate::datadogV2::model::CustomDestinationResponse,
378        datadog::Error<GetLogsCustomDestinationError>,
379    > {
380        match self
381            .get_logs_custom_destination_with_http_info(custom_destination_id)
382            .await
383        {
384            Ok(response_content) => {
385                if let Some(e) = response_content.entity {
386                    Ok(e)
387                } else {
388                    Err(datadog::Error::Serde(serde::de::Error::custom(
389                        "response content was None",
390                    )))
391                }
392            }
393            Err(err) => Err(err),
394        }
395    }
396
397    /// Get a specific custom destination in your organization.
398    pub async fn get_logs_custom_destination_with_http_info(
399        &self,
400        custom_destination_id: String,
401    ) -> Result<
402        datadog::ResponseContent<crate::datadogV2::model::CustomDestinationResponse>,
403        datadog::Error<GetLogsCustomDestinationError>,
404    > {
405        let local_configuration = &self.config;
406        let operation_id = "v2.get_logs_custom_destination";
407
408        let local_client = &self.client;
409
410        let local_uri_str = format!(
411            "{}/api/v2/logs/config/custom-destinations/{custom_destination_id}",
412            local_configuration.get_operation_host(operation_id),
413            custom_destination_id = datadog::urlencode(custom_destination_id)
414        );
415        let mut local_req_builder =
416            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
417
418        // build headers
419        let mut headers = HeaderMap::new();
420        headers.insert("Accept", HeaderValue::from_static("application/json"));
421
422        // build user agent
423        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
424            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
425            Err(e) => {
426                log::warn!("Failed to parse user agent header: {e}, falling back to default");
427                headers.insert(
428                    reqwest::header::USER_AGENT,
429                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
430                )
431            }
432        };
433
434        // build auth
435        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
436            headers.insert(
437                "DD-API-KEY",
438                HeaderValue::from_str(local_key.key.as_str())
439                    .expect("failed to parse DD-API-KEY header"),
440            );
441        };
442        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
443            headers.insert(
444                "DD-APPLICATION-KEY",
445                HeaderValue::from_str(local_key.key.as_str())
446                    .expect("failed to parse DD-APPLICATION-KEY header"),
447            );
448        };
449
450        local_req_builder = local_req_builder.headers(headers);
451        let local_req = local_req_builder.build()?;
452        log::debug!("request content: {:?}", local_req.body());
453        let local_resp = local_client.execute(local_req).await?;
454
455        let local_status = local_resp.status();
456        let local_content = local_resp.text().await?;
457        log::debug!("response content: {}", local_content);
458
459        if !local_status.is_client_error() && !local_status.is_server_error() {
460            match serde_json::from_str::<crate::datadogV2::model::CustomDestinationResponse>(
461                &local_content,
462            ) {
463                Ok(e) => {
464                    return Ok(datadog::ResponseContent {
465                        status: local_status,
466                        content: local_content,
467                        entity: Some(e),
468                    })
469                }
470                Err(e) => return Err(datadog::Error::Serde(e)),
471            };
472        } else {
473            let local_entity: Option<GetLogsCustomDestinationError> =
474                serde_json::from_str(&local_content).ok();
475            let local_error = datadog::ResponseContent {
476                status: local_status,
477                content: local_content,
478                entity: local_entity,
479            };
480            Err(datadog::Error::ResponseError(local_error))
481        }
482    }
483
484    /// Get the list of configured custom destinations in your organization with their definitions.
485    pub async fn list_logs_custom_destinations(
486        &self,
487    ) -> Result<
488        crate::datadogV2::model::CustomDestinationsResponse,
489        datadog::Error<ListLogsCustomDestinationsError>,
490    > {
491        match self.list_logs_custom_destinations_with_http_info().await {
492            Ok(response_content) => {
493                if let Some(e) = response_content.entity {
494                    Ok(e)
495                } else {
496                    Err(datadog::Error::Serde(serde::de::Error::custom(
497                        "response content was None",
498                    )))
499                }
500            }
501            Err(err) => Err(err),
502        }
503    }
504
505    /// Get the list of configured custom destinations in your organization with their definitions.
506    pub async fn list_logs_custom_destinations_with_http_info(
507        &self,
508    ) -> Result<
509        datadog::ResponseContent<crate::datadogV2::model::CustomDestinationsResponse>,
510        datadog::Error<ListLogsCustomDestinationsError>,
511    > {
512        let local_configuration = &self.config;
513        let operation_id = "v2.list_logs_custom_destinations";
514
515        let local_client = &self.client;
516
517        let local_uri_str = format!(
518            "{}/api/v2/logs/config/custom-destinations",
519            local_configuration.get_operation_host(operation_id)
520        );
521        let mut local_req_builder =
522            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
523
524        // build headers
525        let mut headers = HeaderMap::new();
526        headers.insert("Accept", HeaderValue::from_static("application/json"));
527
528        // build user agent
529        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
530            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
531            Err(e) => {
532                log::warn!("Failed to parse user agent header: {e}, falling back to default");
533                headers.insert(
534                    reqwest::header::USER_AGENT,
535                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
536                )
537            }
538        };
539
540        // build auth
541        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
542            headers.insert(
543                "DD-API-KEY",
544                HeaderValue::from_str(local_key.key.as_str())
545                    .expect("failed to parse DD-API-KEY header"),
546            );
547        };
548        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
549            headers.insert(
550                "DD-APPLICATION-KEY",
551                HeaderValue::from_str(local_key.key.as_str())
552                    .expect("failed to parse DD-APPLICATION-KEY header"),
553            );
554        };
555
556        local_req_builder = local_req_builder.headers(headers);
557        let local_req = local_req_builder.build()?;
558        log::debug!("request content: {:?}", local_req.body());
559        let local_resp = local_client.execute(local_req).await?;
560
561        let local_status = local_resp.status();
562        let local_content = local_resp.text().await?;
563        log::debug!("response content: {}", local_content);
564
565        if !local_status.is_client_error() && !local_status.is_server_error() {
566            match serde_json::from_str::<crate::datadogV2::model::CustomDestinationsResponse>(
567                &local_content,
568            ) {
569                Ok(e) => {
570                    return Ok(datadog::ResponseContent {
571                        status: local_status,
572                        content: local_content,
573                        entity: Some(e),
574                    })
575                }
576                Err(e) => return Err(datadog::Error::Serde(e)),
577            };
578        } else {
579            let local_entity: Option<ListLogsCustomDestinationsError> =
580                serde_json::from_str(&local_content).ok();
581            let local_error = datadog::ResponseContent {
582                status: local_status,
583                content: local_content,
584                entity: local_entity,
585            };
586            Err(datadog::Error::ResponseError(local_error))
587        }
588    }
589
590    /// Update the given fields of a specific custom destination in your organization.
591    pub async fn update_logs_custom_destination(
592        &self,
593        custom_destination_id: String,
594        body: crate::datadogV2::model::CustomDestinationUpdateRequest,
595    ) -> Result<
596        crate::datadogV2::model::CustomDestinationResponse,
597        datadog::Error<UpdateLogsCustomDestinationError>,
598    > {
599        match self
600            .update_logs_custom_destination_with_http_info(custom_destination_id, body)
601            .await
602        {
603            Ok(response_content) => {
604                if let Some(e) = response_content.entity {
605                    Ok(e)
606                } else {
607                    Err(datadog::Error::Serde(serde::de::Error::custom(
608                        "response content was None",
609                    )))
610                }
611            }
612            Err(err) => Err(err),
613        }
614    }
615
616    /// Update the given fields of a specific custom destination in your organization.
617    pub async fn update_logs_custom_destination_with_http_info(
618        &self,
619        custom_destination_id: String,
620        body: crate::datadogV2::model::CustomDestinationUpdateRequest,
621    ) -> Result<
622        datadog::ResponseContent<crate::datadogV2::model::CustomDestinationResponse>,
623        datadog::Error<UpdateLogsCustomDestinationError>,
624    > {
625        let local_configuration = &self.config;
626        let operation_id = "v2.update_logs_custom_destination";
627
628        let local_client = &self.client;
629
630        let local_uri_str = format!(
631            "{}/api/v2/logs/config/custom-destinations/{custom_destination_id}",
632            local_configuration.get_operation_host(operation_id),
633            custom_destination_id = datadog::urlencode(custom_destination_id)
634        );
635        let mut local_req_builder =
636            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
637
638        // build headers
639        let mut headers = HeaderMap::new();
640        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
641        headers.insert("Accept", HeaderValue::from_static("application/json"));
642
643        // build user agent
644        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
645            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
646            Err(e) => {
647                log::warn!("Failed to parse user agent header: {e}, falling back to default");
648                headers.insert(
649                    reqwest::header::USER_AGENT,
650                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
651                )
652            }
653        };
654
655        // build auth
656        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
657            headers.insert(
658                "DD-API-KEY",
659                HeaderValue::from_str(local_key.key.as_str())
660                    .expect("failed to parse DD-API-KEY header"),
661            );
662        };
663        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
664            headers.insert(
665                "DD-APPLICATION-KEY",
666                HeaderValue::from_str(local_key.key.as_str())
667                    .expect("failed to parse DD-APPLICATION-KEY header"),
668            );
669        };
670
671        // build body parameters
672        let output = Vec::new();
673        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
674        if body.serialize(&mut ser).is_ok() {
675            if let Some(content_encoding) = headers.get("Content-Encoding") {
676                match content_encoding.to_str().unwrap_or_default() {
677                    "gzip" => {
678                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
679                        let _ = enc.write_all(ser.into_inner().as_slice());
680                        match enc.finish() {
681                            Ok(buf) => {
682                                local_req_builder = local_req_builder.body(buf);
683                            }
684                            Err(e) => return Err(datadog::Error::Io(e)),
685                        }
686                    }
687                    "deflate" => {
688                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
689                        let _ = enc.write_all(ser.into_inner().as_slice());
690                        match enc.finish() {
691                            Ok(buf) => {
692                                local_req_builder = local_req_builder.body(buf);
693                            }
694                            Err(e) => return Err(datadog::Error::Io(e)),
695                        }
696                    }
697                    "zstd1" => {
698                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
699                        let _ = enc.write_all(ser.into_inner().as_slice());
700                        match enc.finish() {
701                            Ok(buf) => {
702                                local_req_builder = local_req_builder.body(buf);
703                            }
704                            Err(e) => return Err(datadog::Error::Io(e)),
705                        }
706                    }
707                    _ => {
708                        local_req_builder = local_req_builder.body(ser.into_inner());
709                    }
710                }
711            } else {
712                local_req_builder = local_req_builder.body(ser.into_inner());
713            }
714        }
715
716        local_req_builder = local_req_builder.headers(headers);
717        let local_req = local_req_builder.build()?;
718        log::debug!("request content: {:?}", local_req.body());
719        let local_resp = local_client.execute(local_req).await?;
720
721        let local_status = local_resp.status();
722        let local_content = local_resp.text().await?;
723        log::debug!("response content: {}", local_content);
724
725        if !local_status.is_client_error() && !local_status.is_server_error() {
726            match serde_json::from_str::<crate::datadogV2::model::CustomDestinationResponse>(
727                &local_content,
728            ) {
729                Ok(e) => {
730                    return Ok(datadog::ResponseContent {
731                        status: local_status,
732                        content: local_content,
733                        entity: Some(e),
734                    })
735                }
736                Err(e) => return Err(datadog::Error::Serde(e)),
737            };
738        } else {
739            let local_entity: Option<UpdateLogsCustomDestinationError> =
740                serde_json::from_str(&local_content).ok();
741            let local_error = datadog::ResponseContent {
742                status: local_status,
743                content: local_content,
744                entity: local_entity,
745            };
746            Err(datadog::Error::ResponseError(local_error))
747        }
748    }
749}