spw-instrumentation
v3.0.0
Published
SPW Instrument tools
Downloads
286
Readme
SPW Instrumentation Tools
System requirements
- [x] NodeJS version 12
Installation
npm i spw-instrumentation
Environment variables
| Name | Description | | ----------- | ----------- | | NEW_RELIC_API_EVENT_BASE_URL | New Relic Event API endpoint before account ID | | NEW_RELIC_API_METRIC_BASE_URL | New Relic Metric API endpoint before account ID | | NEW_RELIC_API_ACCOUNT_ID | New Relic account ID | | NEW_RELIC_LICENSE_KEY | New Relic license key | | NEW_RELIC_INSTRUMENTATION_ENABLED | Set to "true" will send metric and event to New Relic | | NEW_RELIC_INSTRUMENTATION_SENT_INTERVAL_MILLISEC | Interval of when to send a batch |
Usage
Send an event
const instrument: InstrumentServiceInterface = NewRelicInstrumentService.shared()
const eventFactory: EventFactory = instrument.getEventFactory()
const input: EventInput = {
eventType: 'SpwInstrumentationModuleIntegrationTest',
attributes: {
attrA: 'attribute A',
attrB: 'attribute B',
attrC: 'attribute C',
},
timestamp: Date.now(),
}
const event: InstrumentEvent = eventFactory.makeEvent(input)
await instrument.sendEvent(event)
Send metrics
const instrument: InstrumentServiceInterface = NewRelicInstrumentService.shared()
const metricFactory: MetricFactory = instrument.getMetricFactory()
const metrics: InstrumentMetric[] = [
metricFactory.makeCountMetic({
name: 'spw.instrumentation.module.integration.test.count',
value: 1,
attributes: {
attrA: 'attribute A',
attrB: 'attribute B',
attrC: 'attribute C',
},
'interval.ms': 100,
timestamp: Date.now(),
}),
metricFactory.makeGaugeMetric({
name: 'spw.instrumentation.module.integration.test.gauge',
value: 1,
attributes: {
attrA: 'attribute A',
attrB: 'attribute B',
attrC: 'attribute C',
},
timestamp: Date.now(),
}),
metricFactory.makeSummaryMetric({
name: 'spw.instrumentation.module.integration.test.summary',
value: {
count: 1,
sum: 2,
min: 3,
max: 4,
},
attributes: {
attrA: 'attribute A',
attrB: 'attribute B',
attrC: 'attribute C',
},
'interval.ms': 100,
timestamp: Date.now(),
}),
]
await instrument.sendMetric(metrics)
Development prerequisite
nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Testing
Unit test
npm run test:unit
Integration test
Copy .env.example to .env.integration and set its value
npm run test:integration