@storyshelf/observability
v0.15.0
Published
StoryShelf observability: OpenTelemetry tracing, metrics, and log correlation over StoryShelf adapters.
Maintainers
Readme
@storyshelf/observability
OpenTelemetry tracing, metrics, and log correlation for StoryShelf adapters. This is the single OTEL owner in the monorepo.
Install
nub add @storyshelf/observabilityor
npm install @storyshelf/observabilityUsage
The database and storage wrappers come from core, so this example also needs @storyshelf/core installed (npm install @storyshelf/core):
import { createInstrumentedDatabase, createInstrumentedStorage } from "@storyshelf/core/telemetry";
const database = createInstrumentedDatabase(baseDatabase);
const storage = createInstrumentedStorage(baseStorage);See the StoryShelf documentation for configuration details.
Server wiring
import { otelLogMixin } from "@storyshelf/observability";
import { initObservabilityFromEnv } from "@storyshelf/observability/node";
// Noop unless OTEL_EXPORTER_OTLP_ENDPOINT is set. Call before createShelfApp.
const observability = await initObservabilityFromEnv();
const app = createShelfApp({
database,
storage,
testing: { runner: captureRunner },
logger: createShelfLogger({ mixin: otelLogMixin }),
observability,
config: { scratchDir: dataDir },
});
await app.lifecycle.setup();
// on SIGTERM: await app.lifecycle.teardown(); (flushes the SDK)create-storyshelf scaffolds exactly this preamble. Two entrypoints by design: the root is @opentelemetry/api
only (runtime-agnostic); ./node holds the Node SDK lifecycle.
What it exports
initObservabilityFromEnv,resolveObservabilityConfig(./node/ config) — env-driven SDK lifecycle.createHttpMiddleware—@hono/otelserver spans plusstoryshelf.req_id/enduser.id(mounted bycreateShelfApp).createInstrumentedDatabase/createInstrumentedStorage— transparentdb.*/storage.*span + metric wrappers (identity, lifecycle, and tables delegate through). They need core's adapter types, so they live in@storyshelf/core/telemetry, not here: this package depends on@storyshelf/commonand never installs core.withSpan,currentTraceparent,injectTraceContext,parentContext— span and W3C propagation helpers.captureMetrics,dbMetrics,storageMetrics— memoized instruments (capture.job.duration,capture.jobs.completed/failed, operation durations).otelLogMixin— pino mixin injectingtrace_id/span_id(logs stay on stdout; no OTLP log exporter by design).
Core (@storyshelf/core) uses @opentelemetry/api (through @storyshelf/common/tracing) for pipeline
spans (capture.job, phase spans, http.client) and never imports this
package — that one-way boundary is load-bearing (see ADR 0015 §5).
License
MIT
