@bastani/atomic-telemetry
v0.10.31
Published
Atomic's vendor-neutral telemetry contracts, typed schemas and reference contexts
Maintainers
Readme
@bastani/atomic-telemetry defines an explicit, callback-based TelemetryContext and TelemetrySpan contract alongside a no-op context, an in-memory reference context, metrics, context propagation, and typed schemas. It ships no built-in exporter and sends nothing on its own; connect it to OpenTelemetry, Sentry, logs, or another backend through an adapter.
Atomic runs on this package and publishes it with every release at the same version.
Install
npm install @bastani/atomic-telemetryInside an Atomic extension, you can import it without installing it because the running Atomic process provides it. See Libraries.
Quick start
import {
InMemoryTelemetryContext,
NOOP_TELEMETRY_CONTEXT,
type TelemetryContext,
} from "@bastani/atomic-telemetry";
import { renderTrace } from "@bastani/atomic-telemetry/render";
const accounts = new Map<string, { id: string; plan: string }>([["acct-1", { id: "acct-1", plan: "pro" }]]);
async function loadAccount(accountId: string, telemetry: TelemetryContext = NOOP_TELEMETRY_CONTEXT) {
return telemetry.startSpan(
{
name: "example.account.load",
attributes: { "example.account.id": accountId },
},
async (span) => {
const account = accounts.get(accountId);
span.setAttributes({ "example.account.found": account !== undefined });
return account;
},
);
}
const recorder = new InMemoryTelemetryContext();
await loadAccount("acct-1", recorder);
const { traces } = await recorder.findTraces();
if (traces[0]) console.log(renderTrace(traces[0].spans));Subpath exports
@bastani/atomic-telemetry: Core interfaces,NOOP_TELEMETRY_CONTEXT,InMemoryTelemetryContext, and typed span schemas.@bastani/atomic-telemetry/render:renderTrace()to format stored traces as readable terminal text.@bastani/atomic-telemetry/testing:createTelemetryAdapterConformance()to test custom telemetry adapters against the contract.
Documentation
The full guide and API reference are in Atomic's docs: @bastani/atomic-telemetry.
License
MIT. See LICENSE.
Derived from pi by Mario Zechner and Earendil Works; see NOTICE.md.
