Skip to content

Turning on Instrumentation using ember-cli-dotenv #7429

Closed

Description

@patocallaghan

I'd like to enable the ember-cli instrumentation using the .env file from ember-cli-dotenv but it appears doing it that way sets the environment variable too late in the process. The init is set up here

let initInstrumentation;
if (instrumentation.instrumentationEnabled()) {
const heimdall = require('heimdalljs');
let initInstrumentationToken = heimdall.start('init');
initInstrumentation = {
token: initInstrumentationToken,
node: heimdall.current,
};
}
before the variable has been set. If I run ember server I get the following error

➜  instrumentation-dotenv git:(master) ember server
No such instrumentation "init"
Error: No such instrumentation "init"
    at Instrumentation._instrumentationFor (/Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/ember-cli/lib/models/instrumentation.js:171:13)
    at Instrumentation.stopAndReport (/Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/ember-cli/lib/models/instrumentation.js:227:22)
    at Promise.resolve.then (/Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/ember-cli/lib/cli/cli.js:153:25)
    at tryCatch (/Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/rsvp/dist/rsvp.js:538:13)
    at /Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/rsvp/dist/rsvp.js:606:14
    at flush (/Users/patocallaghan/src/me/instrumentation-dotenv/node_modules/rsvp/dist/rsvp.js:2415:5)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

My use case is I'd like to collect metrics, i.e. initial and rebuild times, from my team but would rather they didn't have to:

  1. set the EMBER_CLI_INSTRUMENTATION var themselves
  2. provide a script which they'd use instead of ember server which sets the var and calls ember server.

I'd rather it configured by default i.e. turned on by some sort of config file.

I have a replication repo of the issue here https://github.com/patocallaghan/instrumentation-dotenv

I'm not tied to ember-cli-dotenv so if you have any suggestions how to achieve what I'm trying to do I'd appreciate it, or if you directions on how to fix the issue I'd be happy to put the PR together myself.


Output from ember version --verbose && npm --version && yarn --version:

ember-cli: 2.16.2
http_parser: 2.7.0
node: 7.10.1
v8: 5.5.372.43
uv: 1.11.0
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 51
openssl: 1.0.2k
icu: 58.2
unicode: 9.0
cldr: 30.0.3
tz: 2016j
os: darwin x64
4.2.0
1.2.1

Activity

  1. rwjblue commented on Nov 9, 2017

    @rwjblue
    Member

    The use case seems good to me. Not sure about the best path forward, but the first thing that jumps out at me is that the projects .ember-cli file seems like the right place for this kind of thing...

  2. patocallaghan commented on Nov 9, 2017

    @patocallaghan
    ContributorAuthor

    I was thinking of something like that myself. I'd be happy to attempt a PR to make the changes.

    I guess two questions I have:

    • Is it acceptable to access the .ember-cli config file at the top of the file before the instrumentation init setup or should the init instrumentation setup be moved to within the module.exports?
    • Or should I access the .ember-cli config file within the utilities/instrumentation.js file as it contains all the other "enabling" logic?

    I'll see how I get on with it and if I have any questions I'll ping on a PR or jump into #dev-ember-cli.

  3. twokul commented on Nov 11, 2017

    @twokul
    Contributor

    @patocallaghan I think it might reasonable to move this code within module.exports. That way we would be able to access .ember-cli file and enable/disable instrumentation. All the requires in the file are "lazy" by default to optimize for a boot performance.

  4. patocallaghan commented on Nov 12, 2017

    @patocallaghan
    ContributorAuthor

    Thanks for the guidance @twokul. I'll work on this and ping you guys when ready. 🙇

  5. hjdivad commented on Nov 14, 2017

    @hjdivad
    Contributor

    @twokul not quite following your suggestion. Measuring cost of requireing modules is one of the main points of starting init instrumentation that early.

  6. twokul commented on Nov 14, 2017

    @twokul
    Contributor

    @hjdivad hm, makes sense. I was thinking of how to provide access to .ember-cli. also, if we want to measure the cost of requireing modules, wouldn't we want to place instrumentation here?

  7. hjdivad commented on Nov 14, 2017

    @hjdivad
    Contributor

    @twokul we have much more difficult compatibility requirements with bin/ember so we leave it alone. A consequence is that there's a small bit of startup that isn't measured during init, but we keep it as small as we can (basically as much as possible without requiring changes to bin/ember).

    can't we have instrumentationEnabled read .ember-cli (perhaps indirectly via some other API) and cache the result in module scope?

    @twokul @rwjblue @patocallaghan thoughts?

  8. hjdivad commented on Nov 14, 2017

    @hjdivad
    Contributor

    Or should I access the .ember-cli config file within the utilities/instrumentation.js file as it contains all the other "enabling" logic?

    Okay I see that I'm just echoing @patocallaghan's earlier suggestion ^_^

    Anyway this seems good to me (maybe with module scope caching as I think this function is called a few times).

  9. patocallaghan commented on Nov 15, 2017

    @patocallaghan
    ContributorAuthor

    @hjdivad @twokul ok thanks, so I'll go with the approach of checking the .ember-cli from within utilities/instrumentationEnabled.

    I'll probably need to move the following logic to its own model/module to remove duplication from both locations.

    let Yam = require('yam');
    let Project = require('../models/project');
    let config = new Yam('ember-cli', {
      primary: Project.getProjectRoot(),
    });
    

    @hjdivad that's what you were thinking of saying perhaps indirectly via some other API?

  10. hjdivad commented on Nov 15, 2017

    @hjdivad
    Contributor

    @hjdivad that's what you were thinking of saying perhaps indirectly via some other API?

    yes exactly

  11. patocallaghan commented on Apr 12, 2018

    @patocallaghan
    ContributorAuthor

    Closing as I shipped the ability to turn this on using .ember-cli in #7491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions