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

@rbxts-trail/core

v0.1.1

Published

Event-based diagnostic information inspired from tokio-rs's tracing

Downloads

164

Readme

[!CAUTION] This project is in experimental phase. We advise you to not use this in your production projects. Bugs and unexpecteds output with these modules will occur at any time.

If you wish to do so, PLEASE USE IT AT YOUR OWN RISK!

Usage

roblox-ts

import { Event, Level, Span, Subscriber, fields, info } from "@rbxts-trail/core";
import { Layer, LayerContext, Layers } from "@rbxts-trail/subscriber";
import { LookupSpan, Registry, SpanData } from "@rbxts-trail/subscriber";

type RegistrySubscriber = Subscriber & LookupSpan<SpanData>;

class FmtLayer extends Layer<RegistrySubscriber> {
    public onEvent(event: Event, ctx: LayerContext<RegistrySubscriber>): void {
        const timestamp = DateTime.now()
            .FormatLocalTime("YYYY-MM-DDTHH:MM:SSZ", "en-us");

        event.metadata.fields.push("timestamp");
        event.fields.push(timestamp);

        const levelStr = Level[event.metadata.level].lower();
        print(`[${timestamp}] [${levelStr}] ${event.fields[0]}`);
    }
}

const subscriber = new Layers(new Registry())
    .withLayer(new FmtLayer());

Subscriber.setGlobalDefault(subscriber);

const numberOfYaks = 3;
info("preparing to shave yaks", fields({ numberOfYaks: numberOfYaks }));

const numberShaved = yakShave.shaveAll(numberOfYaks);
info("yak shaving completed", fields({
    allYaksShaved: numberOfYaks === numberShaved,
}));

Soon...

import { Service, OnStart } from "@flamework/core";
import { Players } from "@rbxts/services";
import { Span, info, fields } from "@rbxts-trail/core";
import { Instrument } from "@rbxts-trail/decorators";

@Service({})
export class TestService implements OnStart {
    @Instrument({
        name = "onPlayerAdded",
        target = "src::services::TestService"
    })
    private onPlayerAdded(player: Player) {
        const span = Span.current();
        span.record("player.DisplayName", player.DisplayName);
        span.record("player.Name", player.Name);
        span.record("player.UserId", player.UserId);

        info("{} ({}) joined the game", player.Name, player.UserId, fields({
            "player.AccountAge": player.UserId,
        }));
    }

    public onStart() {
        Players.PlayerAdded.Connect((player) => {
            task.spawn(() => this.onPlayerAdded(player));
        });
    }
}

Luau

local FmtLayer = setmetatable({}, TrailSubscriber.Layer)
FmtLayer.__index = FmtLayer

function FmtLayer.new()
    return setmetatable({
        _name = "FmtLayer",
    }, FmtLayer)
end

function FmtLayer:onEvent(event, ctx)
    local timestamp = DateTime.now():FormatLocalTime("YYYY-MM-DDTHH:MM:SSZ", "en-us")
    table.insert(event.metadata.fields, "timestamp")
    table.insert(event.fields, timestamp)

    local levelStr = Trail.Level[event.metadata.level]:lower()
    print(`[{timestamp}] [{levelStr}] {event.fields[1]}`)
end

local subscriber = Layers.new(Registry.new())
    :withLayer(FmtLayer.new())

Subscriber.setGlobalDefault(subscriber)

local numberOfYaks = 3
info("preparing to shave yaks", fields { numberOfYaks = numberOfYaks })

local numberShaved = yakShave.shaveAll(numberOfYaks)
info("yak shaving completed", fields {
    allYaksShaved = numberOfYaks == numberShaved,
})

local function span(number: number)
    info("hi!")
end
span = instrument(span, {
    name = "span_test",
    target = "script",
    fields = function(span, number: number)
        span:record("number", number)
    end,
})

span(123)