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

gcloud-tracer

v2.0.0

Published

Custom Google Cloud StackDriver tracing client w/out using CLS

Downloads

13

Readme

gcloud-trace

Custom Google Cloud StackDriver tracing client w/out monkey patching

Installation

npm i --save gcloud-trace

Usage

Configure google trace options:

https://github.com/GoogleCloudPlatform/cloud-trace-nodejs https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/blob/a1650a414c153f68f904909f3bba1d9ae73270da/config.js

const trace  = require('gcloud-trace')
// initialize trace w/ options
trace.init(opts)

Glossary

Each bar line in the chart below is a SpanData. The first bar is the RootSpanData. SpanData's have names and have labels (reference properties). Trace Details Example

Custom trace RootSpanData

const trace  = require('gcloud-trace')
trace.init(opts)

const spanName = 'root trace span'
const spanData = trace.createRootSpanData(spanName, {
  // optional options:
  // parent trace span info
  traceId: 'continuingFromAnotherService',
  parentSpanId: 'continuingFromAnotherService',
  // or traceHeader - spanData.toHeader() will return a traceHeader string to trace across services
  traceHeader: 'traceId/parentSpanId;o=1',
  // remove frames from stack trace for span
  // like if you wrap this library w/ your own helper/util
  skipFrames: 1,
  // span kind: RPC_SERVER or RPC_CLIENT
  spanKind: 'RPC_SERVER'
})
// ... see span data usage below

Custom trace RootSpanData for a request

// spanName will be the url path
// parent span info (traceId and parentSpanId) are extracted from req.headers[trace.HEADER_NAME]
// request info labels are automatically added to the span
const spanData = trace.createReqRootSpanData(req, res, {
  // optional options:
  // remove frames from stack trace for span
  // like if you wrap this library w/ your own helper/util
  skipFrames: 1,
  // span kind: RPC_SERVER or RPC_CLIENT
  spanKind: 'RPC_SERVER'
})
// ... see span data usage below

SpanData methods

// add trace span labels
spanData.addLabels('foo', 'bar')
// add trace span properties
spanData.addLabels({
  foo: 'bar'
})
// end trace span time and report to stackdriver
spanData.close()

Create a child SpanData

const spanName = 'childSpanName'
spanData.createChildSpanData(spanName) // same optional opts..

Maintain trace across services

client.js

const trace = require('gcloud-trace')
trace.start()
//...
const traceHeader = spanData.toHeader()
const headers = {}
headers[trace.HEADER_NAME] = traceHeader
http.request({
  hostname: 'foo.foo',
  port: 80,
  path: '/bar',
  headers: headers
}).end()

server.js

const trace = require('gcloud-trace')
trace.start()

http.createServer(function (req, res) {
  const rootSpan = trace.createReqRootSpanData(req, res)
  const timeoutSpan = rootSpan.createChildSpanData('timeout')
  setTimeout(function () {
    timeoutSpan.end() // not required, will auto end with root span..
    res.writeHead(200)
    rootSpan.end() // not required, will auto-end w/ res
    res.end()
  }, 100)
}).listen(80)

Maintain trace non-http across services

client.js

//...
const traceHeader = spanData.toHeader()
rpc({
  operation: 'foo',
  traceHeader: traceHeader,
  payload: { bar: 'qux' }
}, cb)

server.js

const trace =
rpcServer(function (data) {
  const payload = data.payload
  const rootSpan = createRootSpan(data.operation, {
    traceHeader: data.traceHeader
  })
  // ...
})

License

MIT