Skip to content

fix: block forbidden chars from metric names #460

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

Closed
wants to merge 1 commit into from
Closed

fix: block forbidden chars from metric names #460

wants to merge 1 commit into from

Conversation

dotkas
Copy link

@dotkas dotkas commented Jan 10, 2024

What does this PR do?

Block calling metric functions with names that will cause datadog-agent to fail.

Motivation

I should probably have known better, but it took me a merged PR all the way to prod and an error message in DataDog Serverless before I realized my code didn't work, and a clone of datadog-agent Go code to realize what I'd messed up. So I figured this could help other people.

Testing Guidelines

I added a new Jest case.

Additional Notes

I guess this is technically a breaking change. But if anybody would be affected by it we'd really be doing them a favor here as they would still have errors in their logs, only further down the pipeline. 🤷🏻

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@dotkas dotkas requested a review from a team as a code owner January 10, 2024 11:23
Copy link
Contributor

@astuyve astuyve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks so much for taking the time to write this PR up! I'm sorry that you ran into this metric naming issue.
This is a good PR, technically well written, conforms with our conventions, and includes good tests. I appreciate your hard work!

I'm not sure if this something we'd merge at this time, but I'm open to other feedback from additional users and we can revisit this conclusion in the future.

My reasoning is that we do document the format of metric names both implicitly in our lambda examples and explicitly in the datadog metric documentation.

If we did choose to validate the format in the Lambda function itself, we'd prefer to implement it in the Datadog Lambda extension, as this would benefit all users across all runtimes (not just nodejs). That also allows us to change the format in one place if that is ever needed in the future.

Finally this implementation does throw an unhandled exception when an invalid metric name is sent, which we wouldn't want to do as it would crash the running Lambda function.

We can leave this PR in an open state for now and see if other users would like this feature, but I don't intend to merge it at this time.

Thanks again!

@@ -255,6 +260,14 @@ export function extractArgs<TEvent>(isResponseStreamFunction: boolean, ...args:
* @param tags The tags associated with the metric. Should be of the format "tag:value".
*/
export function sendDistributionMetricWithDate(name: string, value: number, metricTime: Date, ...tags: string[]) {
if (FORBIDDEN_METRIC_NAME_CHARS.some((c) => name.includes(c))) {
throw new MalformedMetricName(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would cause the customer's lambda function to crash, which I don't think we'd want to do at any point

@astuyve astuyve added the wontfix This will not be worked on label Jan 23, 2024
@dotkas
Copy link
Author

dotkas commented Jan 23, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants