Skip to content

Commit

Permalink
fix: improve diagnostics log entry
Browse files Browse the repository at this point in the history
Change-Id: Iff2622908b239aef859175ba285f18ac629958f2
GitOrigin-RevId: 285ffdc32b889ae7d1fb76cab0212f89a25f5a3a
  • Loading branch information
nielm authored and Copybara committed Nov 5, 2024
1 parent dd066a2 commit feb5f93
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions projects/pino-logging-gcp-config/src/pino_gcp_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import {
detectServiceContext,
} from '@google-cloud/logging';
import {
setInstrumentationStatus,
createDiagnosticEntry,
DIAGNOSTIC_INFO_KEY,
populateInstrumentationInfo,
} from '@google-cloud/logging/build/src/utils/instrumentation';
import * as gax from 'google-gax';

Expand All @@ -41,8 +42,8 @@ const eventId = new EventId();
* See
* https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files
*/
const NODEJS_GCP_PINO_LIBRARY_VERSION = '1.0.0'; // {x-release-please-version}
const NODEJS_GCP_PINO_LIBRARY_NAME = 'nodejs-gcp-pino';
const NODEJS_GCP_PINO_LIBRARY_VERSION = '1.0.1'; // {x-release-please-version}
const NODEJS_GCP_PINO_LIBRARY_NAME = 'nodejs-gcppino';

const PINO_TO_GCP_LOG_LEVELS = Object.freeze(
Object.fromEntries([
Expand Down Expand Up @@ -129,22 +130,25 @@ class GcpLoggingPino {
* with a line of the form cloud-solutions/pino-logging-gcp-config-v1.0.0
*/
outputDiagnosticEntry() {
const alreadyWritten = setInstrumentationStatus(true);
if (alreadyWritten) {
return;
}
const instrumentationEntry = createDiagnosticEntry(
const diagEntry = createDiagnosticEntry(
NODEJS_GCP_PINO_LIBRARY_NAME,
NODEJS_GCP_PINO_LIBRARY_VERSION
);
diagEntry.data[DIAGNOSTIC_INFO_KEY].runtime = process.version;

const [entries, isInfoAdded] = populateInstrumentationInfo(diagEntry);
if (!isInfoAdded || entries.length === 0) {
return;
}
pino.version;
// Create a temp pino logger instance just to log this diagnostic entry.
pino
.pino({
level: 'info',
...this.getPinoLoggerOptions(),
})
.info({
...instrumentationEntry.data,
...diagEntry.data,
});
}

Expand Down

0 comments on commit feb5f93

Please sign in to comment.