// Search spans returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.SpansListRequest{
Data: &datadogV2.SpansListRequestData{
Attributes: &datadogV2.SpansListRequestAttributes{
Filter: &datadogV2.SpansQueryFilter{
From: datadog.PtrString("now-15m"),
Query: datadog.PtrString("*"),
To: datadog.PtrString("now"),
},
Options: &datadogV2.SpansQueryOptions{
Timezone: datadog.PtrString("GMT"),
},
Page: &datadogV2.SpansListRequestPage{
Limit: datadog.PtrInt32(25),
},
Sort: datadogV2.SPANSSORT_TIMESTAMP_ASCENDING.Ptr(),
},
Type: datadogV2.SPANSLISTREQUESTTYPE_SEARCH_REQUEST.Ptr(),
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewSpansApi(apiClient)
resp, r, err := api.ListSpans(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `SpansApi.ListSpans`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `SpansApi.ListSpans`:\n%s\n", responseContent)
}