3.0.0 • Published 10 months ago

spw-instrumentation v3.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

SPW Instrumentation Tools

System requirements

  • NodeJS version 12

Installation

npm i spw-instrumentation

Environment variables

NameDescription
NEW_RELIC_API_EVENT_BASE_URLNew Relic Event API endpoint before account ID
NEW_RELIC_API_METRIC_BASE_URLNew Relic Metric API endpoint before account ID
NEW_RELIC_API_ACCOUNT_IDNew Relic account ID
NEW_RELIC_LICENSE_KEYNew Relic license key
NEW_RELIC_INSTRUMENTATION_ENABLEDSet to "true" will send metric and event to New Relic
NEW_RELIC_INSTRUMENTATION_SENT_INTERVAL_MILLISECInterval 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