Skip to content

Commit a4cdf49

Browse files
draffenspergerstephenplusplus
authored andcommitted
Export trace key in logging-{winston,bunyan} (#2602)
* Export trace key in logging-{winston,bunyan} * Fix var to const
1 parent fd9df2a commit a4cdf49

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

packages/logging-bunyan/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,4 @@ LoggingBunyan.prototype._writev = function(chunks, callback) {
271271

272272
module.exports = LoggingBunyan;
273273
module.exports.BUNYAN_TO_STACKDRIVER = BUNYAN_TO_STACKDRIVER;
274+
module.exports.LOGGING_TRACE_KEY = LOGGING_TRACE_KEY;

packages/logging-bunyan/test/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,8 @@ describe('logging-bunyan', function() {
233233
});
234234

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

240239
loggingBunyan.log_.entry = function(entryMetadata, record) {
241240
assert.deepStrictEqual(entryMetadata, {
@@ -248,7 +247,7 @@ describe('logging-bunyan', function() {
248247
done();
249248
};
250249

251-
loggingBunyan.formatEntry_(recordWithRequest);
250+
loggingBunyan.formatEntry_(recordWithTrace);
252251
});
253252
});
254253

@@ -285,9 +284,9 @@ describe('logging-bunyan', function() {
285284
getWriterProjectId: function() { return 'project1'; }
286285
};
287286
const recordWithoutTrace = extend({}, RECORD);
288-
const recordWithTrace = extend({
289-
'logging.googleapis.com/trace': 'projects/project1/traces/trace1'
290-
}, RECORD);
287+
const recordWithTrace = extend({}, RECORD);
288+
recordWithTrace[LoggingBunyan.LOGGING_TRACE_KEY] =
289+
'projects/project1/traces/trace1';
291290

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

308307
it('should leave prefixed trace property as is if set', function(done) {
309-
var oldTraceAgent = global._google_trace_agent;
308+
const oldTraceAgent = global._google_trace_agent;
310309
global._google_trace_agent = {
311310
getCurrentContextId: function() { return 'trace-from-agent'; },
312311
getWriterProjectId: function() { return 'project1'; }
313312
};
314-
const recordWithTraceAlreadySet = extend({
315-
'logging.googleapis.com/trace': 'trace-already-set'
316-
}, RECORD);
313+
const recordWithTraceAlreadySet = extend({}, RECORD);
314+
recordWithTraceAlreadySet[LoggingBunyan.LOGGING_TRACE_KEY] = 'trace1';
317315

318316
FakeWritable.prototype.write = function(record, encoding, callback) {
319317
assert.deepStrictEqual(record, recordWithTraceAlreadySet);

packages/logging-winston/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,6 @@ LoggingWinston.prototype.log = function(levelName, msg, metadata, callback) {
249249
this.log_[stackdriverLevel](entry, callback);
250250
};
251251

252+
LoggingWinston.LOGGING_TRACE_KEY = LOGGING_TRACE_KEY;
253+
252254
module.exports = LoggingWinston;

packages/logging-winston/test/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ describe('logging-winston', function() {
319319
});
320320

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

326325
loggingWinston.log_.entry = function(entryMetadata, data) {
327326
assert.deepStrictEqual(entryMetadata, {

0 commit comments

Comments
 (0)