Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I submit metrics with a client token? (instead of api_key+app_key) #54

Closed
aguynamedben opened this issue Jul 17, 2020 · 12 comments
Closed

Comments

@aguynamedben
Copy link

aguynamedben commented Jul 17, 2020

Hi, thanks for making this library available.

I'm building an Electron app and want to collect metrics from it. The Datadog RUM/logging systems support intake using a client token, which is a write-only credential for use in the web browser and apps where source code is comprisable.

Have you found a way with the metrics APIs to submit metrics using the client token? I'm poking around but the API keeps telling me I need an api_key. Thanks for any help you could provide on this.

@jaybe78
Copy link

jaybe78 commented Feb 4, 2022

Is that repository dead or still maintained ?
I'm also using a client token.

@Mr0grog
Copy link
Collaborator

Mr0grog commented Sep 19, 2022

Hi @aguynamedben and @jaybe78, are either of you still using this and is it still a pressing need? I’ve been making a few PRs to support a client who’s using this, and maintainers have been responsive to those changes.

If it’s still useful to you, I might take a look at whether this is possible (unless I miss my mark, the DataDog’s RUM packages use different APIs than this does, so I’m not totally sure a token will work without bigger changes) if I’ve got some extra time.

@Mr0grog
Copy link
Collaborator

Mr0grog commented Sep 23, 2022

I poked around at this a little, and there does not seem to be a way to use client tokens with the standard API (which we use to submit metrics) — only the RUM and browser logs (different from normal logs) APIs, which are hosted at entirely different domains and have different endpoints and parameters (e.g. RUM is at rum-browser-intake-datadoghq.com). Beyond that, it doesn’t look like there is any metrics support in the RUM API — you can generate metrics from your RUM actions and events, but not submit metrics directly.

(I also couldn’t find any technical documentation on these APIs and had to dig through the browser SDK source. If you know of any actual docs, please post here.)

Ultimately, it doesn’t seem like there’s a reasonable way to do this, so I’m going to close this issue. If you know more, please post here. Otherwise I recommend using DataDog’s official RUM packages if you really need client tokens.

@Mr0grog Mr0grog closed this as completed Sep 23, 2022
@Mr0grog Mr0grog closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2022
@aguynamedben
Copy link
Author

Not using it, thank you for asking

@jayshah123
Copy link

Moving to v2 Metrics API seems to support client tokens. Any plans to migrate the same?

@Mr0grog
Copy link
Collaborator

Mr0grog commented Nov 5, 2024

@jayshah123 do you have some example code that successfully submits metrics to the v2 API using client tokens? I just tried, and it does not work for me.

@jayshah123
Copy link

Yeah, actually plain submitMetrics works but submit distribution does not so probably not much we can do.

@jayshah123 do you have some example code that successfully submits metrics to the v2 API using client tokens? I just tried, and it does not work for me.

@Mr0grog
Copy link
Collaborator

Mr0grog commented Nov 6, 2024

actually plain submitMetrics works but submit distribution does not

I could not get plain submitMetrics to work. How are you calling it with a client token?

@jayshah123
Copy link

actually plain submitMetrics works but submit distribution does not

I could not get plain submitMetrics to work. How are you calling it with a client token?

Using this - https://docs.datadoghq.com/api/latest/metrics/#submit-metrics (typescript example)
I have personally tried sending distribution points (which failed with Auth error).
A friend of mine tried above which he reported it worked for gauge type.

@Mr0grog
Copy link
Collaborator

Mr0grog commented Nov 7, 2024

I have personally tried sending distribution points (which failed with Auth error).
A friend of mine tried above which he reported it worked for gauge type.

Are you sure your friend was using a client token and not an API key? How are they using the client token for auth? Are they just using it for the value of DD_API_KEY?

That is the API endpoint I tried, and using a client token in the same way you'd use an API key did not work for me. The docs don't discuss using a client token at all, so I'd love to know if there is a different way you are supposed to use it for auth.

@jayshah123
Copy link

Something like:

import { client, v2, v1 } from '@datadog/datadog-api-client';

class DatadogClient {
  private configuration = client.createConfiguration({
    authMethods: {
      apiKeyAuth: 'xxxCLIENT_TOKENxxx',
    },
  });
  private metricApiInstance: v2.MetricsApi;

  constructor() {
    this.metricApiInstance = new v2.MetricsApi(this.configuration);
  }

  /**
   * Submit metrics returns "Payload accepted" response
   */
  public async submitMetrics(payload: v2.MetricsApiSubmitMetricsRequest) {
    try {
      const response = await this.metricApiInstance.submitMetrics(payload);
      return response;
    } catch (error) {
    }
  }
}

export default DatadogClient;

@Mr0grog
Copy link
Collaborator

Mr0grog commented Nov 7, 2024

That code definitely does not work with a client token. Maybe the errors got silenced by your empty catch block and you misinterpreted the result?

    try {
      const response = await this.metricApiInstance.submitMetrics(payload);
      return response;
    } catch (error) {
    }

Anyway, it seems like this is not actually a thing, so there’s probably not much more to dig into here.

Separately, I would be kind of surprised if Datadog did ever make this work for metrics, since you can only submit one point per second per metric per host. It’s not a very good fit for a situation with lots of uncoordinated senders, which is probably the kind of situation you are in if you need client tokens. (Distributions or events are better for this use case, and that's probably why Datadog’s Lambda package is based on distributions and its RUM package is based on events. Neither uses metrics.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants