diff --git a/tutorials/cloud-iot-logging/functions/package.json b/tutorials/cloud-iot-logging/functions/package.json index f7032d6cbc..723fa53479 100644 --- a/tutorials/cloud-iot-logging/functions/package.json +++ b/tutorials/cloud-iot-logging/functions/package.json @@ -19,8 +19,8 @@ "main": "lib/index.js", "dependencies": { "@google-cloud/logging": "^1.2.0", - "firebase-admin": "^5.11.0", - "firebase-functions": "^1.0.2", + "firebase-admin": "^9.2.0", + "firebase-functions": "^3.11.0", "googleapis": "^39.1.0" }, "devDependencies": { diff --git a/tutorials/cloud-iot-logging/functions/src/index.ts b/tutorials/cloud-iot-logging/functions/src/index.ts index 506ac2cea9..37456cb6f7 100644 --- a/tutorials/cloud-iot-logging/functions/src/index.ts +++ b/tutorials/cloud-iot-logging/functions/src/index.ts @@ -18,17 +18,14 @@ 'use strict'; import * as functions from 'firebase-functions'; -const loggingClient = require('@google-cloud/logging'); +const { Logging } = require('@google-cloud/logging'); -import { runInDebugContext } from 'vm'; - -// create the Stackdriver Logging client -const logging = new loggingClient({ +// create the Cloud Logging client +const logging = new Logging({ projectId: process.env.GCLOUD_PROJECT, }); // start cloud function - exports.deviceLog = functions.pubsub.topic('device-logs').onPublish((message) => { const log = logging.log('device-logs'); @@ -42,13 +39,13 @@ exports.deviceLog = device_num_id: message.attributes.deviceNumId, device_registry_id: message.attributes.deviceRegistryId, location: message.attributes.location, - } + }, }, labels: { // note device_id is not part of the monitored resource, but you can // include it as another log label device_id: message.attributes.deviceId, - } + }, }; const logData = message.json; @@ -56,7 +53,7 @@ exports.deviceLog = // is present const validSeverity = [ 'DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'ALERT', 'CRITICAL', - 'EMERGENCY' + 'EMERGENCY', ]; if (logData.severity && validSeverity.indexOf(logData.severity.toUpperCase()) > -1) { @@ -64,8 +61,8 @@ exports.deviceLog = delete (logData.severity); - // write the log entryto Stackdriver Logging + // write the log entry to Cloud Logging const entry = log.entry(metadata, logData); return log.write(entry); } - }); \ No newline at end of file + }); diff --git a/tutorials/cloud-iot-logging/index.md b/tutorials/cloud-iot-logging/index.md index d33d5f66c7..e088b00998 100644 --- a/tutorials/cloud-iot-logging/index.md +++ b/tutorials/cloud-iot-logging/index.md @@ -78,17 +78,14 @@ The main part of the function handles a Pub/Sub message from IoT Core, extracts [embedmd]:# (functions/src/index.ts /import/ $) ```ts import * as functions from 'firebase-functions'; -const loggingClient = require('@google-cloud/logging'); - -import { runInDebugContext } from 'vm'; +const { Logging } = require('@google-cloud/logging'); // create the Cloud Logging client -const logging = new loggingClient({ +const logging = new Logging({ projectId: process.env.GCLOUD_PROJECT, }); // start cloud function - exports.deviceLog = functions.pubsub.topic('device-logs').onPublish((message) => { const log = logging.log('device-logs'); @@ -102,13 +99,13 @@ exports.deviceLog = device_num_id: message.attributes.deviceNumId, device_registry_id: message.attributes.deviceRegistryId, location: message.attributes.location, - } + }, }, labels: { // note device_id is not part of the monitored resource, but you can // include it as another log label device_id: message.attributes.deviceId, - } + }, }; const logData = message.json; @@ -116,7 +113,7 @@ exports.deviceLog = // is present const validSeverity = [ 'DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'ALERT', 'CRITICAL', - 'EMERGENCY' + 'EMERGENCY', ]; if (logData.severity && validSeverity.indexOf(logData.severity.toUpperCase()) > -1) { @@ -124,7 +121,7 @@ exports.deviceLog = delete (logData.severity); - // write the log entryto Cloud Logging + // write the log entry to Cloud Logging const entry = log.entry(metadata, logData); return log.write(entry); }