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

xray-well

v0.2.0

Published

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

Downloads

21

Readme

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

Documentation

Why?

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(xrayWell.middleware.express({ name: "my.awesome.domain.com" })); // Add it before any another middleware

app.get("/", (req, res) => {
  req.xray.setUser("[email protected]");
  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: "my.awesome.domain.com" })); // Add it before any another middleware

app.use((ctx) => {
  ctx.xray.setUser("[email protected]");
  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.
  xrayWell.segment.submitSegmentPart(segment);

  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.
  xrayWell.segment.submitSegmentPart(nestedSegment);

  await sleep(1000);

  nestedSegment.annotations = {
    function2: "done of doing something",
  };

  // Submit by nested segment already done.
  xrayWell.segment.submitSegment(nestedSegment);

  await sleep(1000);

  // Submit my main segment to finish the flow.
  xrayWell.segment.submitSegment(segment);
}

TO-DO

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

License

MIT