dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

Tracer fails to configure dbm using Typescript and dbmPropagationMode

Open victorkurauchi opened this issue 1 year ago • 2 comments

Expected behaviour

I should be able to connect the database monitoring following the docs for Nodejs: https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/?tab=nodejs

Actual behaviour

I get an error in typescript referring to dbmPropagationMode not existing in types

image

Looks like there's no type definition for pg plugin that should accept dbmPropagationMode ?

/**
   * This plugin automatically instruments the
   * [pg](https://node-postgres.com/) module.
   */
  interface pg extends Instrumentation {
    /**
     * The service name to be used for this plugin. If a function is used, it will be passed the connection parameters and its return value will be used as the service name.
     */
    service?: string | ((params: any) => string);
  }

Steps to reproduce

  • Install last version of dd-trace
  • Init your tracer
  • Use the config provided in the docs
tracer.use('pg', { dbmPropagationMode: 'full', service: 'my-db-service' });
  • See typescript erroring out Object literal may only specify known properties, and 'dbmPropagationMode' does not exist in type 'pg'

Environment

  • Operation system: macOS Ventura 13.2.1 (or linux with docker)
  • Node.js version: v18.16.1
  • Tracer version: "dd-trace": "^4.14.0"
  • Agent version: 7.44.1
  • Relevant library versions:

victorkurauchi avatar Sep 05 '23 05:09 victorkurauchi

I am getting a different error (dd-trace 4.11.1):

Argument of type '{ dbmPropagationMode: string; service: string; }' is not assignable to parameter of type 'boolean \| pg \| undefined'.

Using the sample code in the documentation:

tracer.use('pg', {
    dbmPropagationMode: 'full',
    service: 'service-name,
});

It does seem to accept it if you configure it this way though:

tracer.init({
    service: 'service-name',
    ...
    dbmPropagationMode: 'full'
});
tracer.use('pg', {
    service: 'service-name',
});

n2taylor avatar Nov 10 '23 15:11 n2taylor

@victorkurauchi can you submit a pull request?

tlhunter avatar Dec 18 '23 23:12 tlhunter