dd-sdk-android icon indicating copy to clipboard operation
dd-sdk-android copied to clipboard

Validate API TOKEN

Open lgvalle opened this issue 2 years ago • 3 comments

Are you requesting automatic instrumentation for a framework or library? Please describe. using library dd-sdk-android:1.17.2

Is your feature request related to a problem? Please describe. Yes, if the datadog Android SDK is initialised using a wrong Token there's no way to know other than events not appearing on Datadog Dashboard, which is a very manual and prone to errors process.

Describe the solution you'd like A function in the SDK to validate that the token passed to initialise it is correct. Something similar to the functionality of the existing API endpoint to validate API KEYs

Describe alternatives you've considered I've tried two options with no luck

  1. Use the validate-api-key endpoint linked above passing an API TOKEN
  2. Use the Datadog JVM dependency for unit tests in our Android app, since it does have a validate functionality

In both cases, I received the same 403 error and I believe it's because API TOKENS cannot be used against the validate-api-key endpoint

Thanks!

lgvalle avatar May 19 '23 09:05 lgvalle

Hello @lgvalle!

When token is invalid you should have an error in the logcat, given that you set logs verbosity using Datadog.setVerbosity call (by default no logs will be printed).

0xnm avatar May 19 '23 09:05 0xnm

Thanks @0xnm , that's totally true: you can see that error message in the logs. I want to achieve an automatic check that Datadog has been initialised correctly. Inspecting the logs requires a manual process. I'd like to be able to stop a production build on the CI if Datadog cannot be initialised.

The immediate solutions I can think of are: if the Datadog.initialize function would check the token validity as part of the initialisation process it'll be fantastic. Alternatively, a listener to hook into the upload function to receive upload results not only on the logs would be good too.

lgvalle avatar May 19 '23 10:05 lgvalle

Thank you for the suggestion, we will check what we can do indeed. Generally speaking, validating client setup is more complicated topic, because missing data in Datadog dashboards may be related not only to the wrong token/site usage, but also mistakes in the instrumentation setup itself.

Although we are trying to notify the user if there is something wrong in their setup as much as we can, there is definitely some room for the improvement.

0xnm avatar May 19 '23 11:05 0xnm