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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@loopstack/observability-examples

v0.1.1

Published

Workflow examples for observability in Loopstack — opt-in quota tracking and enforcement.

Downloads

173

Readme


title: Observability Examples description: Workflow examples for observability in Loopstack — quota tracking, custom tool interceptors for tracing, custom quota calculators, and event-driven audit logging

@loopstack/observability-examples

Observability workflow examples for the Loopstack automation framework.

Workflow examples for tracking and enforcing operational limits.

Install as Source (Recommended)

npx giget@latest gh:loopstack-ai/loopstack/registry/examples/observability-examples src/observability-examples

Register the module:

import { Module } from '@nestjs/common';
import { LoopstackModule } from '@loopstack/loopstack-module';
import { ObservabilityExamplesModule } from './observability-examples/observability-examples.module';

@Module({
  imports: [LoopstackModule.forRoot(), ObservabilityExamplesModule],
})
export class AppModule {}

Install as a Dependency

npm install @loopstack/observability-examples
import { ObservabilityExamplesModule } from '@loopstack/observability-examples';

Examples

| Example | Studio title | Description | | --------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------- | | Quota | Observability - Quota Example | Manual check + report usage with @loopstack/quota, Redis-backed when enabled | | Tracing Interceptor | Observability - Tracing Interceptor Example | Custom ToolInterceptor measuring every tool execution app-wide | | Custom Quota Calculator | Observability - Custom Quota Calculator Example | Custom ToolQuotaCalculator metering a tool automatically via QuotaInterceptor | | Audit Log | Observability - Audit Log Example | @OnEvent listener recording workflow & document lifecycle events |


Quota

Demonstrates the manual quota API of @loopstack/quota:

  1. quotaClient.checkQuota(userId, quotaType) — verify available budget
  2. Perform the (placeholder) operation if allowed
  3. quotaClient.report(userId, quotaType, amount) — charge against the quota

When QuotaModule.forRoot({ enabled: false }), both calls no-op. Set enabled: true plus Redis connection options to enforce real limits. Note: with quota enabled, a user without a limit key in Redis is blocked by default.

Built-in quota types: llm-cost (LLM token cost in microcents) and processing-time-ms (tool execution time).

Files

  • quota-example.workflow.ts — workflow class

Tracing Interceptor

Demonstrates writing a custom ToolInterceptor:

  • @UseToolInterceptor({ priority: 10 }) registers the class app-wide — the framework discovers it via NestJS DiscoveryService, no manual wiring
  • The interceptor wraps every tool call (all modules), measures duration, and records entries in an injectable ToolTraceService
  • The workflow runs a few SimulateWorkTool calls, then filters the trace by its own workflowId and renders a markdown table

Interceptors follow a chain pattern like NestJS interceptors: run logic before/after next(), transform results, short-circuit (caching), or catch errors. Lower priority runs first (outermost).

Files

  • tracing-example.workflow.ts — workflow class
  • interceptors/tracing.interceptor.ts — the custom ToolInterceptor
  • services/tool-trace.service.ts — injectable trace store
  • tools/simulate-work.tool.ts — demo tool that sleeps for a configurable duration

Custom Quota Calculator

Demonstrates extending the quota system with a custom ToolQuotaCalculator:

  • WordsProcessedQuotaCalculator defines quota type words-processed and derives the charged amount from the tool result (word count)
  • The module registers it for AnalyzeTextTool in onModuleInit via QuotaCalculatorRegistry
  • The built-in QuotaInterceptor then checks the quota before and reports usage after every AnalyzeTextTool execution — the workflow just calls the tool, no manual check/report

This is the recommended pattern for metering tools: the workflow stays clean, enforcement lives in the interceptor.

Files

  • custom-calculator-example.workflow.ts — workflow class
  • calculators/words-processed.calculator.ts — the custom ToolQuotaCalculator
  • tools/analyze-text.tool.ts — demo tool whose usage is metered

Audit Log

Demonstrates subscribing to framework events for monitoring:

  • The framework dispatches lifecycle events on the client.message channel — e.g. workflow.created, workflow.updated, document.created
  • AuditListener uses @OnEvent('client.message') to capture every event into an injectable AuditLogService (bounded in-memory store)
  • The workflow saves a few documents to generate events, then renders its own audit trail filtered by workflowId

This is the event-driven counterpart to the tracing interceptor: interceptors wrap tool calls, event listeners observe workflow and document lifecycle. Swap the in-memory store for a database or metrics exporter in production.

Files

  • audit-log-example.workflow.ts — workflow class
  • listeners/audit.listener.ts — the @OnEvent listener
  • services/audit-log.service.ts — injectable audit store

About

Author: Jakob Klippel

License: MIT