DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
609 stars 302 forks source link

Issues using the api.Logs.list #701

Closed PeterX41 closed 2 years ago

PeterX41 commented 2 years ago

Hello everyone, I have some issues, using the api.Logs.list.

def get_query_output(search_query):

    search_query = search_query
    dataALL = ''
    import datetime
    date_hour_actual = datetime.datetime.strftime(datetime.datetime.today(), "%Y-%m-%dT%H:%M:00Z")
    date_hour_yesterday = datetime.datetime.strftime(datetime.datetime.today() - datetime.timedelta(days=1), "%Y-%m-%dT%H:%M:00Z")   

    nextLogId = None

    while True:
               resp = api.Logs.list({
               'time': {
                   "from": date_hour_yesterday,
                   "to": date_hour_actual
               },              
               'query': search_query,
               'startAt': nextLogId,
               'limit': 1000,}) 
               nextLogId = resp['nextLogId']
               for i in range(0, len(resp['logs'])):                
                   #print(resp['logs'][i]['content'])                   
                   dataALL = dataALL + json.dumps(resp['logs'][i]['content'],default=str)

               if nextLogId == None:
                  break

    return dataALL

I have the above function that works great with querys like this:

resp_SalesOrderConfirmRequested = get_query_output('@trips.eventType:SalesOrderConfirmRequested application:sales-order-
print(resp_SalesOrderConfirmRequested)

but if I try and query like this, fails:

resp_trips-nsk-error = get_query_output('service:trips-booking-nsk-connector')  
print(resp_trips-nsk-error)

How can I do "service" querys?

Thanks in advance for any help.

therve commented 2 years ago

Hi. I believe service is a facet so you need to prefix it with @ like get_query_output('@service:trips-booking-nsk-connector').

This seems unrelated to datadogpy though, please raise future logs issues with support. Thank you.