Possible to run initialisation code?

  • I would like to integrate jsreport more into my DataDog setup. To do this I need to initialise the dd-trace library when jsreport starts. Adding the dependency to node_modules is easily done when building the Docker Image, which is based on jsreport/jsreport:2.5.0

    Is there any way to add code to the jsreport start script?

    I need to add this:
    const tracer = require('dd-trace').init()

    Or would I need to build a Node server of my own which incorporates the jsreport manually?

    More info here: https://docs.datadoghq.com/tracing/setup/nodejs/

  • administrators

    hi! the only way right now will be to define you dockerfile something like this:

    FROM jsreport/jsreport:2.5.0
    RUN npm install dd-trace
    COPY ./custom-server.js /app/server.js

    then the custom-server.js can include the following

    const tracer = require('dd-trace').init()
    const jsreport = require('./')({ rootDirectory: __dirname })
    if (process.env.JSREPORT_CLI) {
      module.exports = jsreport
    } else {
      jsreport.init().then(() => {
      }).catch((e) => {

    maybe in the future we can support declaring some env var in the dockerfile with the file(s) that should be required at the startup before initializing jsreport

  • Ok, thanks.
    I'd have to manually track possible future changes that you might make in server.js. I could just as well create a Node server of my own and integrate jsreport into this. I've thought about this anyway, as it would make it easier to implement custom file storage and other stuff. This might be a good reason to move on with that thought.

  • administrators

    yes, although it is very unlikely that we will change the initialization code, i get your point.

    let's see if we can add a simple way to run code at the startup, at least it will be good for simple cases, for more complex cases which requires more grained control the best is to do it yourself in your own server.

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.