DataDog / browser-sdk

Datadog Browser SDK
Apache License 2.0
291 stars 130 forks source link

Has DataDog logger been successfully initialized / has a valid API token? #2611

Open monsieurnebo opened 6 months ago

monsieurnebo commented 6 months ago

Hello,

Context

While implementing the DataDog logger (@datadog/browser-logs), I'm trying to make sure that it has been successfully initialized with a valid API token.

What I tried

From my understanding:

The only way of getting the info seems to be the failing logging query resulting of a wrong token... Which is not really helping me.

The question

Did I miss something in the doc & issues regarding this topic? Is there a way of getting this information?

If not, wouldn't it be useful to provide this info somehow? What do you think?

amortemousque commented 6 months ago

Hello @monsieurnebo, On the client side the browser SDK only check if the clientToken is provided and if not display a console error: Client Token is not configured, we will not send any data. The client token validity is done on the backend side and if not valid the requests to the Datadog intake will fail with 403 status code. Can you elaborate on you context and what behaviours or APIs you are expecting?

monsieurnebo commented 6 months ago

Hello @amortemousque , thanks for your answer.

So there will be no initialization error if a clientToken is indeed passed but is invalid?

My "context" is to make sure that my production logger is up & running (including a valid token). I would expect a console error in this scenario, to avoid a silent failing logger (before calling a log method, straight at the init).

amortemousque commented 6 months ago

Hello @monsieurnebo, We understand that a console error could be more convenient than looking at the 403. We will keep it in mind. In the meantime, if you want to ensure that logs are still collected on your prod environment, you could create a monitor to alert you in case your ingested logs suddenly drop.

monsieurnebo commented 6 months ago

For instance, here is what Google Map is returning in such a case:

Google Maps JavaScript API error: InvalidKeyMapError
https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error

Something similar would be neat, making things explicit (without having to create some custom monitor for that).