Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/logging-bunyan/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,4 @@ LoggingBunyan.prototype._writev = function(chunks, callback) {

module.exports = LoggingBunyan;
module.exports.BUNYAN_TO_STACKDRIVER = BUNYAN_TO_STACKDRIVER;
module.exports.LOGGING_TRACE_KEY = LOGGING_TRACE_KEY;
20 changes: 9 additions & 11 deletions packages/logging-bunyan/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ describe('logging-bunyan', function() {
});

it('should promote prefixed trace property to metadata', function(done) {
var recordWithRequest = extend({
'logging.googleapis.com/trace': 'trace1'
}, RECORD);
const recordWithTrace = extend({}, RECORD);
recordWithTrace[LoggingBunyan.LOGGING_TRACE_KEY] = 'trace1';

loggingBunyan.log_.entry = function(entryMetadata, record) {
assert.deepStrictEqual(entryMetadata, {
Expand All @@ -248,7 +247,7 @@ describe('logging-bunyan', function() {
done();
};

loggingBunyan.formatEntry_(recordWithRequest);
loggingBunyan.formatEntry_(recordWithTrace);
});
});

Expand Down Expand Up @@ -285,9 +284,9 @@ describe('logging-bunyan', function() {
getWriterProjectId: function() { return 'project1'; }
};
const recordWithoutTrace = extend({}, RECORD);
const recordWithTrace = extend({
'logging.googleapis.com/trace': 'projects/project1/traces/trace1'
}, RECORD);
const recordWithTrace = extend({}, RECORD);
recordWithTrace[LoggingBunyan.LOGGING_TRACE_KEY] =
'projects/project1/traces/trace1';

FakeWritable.prototype.write = function(record, encoding, callback) {
// Check that trace field added to record before calling Writable.write
Expand All @@ -306,14 +305,13 @@ describe('logging-bunyan', function() {
});

it('should leave prefixed trace property as is if set', function(done) {
var oldTraceAgent = global._google_trace_agent;
const oldTraceAgent = global._google_trace_agent;
global._google_trace_agent = {
getCurrentContextId: function() { return 'trace-from-agent'; },
getWriterProjectId: function() { return 'project1'; }
};
const recordWithTraceAlreadySet = extend({
'logging.googleapis.com/trace': 'trace-already-set'
}, RECORD);
const recordWithTraceAlreadySet = extend({}, RECORD);
recordWithTraceAlreadySet[LoggingBunyan.LOGGING_TRACE_KEY] = 'trace1';

FakeWritable.prototype.write = function(record, encoding, callback) {
assert.deepStrictEqual(record, recordWithTraceAlreadySet);
Expand Down
2 changes: 2 additions & 0 deletions packages/logging-winston/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,6 @@ LoggingWinston.prototype.log = function(levelName, msg, metadata, callback) {
this.log_[stackdriverLevel](entry, callback);
};

LoggingWinston.LOGGING_TRACE_KEY = LOGGING_TRACE_KEY;

module.exports = LoggingWinston;
5 changes: 2 additions & 3 deletions packages/logging-winston/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ describe('logging-winston', function() {
});

it('should promote prefixed trace property to metadata', function(done) {
const metadataWithTrace = extend({
'logging.googleapis.com/trace': 'trace1'
}, METADATA);
const metadataWithTrace = extend({}, METADATA);
metadataWithTrace[LoggingWinston.LOGGING_TRACE_KEY] = 'trace1';

loggingWinston.log_.entry = function(entryMetadata, data) {
assert.deepStrictEqual(entryMetadata, {
Expand Down