@neo-one/monitor
Advanced tools
Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4
@@ -422,5 +422,5 @@ import opentracing from 'opentracing'; | ||
value: function forRequest(ctx) { | ||
var _withLabels; | ||
var _withLabels, _withLabels$withData; | ||
return this.withLabels((_withLabels = {}, _defineProperty(_withLabels, KNOWN_LABELS.HTTP_METHOD, ctx.method), _defineProperty(_withLabels, KNOWN_LABELS.SPAN_KIND, 'server'), _withLabels)).withData(_defineProperty({}, KNOWN_LABELS.HTTP_URL, ctx.originalUrl || ctx.url)); | ||
return this.withLabels((_withLabels = {}, _defineProperty(_withLabels, KNOWN_LABELS.HTTP_METHOD, ctx.method), _defineProperty(_withLabels, KNOWN_LABELS.SPAN_KIND, 'server'), _withLabels)).withData((_withLabels$withData = {}, _defineProperty(_withLabels$withData, KNOWN_LABELS.HTTP_URL, ctx.originalUrl || ctx.url), _defineProperty(_withLabels$withData, KNOWN_LABELS.HTTP_PATH, ctx.path), _withLabels$withData)); | ||
} | ||
@@ -592,3 +592,3 @@ }, { | ||
type: 'counter', | ||
suffix: 'error_total' | ||
suffix: 'total' | ||
} : metric, | ||
@@ -599,4 +599,3 @@ error: { | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -627,4 +626,3 @@ } | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -756,3 +754,8 @@ } | ||
value: function captureSpan(func, options) { | ||
var span = this.startSpan(options); | ||
var span = this.startSpan({ | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
@@ -780,2 +783,21 @@ try { | ||
}, { | ||
key: "captureSpanLog", | ||
value: function captureSpanLog(func, options) { | ||
return this.captureSpan(function (span) { | ||
return span.captureLogSingle(function (log) { | ||
return func(log); | ||
}, { | ||
name: options.name, | ||
level: options.level, | ||
message: options.message, | ||
error: options.error == null ? {} : options.error | ||
}); | ||
}, { | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
} | ||
}, { | ||
key: "childOf", | ||
@@ -863,4 +885,3 @@ value: function childOf(span) { | ||
metric = _ref9.metric, | ||
error = _ref9.error, | ||
disableErrorLabel = _ref9.disableErrorLabel; | ||
error = _ref9.error; | ||
var labels = {}; | ||
@@ -875,14 +896,18 @@ var message = messageIn; | ||
if (error != null) { | ||
if (!disableErrorLabel) { | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
} | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[error.level == null ? 'error' : error.level]); | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
var errorLevel = error.level == null ? 'error' : error.level; | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[errorLevel]); | ||
var errorObj = error.error; | ||
if (errorObj != null) { | ||
logLevel = error.level == null ? 'error' : error.level; | ||
var dot = error.message.endsWith('.') ? '' : '.'; | ||
message = "".concat(error.message).concat(dot, " ").concat(errorObj.message); | ||
logLevel = errorLevel; | ||
var errorMessage = error.message; | ||
if (errorMessage == null) { | ||
message = errorMessage; | ||
} else { | ||
var dot = errorMessage.endsWith('.') ? '' : '.'; | ||
message = "".concat(errorMessage).concat(dot, " ").concat(errorObj.message); | ||
} | ||
} | ||
@@ -1004,6 +1029,7 @@ } | ||
var span = this.getSpan(); | ||
var tagLabels = convertTagLabels(labels); | ||
var tracerSpan = span.span; | ||
if (tracerSpan != null) { | ||
var tagLabels = convertTagLabels(labels); | ||
var _arr3 = Object.keys(tagLabels); | ||
@@ -1010,0 +1036,0 @@ |
@@ -428,5 +428,5 @@ 'use strict'; | ||
value: function forRequest(ctx) { | ||
var _withLabels; | ||
var _withLabels, _withLabels$withData; | ||
return this.withLabels((_withLabels = {}, _defineProperty(_withLabels, KNOWN_LABELS.HTTP_METHOD, ctx.method), _defineProperty(_withLabels, KNOWN_LABELS.SPAN_KIND, 'server'), _withLabels)).withData(_defineProperty({}, KNOWN_LABELS.HTTP_URL, ctx.originalUrl || ctx.url)); | ||
return this.withLabels((_withLabels = {}, _defineProperty(_withLabels, KNOWN_LABELS.HTTP_METHOD, ctx.method), _defineProperty(_withLabels, KNOWN_LABELS.SPAN_KIND, 'server'), _withLabels)).withData((_withLabels$withData = {}, _defineProperty(_withLabels$withData, KNOWN_LABELS.HTTP_URL, ctx.originalUrl || ctx.url), _defineProperty(_withLabels$withData, KNOWN_LABELS.HTTP_PATH, ctx.path), _withLabels$withData)); | ||
} | ||
@@ -598,3 +598,3 @@ }, { | ||
type: 'counter', | ||
suffix: 'error_total' | ||
suffix: 'total' | ||
} : metric, | ||
@@ -605,4 +605,3 @@ error: { | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -633,4 +632,3 @@ } | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -762,3 +760,8 @@ } | ||
value: function captureSpan(func, options) { | ||
var span = this.startSpan(options); | ||
var span = this.startSpan({ | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
@@ -786,2 +789,21 @@ try { | ||
}, { | ||
key: "captureSpanLog", | ||
value: function captureSpanLog(func, options) { | ||
return this.captureSpan(function (span) { | ||
return span.captureLogSingle(function (log) { | ||
return func(log); | ||
}, { | ||
name: options.name, | ||
level: options.level, | ||
message: options.message, | ||
error: options.error == null ? {} : options.error | ||
}); | ||
}, { | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
} | ||
}, { | ||
key: "childOf", | ||
@@ -869,4 +891,3 @@ value: function childOf(span) { | ||
metric = _ref9.metric, | ||
error = _ref9.error, | ||
disableErrorLabel = _ref9.disableErrorLabel; | ||
error = _ref9.error; | ||
var labels = {}; | ||
@@ -881,14 +902,18 @@ var message = messageIn; | ||
if (error != null) { | ||
if (!disableErrorLabel) { | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
} | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[error.level == null ? 'error' : error.level]); | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
var errorLevel = error.level == null ? 'error' : error.level; | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[errorLevel]); | ||
var errorObj = error.error; | ||
if (errorObj != null) { | ||
logLevel = error.level == null ? 'error' : error.level; | ||
var dot = error.message.endsWith('.') ? '' : '.'; | ||
message = "".concat(error.message).concat(dot, " ").concat(errorObj.message); | ||
logLevel = errorLevel; | ||
var errorMessage = error.message; | ||
if (errorMessage == null) { | ||
message = errorMessage; | ||
} else { | ||
var dot = errorMessage.endsWith('.') ? '' : '.'; | ||
message = "".concat(errorMessage).concat(dot, " ").concat(errorObj.message); | ||
} | ||
} | ||
@@ -1010,6 +1035,7 @@ } | ||
var span = this.getSpan(); | ||
var tagLabels = convertTagLabels(labels); | ||
var tracerSpan = span.span; | ||
if (tracerSpan != null) { | ||
var tagLabels = convertTagLabels(labels); | ||
var _arr3 = Object.keys(tagLabels); | ||
@@ -1016,0 +1042,0 @@ |
@@ -263,3 +263,4 @@ import opentracing from 'opentracing'; | ||
}).withData({ | ||
[KNOWN_LABELS.HTTP_URL]: ctx.originalUrl || ctx.url | ||
[KNOWN_LABELS.HTTP_URL]: ctx.originalUrl || ctx.url, | ||
[KNOWN_LABELS.HTTP_PATH]: ctx.path | ||
}); | ||
@@ -424,3 +425,3 @@ } | ||
type: 'counter', | ||
suffix: 'error_total' | ||
suffix: 'total' | ||
} : metric, | ||
@@ -431,4 +432,3 @@ error: { | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -459,4 +459,3 @@ } | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -585,3 +584,8 @@ } | ||
captureSpan(func, options) { | ||
const span = this.startSpan(options); | ||
const span = this.startSpan({ | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
@@ -609,2 +613,16 @@ try { | ||
captureSpanLog(func, options) { | ||
return this.captureSpan(span => span.captureLogSingle(log => func(log), { | ||
name: options.name, | ||
level: options.level, | ||
message: options.message, | ||
error: options.error == null ? {} : options.error | ||
}), { | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
} | ||
childOf(span) { | ||
@@ -681,4 +699,3 @@ if (span == null) { | ||
metric, | ||
error, | ||
disableErrorLabel | ||
error | ||
}) { | ||
@@ -694,8 +711,6 @@ let labels = {}; | ||
if (error != null) { | ||
if (!disableErrorLabel) { | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
} | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[error.level == null ? 'error' : error.level]); | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
const errorLevel = error.level == null ? 'error' : error.level; | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[errorLevel]); | ||
const { | ||
@@ -706,5 +721,13 @@ error: errorObj | ||
if (errorObj != null) { | ||
logLevel = error.level == null ? 'error' : error.level; | ||
const dot = error.message.endsWith('.') ? '' : '.'; | ||
message = `${error.message}${dot} ${errorObj.message}`; | ||
logLevel = errorLevel; | ||
const { | ||
message: errorMessage | ||
} = error; | ||
if (errorMessage == null) { | ||
message = errorMessage; | ||
} else { | ||
const dot = errorMessage.endsWith('.') ? '' : '.'; | ||
message = `${errorMessage}${dot} ${errorObj.message}`; | ||
} | ||
} | ||
@@ -824,3 +847,2 @@ } | ||
const span = this.getSpan(); | ||
const tagLabels = convertTagLabels(labels); | ||
const { | ||
@@ -831,2 +853,4 @@ span: tracerSpan | ||
if (tracerSpan != null) { | ||
const tagLabels = convertTagLabels(labels); | ||
for (const key of Object.keys(tagLabels)) { | ||
@@ -833,0 +857,0 @@ if (tagLabels[key] != null) { |
@@ -269,3 +269,4 @@ 'use strict'; | ||
}).withData({ | ||
[KNOWN_LABELS.HTTP_URL]: ctx.originalUrl || ctx.url | ||
[KNOWN_LABELS.HTTP_URL]: ctx.originalUrl || ctx.url, | ||
[KNOWN_LABELS.HTTP_PATH]: ctx.path | ||
}); | ||
@@ -430,3 +431,3 @@ } | ||
type: 'counter', | ||
suffix: 'error_total' | ||
suffix: 'total' | ||
} : metric, | ||
@@ -437,4 +438,3 @@ error: { | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -465,4 +465,3 @@ } | ||
level: errorLevel | ||
}, | ||
disableErrorLabel: true | ||
} | ||
}); | ||
@@ -591,3 +590,8 @@ } | ||
captureSpan(func, options) { | ||
const span = this.startSpan(options); | ||
const span = this.startSpan({ | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
@@ -615,2 +619,16 @@ try { | ||
captureSpanLog(func, options) { | ||
return this.captureSpan(span => span.captureLogSingle(log => func(log), { | ||
name: options.name, | ||
level: options.level, | ||
message: options.message, | ||
error: options.error == null ? {} : options.error | ||
}), { | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references | ||
}); | ||
} | ||
childOf(span) { | ||
@@ -687,4 +705,3 @@ if (span == null) { | ||
metric, | ||
error, | ||
disableErrorLabel | ||
error | ||
}) { | ||
@@ -700,8 +717,6 @@ let labels = {}; | ||
if (error != null) { | ||
if (!disableErrorLabel) { | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
} | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[error.level == null ? 'error' : error.level]); | ||
labels = _objectSpread({}, labels); | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
const errorLevel = error.level == null ? 'error' : error.level; | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[errorLevel]); | ||
const { | ||
@@ -712,5 +727,13 @@ error: errorObj | ||
if (errorObj != null) { | ||
logLevel = error.level == null ? 'error' : error.level; | ||
const dot = error.message.endsWith('.') ? '' : '.'; | ||
message = `${error.message}${dot} ${errorObj.message}`; | ||
logLevel = errorLevel; | ||
const { | ||
message: errorMessage | ||
} = error; | ||
if (errorMessage == null) { | ||
message = errorMessage; | ||
} else { | ||
const dot = errorMessage.endsWith('.') ? '' : '.'; | ||
message = `${errorMessage}${dot} ${errorObj.message}`; | ||
} | ||
} | ||
@@ -830,3 +853,2 @@ } | ||
const span = this.getSpan(); | ||
const tagLabels = convertTagLabels(labels); | ||
const { | ||
@@ -837,2 +859,4 @@ span: tracerSpan | ||
if (tracerSpan != null) { | ||
const tagLabels = convertTagLabels(labels); | ||
for (const key of Object.keys(tagLabels)) { | ||
@@ -839,0 +863,0 @@ if (tagLabels[key] != null) { |
{ | ||
"name": "@neo-one/monitor", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "neo", |
@@ -7,3 +7,5 @@ /* @flow */ | ||
CaptureLogSingleOptions, | ||
CaptureMonitor, | ||
CaptureSpanOptions, | ||
CaptureSpanLogOptions, | ||
Counter, | ||
@@ -198,3 +200,2 @@ Format, | ||
// eslint-disable-next-line | ||
constructor(span: SpanContext | MonitorBase) { | ||
@@ -321,2 +322,3 @@ this._span = span; | ||
[KNOWN_LABELS.HTTP_URL]: ctx.originalUrl || ctx.url, | ||
[KNOWN_LABELS.HTTP_PATH]: ctx.path, | ||
}); | ||
@@ -343,3 +345,3 @@ } | ||
captureLog( | ||
func: (monitor: Monitor) => $FlowFixMe, | ||
func: (monitor: CaptureMonitor) => $FlowFixMe, | ||
options: CaptureLogOptions, | ||
@@ -399,3 +401,3 @@ ): $FlowFixMe { | ||
captureLogSingle( | ||
func: (monitor: Monitor) => $FlowFixMe, | ||
func: (monitor: CaptureMonitor) => $FlowFixMe, | ||
options: CaptureLogSingleOptions, | ||
@@ -471,7 +473,6 @@ ): $FlowFixMe { | ||
type: 'counter', | ||
suffix: 'error_total', | ||
suffix: 'total', | ||
} | ||
: metric, | ||
error: { error, message, level: errorLevel }, | ||
disableErrorLabel: true, | ||
}); | ||
@@ -492,3 +493,2 @@ } | ||
error: { error, message, level: errorLevel }, | ||
disableErrorLabel: true, | ||
}); | ||
@@ -613,6 +613,11 @@ } | ||
captureSpan( | ||
func: (span: Span) => $FlowFixMe, | ||
func: (span: CaptureMonitor) => $FlowFixMe, | ||
options: CaptureSpanOptions, | ||
): $FlowFixMe { | ||
const span = this.startSpan(options); | ||
const span = this.startSpan({ | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references, | ||
}); | ||
try { | ||
@@ -641,2 +646,23 @@ const result = func(span); | ||
captureSpanLog( | ||
func: (span: CaptureMonitor) => $FlowFixMe, | ||
options: CaptureSpanLogOptions, | ||
): $FlowFixMe { | ||
return this.captureSpan( | ||
span => | ||
span.captureLogSingle(log => func(log), { | ||
name: options.name, | ||
level: options.level, | ||
message: options.message, | ||
error: options.error == null ? {} : options.error, | ||
}), | ||
{ | ||
name: options.name, | ||
level: options.level, | ||
help: options.help, | ||
references: options.references, | ||
}, | ||
); | ||
} | ||
childOf(span: SpanContext | Monitor | void): $FlowFixMe { | ||
@@ -712,7 +738,3 @@ if (span == null) { | ||
error, | ||
disableErrorLabel, | ||
}: {| | ||
...CommonLogOptions, | ||
disableErrorLabel?: boolean, | ||
|}): void { | ||
}: CommonLogOptions): void { | ||
let labels = {}; | ||
@@ -724,13 +746,9 @@ let message = messageIn; | ||
if (error != null) { | ||
if (!disableErrorLabel) { | ||
labels = { ...labels }; | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
} | ||
metricLevel = Math.min( | ||
metricLevel, | ||
LOG_LEVEL_TO_LEVEL[error.level == null ? 'error' : error.level], | ||
); | ||
labels = { ...labels }; | ||
labels[KNOWN_LABELS.ERROR] = error.error != null; | ||
const errorLevel = error.level == null ? 'error' : error.level; | ||
metricLevel = Math.min(metricLevel, LOG_LEVEL_TO_LEVEL[errorLevel]); | ||
const { error: errorObj } = error; | ||
if (errorObj != null) { | ||
logLevel = error.level == null ? 'error' : error.level; | ||
logLevel = errorLevel; | ||
const { message: errorMessage } = error; | ||
@@ -857,5 +875,5 @@ if (errorMessage == null) { | ||
const span = this.getSpan(); | ||
const tagLabels = convertTagLabels(labels); | ||
const { span: tracerSpan } = span; | ||
if (tracerSpan != null) { | ||
const tagLabels = convertTagLabels(labels); | ||
for (const key of Object.keys(tagLabels)) { | ||
@@ -862,0 +880,0 @@ if (tagLabels[key] != null) { |
@@ -156,2 +156,13 @@ /* @flow */ | ||
export type CaptureSpanLogOptions = {| | ||
name: string, | ||
message?: string, | ||
level?: LogLevelOption, | ||
help?: string, | ||
error?: CaptureErrorOptions, | ||
references?: Array<Reference | void>, | ||
|}; | ||
export interface Counter { | ||
@@ -265,7 +276,9 @@ inc(count?: number): void; | ||
captureLog<TResult>( | ||
func: (monitor: Monitor) => TResult, | ||
// eslint-disable-next-line | ||
func: (monitor: CaptureMonitor) => TResult, | ||
options: CaptureLogOptions, | ||
): TResult; | ||
captureLog<TResult>( | ||
func: (monitor: Monitor) => Promise<TResult>, | ||
// eslint-disable-next-line | ||
func: (monitor: CaptureMonitor) => Promise<TResult>, | ||
options: CaptureLogOptions, | ||
@@ -275,7 +288,9 @@ ): Promise<TResult>; | ||
captureLogSingle<TResult>( | ||
func: (monitor: Monitor) => TResult, | ||
// eslint-disable-next-line | ||
func: (monitor: CaptureMonitor) => TResult, | ||
options: CaptureLogSingleOptions, | ||
): TResult; | ||
captureLogSingle<TResult>( | ||
func: (monitor: Monitor) => Promise<TResult>, | ||
// eslint-disable-next-line | ||
func: (monitor: CaptureMonitor) => Promise<TResult>, | ||
options: CaptureLogSingleOptions, | ||
@@ -295,3 +310,3 @@ ): Promise<TResult>; | ||
// eslint-disable-next-line | ||
func: (span: Span) => TResult, | ||
func: (span: CaptureMonitor) => TResult, | ||
options: CaptureSpanOptions, | ||
@@ -301,5 +316,15 @@ ): TResult; | ||
// eslint-disable-next-line | ||
func: (span: Span) => Promise<TResult>, | ||
func: (span: CaptureMonitor) => Promise<TResult>, | ||
options: CaptureSpanOptions, | ||
): Promise<TResult>; | ||
captureSpanLog<TResult>( | ||
// eslint-disable-next-line | ||
func: (span: CaptureMonitor) => TResult, | ||
options: CaptureSpanLogOptions, | ||
): TResult; | ||
captureSpanLog<TResult>( | ||
// eslint-disable-next-line | ||
func: (span: CaptureMonitor) => Promise<TResult>, | ||
options: CaptureSpanLogOptions, | ||
): Promise<TResult>; | ||
@@ -324,6 +349,9 @@ childOf(span: SpanContext | Monitor): Reference; | ||
export interface Span extends Monitor { | ||
export interface CaptureMonitor extends Monitor { | ||
setLabels(labels: Labels): void; | ||
setData(data: Labels): void; | ||
} | ||
export interface Span extends CaptureMonitor { | ||
end(error?: boolean): void; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
434951
5498