nats-hemera
Advanced tools
Comparing version 5.4.9 to 5.5.0
/// <reference types="node" /> | ||
import * as pino from 'pino' | ||
import { Stream } from 'stream'; | ||
import { Stream } from 'stream' | ||
// tslint:disable-next-line:export-just-namespace | ||
export = Hemera; | ||
export as namespace Hemera; | ||
export = Hemera | ||
export as namespace Hemera | ||
@@ -61,2 +61,3 @@ declare namespace Hemera { | ||
load?: LoadConfig | ||
logTraceDetails?: boolean | ||
} | ||
@@ -354,6 +355,14 @@ | ||
// serialization | ||
setClientEncoder(encoder: (message: Object | Buffer) => Hemera.EncoderResult): Hemera | ||
setClientDecoder(encoder: (message: String | Buffer) => Hemera.DecoderResult): Hemera | ||
setServerEncoder(encoder: (message: Object | Buffer) => Hemera.EncoderResult): Hemera | ||
setServerDecoder(encoder: (message: String | Buffer) => Hemera.DecoderResult): Hemera | ||
setClientEncoder( | ||
encoder: (message: Object | Buffer) => Hemera.EncoderResult | ||
): Hemera | ||
setClientDecoder( | ||
encoder: (message: String | Buffer) => Hemera.DecoderResult | ||
): Hemera | ||
setServerEncoder( | ||
encoder: (message: Object | Buffer) => Hemera.EncoderResult | ||
): Hemera | ||
setServerDecoder( | ||
encoder: (message: String | Buffer) => Hemera.DecoderResult | ||
): Hemera | ||
@@ -363,4 +372,8 @@ setSchemaCompiler(compilerFunction: (schema: Object) => Function): Hemera | ||
setResponseSchemaCompiler(compilerFunction: (schema: Object) => Function): Hemera | ||
setResponseSchemaCompiler(compilerFunction: (schema: Object) => Promise<any>): Hemera | ||
setResponseSchemaCompiler( | ||
compilerFunction: (schema: Object) => Function | ||
): Hemera | ||
setResponseSchemaCompiler( | ||
compilerFunction: (schema: Object) => Promise<any> | ||
): Hemera | ||
@@ -367,0 +380,0 @@ setNotFoundPattern(pattern: string | Hemera.ServerPattern | null): void |
@@ -41,2 +41,4 @@ const Joi = require('joi') | ||
), | ||
// Attach trace and request informations to the logs. It costs ~10% perf | ||
traceLog: Joi.boolean().default(false), | ||
// The error serialization options | ||
@@ -43,0 +45,0 @@ errio: Joi.object() |
@@ -86,3 +86,24 @@ 'use strict' | ||
context.emit('clientPreRequest', context) | ||
if (context._config.traceLog) { | ||
context.log = context.log.child({ | ||
requestId: request.id, | ||
parentSpanId: context.trace$.parentSpanId, | ||
traceId: context.trace$.traceId, | ||
spanId: context.trace$.spanId | ||
}) | ||
context.log.info( | ||
{ | ||
pattern: context.trace$.method | ||
}, | ||
'Incoming request' | ||
) | ||
} else { | ||
context.log.info( | ||
{ | ||
requestId: request.id, | ||
pattern: context.trace$.method | ||
}, | ||
'Incoming request' | ||
) | ||
} | ||
@@ -95,3 +116,3 @@ // build msg | ||
trace: context.trace$, | ||
request: request | ||
request | ||
} | ||
@@ -101,5 +122,3 @@ | ||
context.log.debug({ | ||
outbound: context | ||
}) | ||
context.emit('clientPreRequest', context) | ||
@@ -128,3 +147,4 @@ next() | ||
// calculate request duration | ||
let diff = Util.nowHrTime() - context.trace$.timestamp | ||
const now = Util.nowHrTime() | ||
const diff = now - context.trace$.timestamp | ||
context.trace$.duration = diff | ||
@@ -135,5 +155,26 @@ | ||
context.log.debug({ | ||
inbound: context | ||
}) | ||
if (context._config.traceLog) { | ||
context.log = context.log.child({ | ||
requestId: context.request$.id, | ||
parentSpanId: context.trace$.parentSpanId, | ||
traceId: context.trace$.traceId, | ||
spanId: context.trace$.spanId | ||
}) | ||
context.log.info( | ||
{ | ||
pattern: context.trace$.method, | ||
responseTime: context.trace$.duration / 1e6 | ||
}, | ||
'Request completed' | ||
) | ||
} else { | ||
context.log.info( | ||
{ | ||
requestId: context.request$.id, | ||
pattern: context.trace$.method, | ||
responseTime: context.trace$.duration / 1e6 | ||
}, | ||
'Request completed' | ||
) | ||
} | ||
@@ -140,0 +181,0 @@ context.emit('clientPostRequest', context) |
@@ -42,3 +42,2 @@ 'use strict' | ||
const ClientResponse = require('./clientResponse') | ||
const Serializers = require('./serializer') | ||
const ConfigScheme = require('./configScheme') | ||
@@ -215,4 +214,3 @@ const Reply = require('./reply') | ||
safe: true, // handle circular refs | ||
level: this._config.logLevel, | ||
serializers: Serializers | ||
level: this._config.logLevel | ||
} | ||
@@ -219,0 +217,0 @@ if (this._config.logger instanceof Stream) { |
@@ -17,2 +17,4 @@ 'use strict' | ||
const NS_PER_SEC = 1e9 | ||
/** | ||
@@ -98,3 +100,3 @@ * @class Util | ||
const hrtime = process.hrtime() | ||
return +hrtime[0] * 1e9 + +hrtime[1] | ||
return +hrtime[0] * NS_PER_SEC + +hrtime[1] | ||
} | ||
@@ -101,0 +103,0 @@ /** |
{ | ||
"name": "nats-hemera", | ||
"author": "Dustin Deus (https://github.com/StarpTech)", | ||
"version": "5.4.9", | ||
"version": "5.5.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://hemerajs.github.io/hemera/", |
80159
3235
22