Extensions
Telemetry
@stone-js/telemetry observes the app from the same place everything else attaches: a blueprint and a middleware. It records spans and metrics around each event and hands them to an exporter, so observability is configuration, not code scattered through handlers.
#Install & enable
npm i @stone-js/telemetryimport { StoneApp } from '@stone-js/core'
import { Telemetry } from '@stone-js/telemetry'
@Telemetry() // spans and metrics around each event
@StoneApp({ name: 'tasks' })
export class Application {}import { defineStoneApp } from '@stone-js/core'
import { telemetryBlueprint } from '@stone-js/telemetry'
export const App = defineStoneApp(
{ name: 'tasks' },
[telemetryBlueprint]
)#What it records
With telemetry enabled, each event is wrapped in a span and timed; you add your own spans and counters where a domain operation is worth measuring. The Telemetry service is injected like any other.
constructor ({ telemetry }) { this.telemetry = telemetry }
create (event: IncomingHttpEvent) {
return this.telemetry.span('task.create', () => {
const task = this.tasks.add(event.get('title'))
this.telemetry.count('task.created')
return task
})
}#Exporters
Where telemetry goes is an exporter, swapped without touching your instrumentation. The console exporter ships for development; point it at your platform in production.
| Piece | Type | Description |
|---|---|---|
| Telemetry | service | Injected; create spans and metrics from your code. |
| TelemetryMiddleware | middleware | Wraps each event in a span automatically. |
| ConsoleTelemetryExporter | exporter | Writes telemetry to the console (development default). |
| telemetryBlueprint | blueprint | Enables telemetry imperatively. |