DataDog / serverless-plugin-datadog

Serverless plugin to automagically instrument your Lambda functions with Datadog
Apache License 2.0
96 stars 49 forks source link

Loglevel set to error not working #541

Closed earlybirdeng closed 1 month ago

earlybirdeng commented 1 month ago

Expected Behavior

When i set the logLevel to error in the plugin it should only emit error logs to data dog

Actual Behavior

All my INFO logs are being sent to datadog.

Steps to Reproduce the Problem

custom:
  staged: ${self:custom.stageVars.${self:provider.stage}}
  stageVars:
    dev:
      dd_enabled: false
    prod:
      dd_enabled: true
  datadog:
    enabled: ${self:custom.staged.dd_enabled, true}
    apiKey: ${self:custom.datadog_api_key.key}
    site: us5.datadoghq.com
    logLevel: error
    enableXrayTracing: false
    enableDDTracing: false
    enableDDLogs: true
    subscribeToAccessLogs: true
    exclude:
      - dd-excluded-function

I even tried manually setting the env var

  environment:
    DATADOG_API_KEY: ${self:custom.datadog_api_key.key}
    DD_LOGS_INJECTION: true
    DD_LOG_LEVEL: error

Specifications

Stacktrace

  Paste here
lym953 commented 1 month ago

@earlybirdeng Could you clarify what INFO logs you are referring to? Do you mean your custom log?

earlybirdeng commented 1 month ago

I am testing with a nodejs lambda, I noticed that setting loglevel or not setting it will just send all logs (console.log, console.error, etc) to DD. I had expected if I set the loglevel to 'ERROR' that only the console.error logs I emit in my lambda will be sent.

lym953 commented 1 month ago

Thanks for the clarification!

DD_LOG_LEVEL only controls the log level of Datadog layers, and doesn't affect the whether custom logs are forwarded to Datadog. All your custom logs logged by console.log, console.error etc are forward to Datadog.

lym953 commented 1 month ago

I'm going to close this issue. Feel free to reopen it if you need further help.