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

@primafuture/telemetry-structured-metadata

v0.1.2

Published

Shared structured metadata encoder for PrimaFuture telemetry libraries.

Readme

@primafuture/telemetry-structured-metadata

Shared structured metadata encoder for PrimaFuture telemetry libraries.

It converts nested JavaScript metadata into OpenTelemetry-safe flat attributes and an optional JSON representation that can be decoded back later.

Usage

import {
  encodeStructuredMetadata,
  decodeStructuredMetadata,
} from '@primafuture/telemetry-structured-metadata';

const attributes = encodeStructuredMetadata({
  request: {
    id: 'abc',
    deletedAt: null,
  },
  missing: undefined,
});

Default output:

app.value.request.id = "abc"
app.type.request.deletedAt = "null"
app.type.missing = "undefined"
app.meta.json = "{\"request\":{\"id\":\"abc\",\"deletedAt\":null},\"missing\":{\"$pfType\":\"undefined\"}}"

flatten output is meant for queries. json output is meant for reconstruction. raw output is disabled by default and only passes through OpenTelemetry-safe scalar or homogeneous array values.

Options

All output modes are independent and can be enabled at the same time:

encodeStructuredMetadata(metadata, {
  flatten: {
    enabled: true,
    namespace: 'app',
    valuePrefix: 'value',
    typePrefix: 'type',
    typeFields: 'when-needed',
  },
  json: {
    enabled: true,
    key: 'app.meta.json',
    valueEncoding: 'typed',
    typeKey: '$pfType',
  },
  raw: {
    enabled: false,
  },
});

Defaults:

  • flatten.enabled = true
  • flatten.namespace = "app"
  • flatten.valuePrefix = "value"
  • flatten.typePrefix = "type"
  • flatten.typeFields = "when-needed"
  • json.enabled = true
  • json.key = "app.meta.json"
  • json.valueEncoding = "typed"
  • json.typeKey = "$pfType"
  • raw.enabled = false

typeFields controls app.type.* output:

  • when-needed: emit type markers only for values that plain OTel attributes cannot represent clearly, such as null, undefined, Date, bigint, Error, empty objects/arrays, functions, symbols, circular references, and unsupported objects.
  • always: emit a type marker for every flattened value.
  • never: do not emit type markers.

json.valueEncoding = "typed" preserves JavaScript-only values using the configured type key. plain-json writes ordinary JSON instead: Date becomes an ISO string, bigint becomes a string, and undefined/function/symbol values follow normal JSON behavior.

raw.enabled = true is a compatibility mode. It passes through only OTel-safe scalar values or homogeneous arrays. Nested objects never go through raw mode.

Decode

decodeStructuredMetadata(attributes) reads the configured JSON key, defaulting to app.meta.json, and reconstructs the metadata object from the JSON view.

const decoded = decodeStructuredMetadata(attributes);

The decoder primarily uses JSON because flattened attributes are a query view, not the source of truth for reconstruction. It also accepts Loki-style underscore keys such as app_meta_json.

Development

npm install
npm run typecheck
npm test
npm run build
npm run prepublishOnly