npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dynatrace/agent-api

v1.2.0

Published

Node.js bindings for Dynatrace OneAgent

Downloads

12

Readme

Node.js API for Dynatrace OneAgent

This module provides JavaScript bindings for Node.js applications monitored with Dynatrace.

What does this module provide?

The current version provides a method passContext() which passes transactional context through chains of callbacks for new modules that are not yet supported out-of-the-box. Dynatrace supports many technologies out-of-the-box and this module needs to be used only in rare corner cases - so only use this module if transactions seem to be incomplete.

Quick Start

Installation

$ npm install --save @dynatrace/agent-api

Usage

Example: Regular callbacks

const dta = require('@dynatrace/agent-api')();

some.asyncFunction(someParam, dta.passContext(function(err, result) {
   // Context is preserved
   http.get('https://some-api.xyz/service', dta.passContext((res) => {}));
}));

Example: Express route with couchDB middleware and promises

const dta = require('@dynatrace/agent-api')();

function couchMiddleware(req, res, next) {
  couch.get('testdb', '123a3354452ddfa2973ec0a477000f7a').then(dta.passContext(couchCallback), err => {
    if(err) throw err;
  }).then(dta.passContext(next)); 
}

router.get('/couchdb', couchMiddleware, (req, res, next) => {
  request.get('https://google.com', (err, result) => {
    res.send('hello');
  });
});

Please Note

  • Make sure that the module is required after Dynatrace agent.
  • Using this module will not cause any errors if no agent is present (e.g. in testing).
  • The wrapping needs to happen call time.
// This will *NOT* work
const wrappedFunction = dta.passContext(someFunction);
some.asyncFunction('someParam', wrappedFunction);

// This works
some.asyncFunction('someParam', dta.passContext(someFunction));

Further Information

What is transactional context?

Dynatrace's patented PurePath Technology® captures timing and code level context for all transactions, end-to-end, from user click, across all tiers, to the database of record and back. Technically this means that Dynatrace adds transactional context to any inbound-, outbound- and function call of an application.

What does this mean for Node.js applications?

Node.js is single threaded - its control flow is based on events and asynchronous callbacks.

Let's look at an example for finding a document with mongoDB:

function callback(err, document) {
    console.log(document.name);

    http.get('https://some-api.xyz/service', (res) => {});
      // ^^^                                 °°°°°°°°°°°
      // Asynchronous call                   Asynchronous callback                                            
}

collection.findOne({_id: doc_id}, callback);
        // ^^^^^^^                °°°°°°°°
        // Asynchronous call      Asynchronous callback

After collection.findOne() is executed asynchronously callback() will be called. callback() again contains an asynchronous call http.get() which performs an outbound http request. If there is a current transactional context, Dynatrace will transparently add a header containing a transaction id to this outbound request. The next tier - if instrumented with Dynatrace - will continue this transaction then.

Without further intervention any transactional context would get lost between asynchronous invocation and a callback.

Currently the only reliable way to pass over context information to a callback is called 'wrapping'.

This means: Dynatrace will transparently wrap supported libraries to add context information. For every yet unsupported module passContext() can be used to provide transactional context to callbacks.

Disclaimer

This module is supported by the Dynatrace Innovation Lab. Please use the issue tracker to report any problems or ask questions.

License

Licensed under the MIT License. See the LICENSE file for details.