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

Lambd sendDistributionMetrics - datadog:handler not initialized #535

Closed
DanielScharfsteinGit opened this issue May 6, 2024 · 6 comments
Closed

Comments

@DanielScharfsteinGit
Copy link

Expected Behavior

Custom metrics should be added using the sendDistributionMetric function.

Actual Behavior

An error is encountered: {"status":"error","message":"datadog:handler not initialized"}.

Steps to Reproduce the Problem

  • I have a Lambda function that runs with the datadog Lambda Layers on Node 18.
  • The sendDistributionMetric is called during the runtime of the handler, after the init.
  • Tracer is working in the env
  • No webpack or any other module bundler.

Attempted Solutions

I reviewed the following issues on GitHub (#298, #209, #369), but was unable to resolve the issue.

Specifications

  • Node Layer Version: 96
  • Extension Layer Version: 47
  • Node Version: 18
@DanielScharfsteinGit DanielScharfsteinGit changed the title datadog:handler not initialized Lambd sendDistributionMetrics - datadog:handler not initialized May 6, 2024
@purple4reina
Copy link
Contributor

Hi @DanielScharfsteinGit, do you mind upgrading your version of datadog-lambda-js to the most recent (currently v8.108.0) and testing again? Support for your use case should be added in a more recent version.

@DanielScharfsteinGit
Copy link
Author

@purple4reina Hey! Im using the newest - 8.108.0 version.

Adding that I'm not using the datadog() function from the datadog-lambda-js package but only use the layer. When adding the datadog() it is working. But I looked online and saw examples of using the metrics without the need of the datadog().

@duncanista
Copy link
Contributor

Hey @DanielScharfsteinGit, could you share the example you are mentioning?

sendDistributionMetrics exported from this package, requires that datadog is used. Even though we allow to use it outside of the handler, usage of it is tied of our instrumentation knowing when to flush data, as datadog is never ran, our metrics processes never send that data.

@DanielScharfsteinGit
Copy link
Author

DanielScharfsteinGit commented May 10, 2024

Hello @duncanista,

On this page - https://docs.datadoghq.com/serverless/aws_lambda/metrics/#submit-custom-metrics, it appears that if you use the Datadog Lambda layer—which includes instrumentation and ensures tracing works—you might not need to directly invoke the datadog() function. My code snippet below, which sends custom metrics, is incorporated directly into the handler:

import { sendDistributionMetricWithDate } from 'datadog-lambda-js';

const testHandler = async (event: Event): Promise<void> => { sendDistributionMetricWithDate('example.metric', 1, new Date()); };

const handlerName = 'testHandler';

export const handler = middy(testHandler).use(logEvent(handlerName));

@duncanista
Copy link
Contributor

duncanista commented May 10, 2024

@DanielScharfsteinGit,

The instructions assume that you have Serverless Intrumentation set:

Install Serverless Monitoring for AWS Lambda and ensure that you have installed the Datadog Lambda extension.

Which, depending on your instrumentation of choice, most of them directly end up using the datadog wrapper. Like changing the code handler to the Datadog one, which ends up using that function under the hood. For example, custom instrumentation requires you to do it manually.

How are you instrumenting your AWS Lambda?

@duncanista
Copy link
Contributor

Hey,

I'm going to close this issue since there hasn't been a response in a week, and the underlying problem should be solved by instrumenting the AWS Lambda function – since the methods expect it to be eventually executed.

If there's any other questions/concerns, please feel free to re-open!

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

No branches or pull requests

3 participants