dynatrace-oss / api-client-python

Dynatrace API Python client
Apache License 2.0
57 stars 22 forks source link

ValueError: 'xxx' is not a valid Category from dt.audit_logs.list() #89

Open JosephHobbs opened 1 week ago

JosephHobbs commented 1 week ago

Describe the bug

When calling dt.audit_logs.list() I'm seeing sporadic errors in my logs. The errors I see are ValueError exceptions complaining that specific values are not a valid Category. I am seeing this exception for ACTIVEGATE_TOKEN, ACTIVE_GATE, AGENT, COMPONENT and MANUAL_TAGGING_SERVICE (so far).

Here is an example of the raw exception for your reference:

[ERROR] ValueError: 'MANUAL_TAGGING_SERVICE' is not a valid Category
Traceback (most recent call last):
  File "/var/task/collect_audit_events.py", line 39, in lambda_handler
    events = dt.audit_logs.list(
  File "/opt/python/dynatrace/environment_v2/audit_logs.py", line 41, in list
    return PaginatedList(
  File "/opt/python/dynatrace/pagination.py", line 37, in __init__
    self.__elements = self._get_next_page()
  File "/opt/python/dynatrace/pagination.py", line 68, in _get_next_page
    data = [self.__target_class(self.__http_client, response.headers, element) for element in elements]
  File "/opt/python/dynatrace/pagination.py", line 68, in <listcomp>
    data = [self.__target_class(self.__http_client, response.headers, element) for element in elements]
  File "/opt/python/dynatrace/dynatrace_object.py", line 35, in __init__
    self._create_from_raw_data(raw_element)
  File "/opt/python/dynatrace/environment_v2/audit_logs.py", line 83, in _create_from_raw_data
    self.category: Category = Category(raw_element.get("category"))
  File "/var/lang/lib/python3.10/enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "/var/lang/lib/python3.10/enum.py", line 710, in __new__
    raise ve_exc

My assumption here is that additional categories have been added to Dynatrace (SaaS), but the API has not been updated (yet) to include them...

JosephHobbs commented 1 week ago

Looking at the Dynatrace API docs, it looks like not all of these are included as valid even though the tenant is returning them...

image

Dynatrace-James-Kitson commented 1 week ago

The latest docs didn't just add some possible values for category it looks like the majority of them were changed or are different, only 'TOKEN' and 'WEB_UI' are still present which is what the original list was.

I'll do some asking/checking to see if these values really are different as opposed to just being added. Either way, just adding these new ones might be the best 'backward compatible' way of doing it. There'd be no risk of supporting values that aren't coming in.