Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Sketch out key-value logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bhs committed Sep 3, 2016
1 parent 72945db commit 2e2cb0e
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions src/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,39 +171,41 @@ export default class Span {
}

/**
* Explicitly create a log record associated with the span.
* Add a log record to this Span, optionally at a user-provided timestamp.
*
* @param {object} fields - object containing the log record properties
* @param {number} [fields.timestamp] - optional field specifying the
* timestamp in milliseconds as a Unix timestamp. Fractional values
* are allowed so that timestamps with sub-millisecond accuracy
* can be represented. If not specified, the implementation is
* expected to use it's notion of the current time of the call.
* @param {string} [fields.event] - the event name
* @param {object} [fields.payload] - an arbitrary structured payload. It is
* implementation-dependent how this will be processed.
* @param {object} keyValuePairs
* An object mapping string keys to arbitrary value types. All
* Tracer implementations should support bool, string, and numeric
* value types, and some may also support Object values.
* @param {number} timestamp
* An optional parameter specifying the timestamp in milliseconds
* since the Unix epoch. Fractional values are allowed so that
* timestamps with sub-millisecond accuracy can be represented. If
* not specified, the implementation is expected to use its notion
* of the current time of the call.
*/
log(fields) {
log(keyValuePairs, timestamp) {
// Debug-only runtime checks on the arguments
if (process.env.NODE_ENV === 'debug') {
if (arguments.length !== 1) {
if (arguments.length > 2 || arguments.length === 0) {
throw new Error('Invalid number of arguments');
}
if (typeof fields !== 'object') {
throw new Error('Expected fields to be an object');
if (arguments.length === 2) {
if (typeof timestamp !== 'number') {
throw new Error('Expected timestamp to be a number');
}
}
if (typeof keyValuePairs !== 'object') {
throw new Error('Expected keyValuePairs to be an object');
}
}

this._log(fields);
this._log(keyValuePairs, timestamp);
return this;
}

/**
* Logs a event with an optional payload.
*
* @param {string} eventName - string associated with the log record
* @param {object} [payload] - arbitrary payload object associated with the
* log record.
* DEPRECATED
*/
logEvent(eventName, payload) {
// Debug-only runtime checks on the arguments
Expand Down Expand Up @@ -232,7 +234,7 @@ export default class Span {
* finish() must be the last call made to any span instance, and to do
* otherwise leads to undefined behavior.
*
* @param {Number} finishTime
* @param {number} finishTime
* Optional finish time in milliseconds as a Unix timestamp. Decimal
* values are supported for timestamps with sub-millisecond accuracy.
* If not specified, the current time (as defined by the
Expand Down Expand Up @@ -294,10 +296,7 @@ export default class Span {
}

// By default does nothing
//
// NOTE: both log() and logEvent() map to this function. fields will always
// be an associative array.
_log(fields) {
_log(keyValuePairs, timestamp) {
}

// By default does nothing
Expand Down

0 comments on commit 2e2cb0e

Please sign in to comment.