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

telemetry-events-trace

v0.2.1

Published

Helper for creating and emitting telemetry trace events.

Downloads

5

Readme

telemetry-events-trace

Stability: 1 - Experimental

NPM version

Helper for creating and emitting TelemetryEvents for tracing.

Contributors

@tristanls

Contents

Installation

npm install telemetry-events-trace

Usage

To run the below example run:

npm run readme
"use strict";

const events = require("events");
const pkg = require("../package.json");
const TelemetryEvents = require("telemetry-events");

const TraceTelemetryEvents = require("../index.js");

const emitter = new events.EventEmitter();

const telemetry = new TelemetryEvents(
    {
        emitter,
        package: pkg
    }
);
const tracing = new TraceTelemetryEvents(
    {
        telemetry
    }
);

emitter.on("telemetry", event => console.dir(event));

let rootSpan1 = tracing.trace("rootSpan1", undefined, {user: "tristan"});
setTimeout(() => rootSpan1.finish(), 5);

let rootSpan2 = tracing.trace("rootSpan2", {server: "001"}, {user: "tristan"});
let childSpan1 = rootSpan2.childSpan("childSpan1", {db: "020"});
let childSpan2 = rootSpan2.childSpan("childSpan2", {db: "021"});
let childSpan3 = childSpan1.childSpan("childSpan3");
let childSpan4 = childSpan2.followingSpan("childSpan4", {consumer: "me"});
childSpan4.tags(
    {
        "some": "tag",
        "some_other": "tag"
    }
);

let headers = childSpan3.inject("http_headers", {});
console.log(headers);
let extractedSpan = tracing.extract("http_headers", headers);

let childSpan5 = extractedSpan.childSpan("childSpan5");
childSpan5.tag("error", true);

setTimeout(() => childSpan3.finish(), 10);
setTimeout(() => childSpan2.finish(), 11);
setTimeout(() => childSpan1.finish(), 12);
setTimeout(() => rootSpan2.finish(), 13);
setTimeout(() => childSpan4.finish(), 22);

setTimeout(() => childSpan5.finish(), 20);

Tests

No tests at this time.

Documentation

TraceTelemetryEvents

Public API

new TraceTelemetryEvents(config)

  • config: Object
    • telemetry: Object TelemetryEvents instance.
  • Return: Object Instance of TraceTelemetryEvents.

Creates a new TraceTelemetryEvents instance.

tracing.extract(type, carrier)

  • type: String One of ["http_headers", "text_map"]
  • carrier: Object JavaScript object to extract span from.
  • Return: TraceTelemetryEvents.Span Span initialized from information in the carrier.

Creates a localy copy of the parent span extracted from the carrier. This local Span instance can then be used to generate child or following spans.

tracing.trace(name, [tags], [baggage], [start])

  • name: String Operation name to trace.
  • tags: Object (Default: {}) Tags to attach to the span.
  • baggage: Object (Default: {}) Baggage to attach to all the spans in the trace.
  • start: Date (Default: new Date()) Start time.
  • Return: TraceTelemetryEvents.Span Newly created root span for the trace.

Creates a root span.

span.childSpan(name, [tags], [baggage], [start])

  • name: String Operation name to trace.
  • tags: Object (Default: {}) Tags to attach to the span.
  • baggage: Object (Default: {}) Baggage to attach to this and all following spans in the trace.
  • start: Date (Default: new Date()) Start time.
  • Return: TraceTelemetryEvents.Span Newly created child span.

Creates a child span that has a childOf reference to the span.

span.finish([finish])

  • finish: Date (Default: new Date()) Finish time.
  • Return: TraceTelemetryEvents.Span Finished span.

Finishes the span and emits a trace telemetry event.

span.followingSpan(name, [tags], [baggage], [start])

  • name: String Operation name to trace.
  • tags: Object (Default: {}) Tags to attach to the span.
  • baggage: Object (Default: {}) Baggage to attach to this and all following spans in the trace.
  • start: Date (Default: new Date()) Start time.
  • Return: TraceTelemetryEvents.Span Newly created "follows from" span.

Creates a child span that has a followsFrom reference to the span.

span.inject(type, carrier)

  • type: String One of ["http_headers", "text_map"]
  • carrier: Object JavaScript object to inject span information into.
  • Return: carrier with injected span information.

Injects span information into the carrier.

span.tag(key, value)

  • key: String Tag key.
  • value: String Tag value.
  • Return: TraceTelemetryEvents.Span Span where tags were updated.

Creates or updates a tag in a span.

span.tags(tags)

  • tags: Object Keys and values of tags to create or update.
  • Return: TraceTelemetryEvents.Span Span where tags were updated.

Creates or updates tags in a span.

Releases

We follow semantic versioning policy (see: semver.org):

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes.

caveat: Major version zero is a special case indicating development version that may make incompatible API changes without incrementing MAJOR version.