Naughty Pinching Mannequins

    TypeScript icon, indicating that this package has built-in type declarations

    0.2.0 • Public • Published

    AWS X-Ray Well - An Unofficial SDK for Node.js

    Simple way to use AWS X-Ray. This is a jerry-rig free X-Ray SDK.

    X-Ray Well Tests GitHub node-current npm npm



    The Official AWS SDK X-Ray wraps the native node modules to try to make it like magic, but it's a bad idea when trying to use it in complex systems. I tried to use the official SDK for more than 5 times in the past and it always not work to me, sometimes the problem is because I use it in a framework not supported as Koa, some times even on express (supported framework by AWS SDK) it not work well.

    So, I created this lib well done, this lib will never auto attach on Node.js native modules, it does not work like magic, but you can do your magic using it.

    How to install it?

    $ npm install xray-well --save

    Set the configuration on main file of your application. You still need the AWS X-Ray Daemon

    const xrayWell = require("xray-well");
    xrayWell.setConfig({ server: "localhost", port: 2000 });

    How to use on Express Framework?

    const xrayWell = require("xray-well");
    const express  = require("express");
    const app      = express();
    app.use({ name: "" })); // Add it before any another middleware
    app.get("/", (req, res) => {
      req.xray.addAnnotation("user_id", "44232123");
      req.xray.addAnnotation("company", "acme");
      req.xray.addMetadata("myNamespace", "any", "value");
      req.xray.addMetadata("myNamespace", "another", true);
      req.xray.addMetadata("mySecondsNamespace", "foo", "bar");
      res.send("Hi AWS, I'm not using your SDK! =)");
    app.listen(3030, () => console.log("Listening at http://localhost:3030"));

    How to use on Koa Framework?

    const xrayWell = require("xray-well");
    const Koa      = require("koa");
    const app      = new Koa();
    app.use(xrayWell.middleware.koa({ name: "" })); // Add it before any another middleware
    app.use((ctx) => {
      ctx.xray.addAnnotation("user_id", "44232123");
      ctx.xray.addAnnotation("company", "acme");
      ctx.xray.addMetadata("myNamespace", "any", "value");
      ctx.xray.addMetadata("myNamespace", "another", true);
      ctx.xray.addMetadata("mySecondsNamespace", "foo", "bar");
      ctx.body = "Hi AWS, I'm not using your SDK! =)";
    app.listen(3030, () => console.log("Listening at http://localhost:3030"));

    How to use without any web framework

    You can change any aspect of your segment any time.

    const xrayWell = require("xray-well");
    const sleep    = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
    async function init() {
      // Create a main segment.
      const segment = xrayWell.segment.createSegment("my-own-function");
      segment.annotations = {
        function: "init",
      // Submit main segment, in process yet.
      await sleep(1000);
      // Create a nested segment forked from main.
      const nestedSegment = xrayWell.segment.forkSegment("nestedSegment", segment);
      nestedSegment.annotations = {
        function2: "doing something",
      // Submit my nested segment, in process yet.
      await sleep(1000);
      nestedSegment.annotations = {
        function2: "done of doing something",
      // Submit by nested segment already done.
      await sleep(1000);
      // Submit my main segment to finish the flow.


    • [ ] Create an easy way to add SQL Segments;
    • [ ] Implement exceptions segments;
    • [ ] Complete documentation;




    npm i xray-well

    DownloadsWeekly Downloads






    Unpacked Size

    65 kB

    Total Files


    Last publish


    • felipefdl