Detalhes do pacote

@google-cloud/synthetics-sdk-api

GoogleCloudPlatform9.3kApache-2.00.7.0

NodeJS distribution of the API Specification that must be complied with for integrating with Google Cloud Monitoring Synthetics

readme (leia-me)

npm version

Synthetics SDK API

Note: This is an experimental package under active development. New releases may include breaking changes.

Installation

npm install --save @google-cloud/synthetics-sdk-api

Usage With Cloud Function V2

Google Cloud Monitoring Synthetics requires a Cloud Function v2 target, and as such, this guide explains how to set up a simple function that uses the @google-cloud/synthetics-sdk-api package.

$ npm init
$ npm install --save @google-cloud/synthetics-sdk-api
$ npm install --save @google-cloud/functions-framework

# This example uses node-fetch for http requests
$ npm install --save node-fetch

Usage With runSyntheticHandler Middleware

This package provides an easy to use express compatible middleware for writing code that is invoked by Google Cloud Monitoring Synthetics. When a user written function is provided to it, a response is sent that may be consumed by Google's services. The following is an example index.js file that can be used as the entrypoint for a cloud function.

// index.js
const assert = require("node:assert");
const functions = require('@google-cloud/functions-framework');
const fetch = require("node-fetch");
const GcmSynthetics = require('@google-cloud/synthetics-sdk-api');

functions.http('SyntheticFunction', GcmSynthetics.runSyntheticHandler(async () => {
  const url = 'https://www.google.com/'; // URL to send the request to
  return await assert.doesNotReject(fetch(url));
}));

Usage Without Framework

As long as a Google Cloud Function exposes an http endpoint that complies with the API spec as defined in the Synthetics SDK API package, the Cloud Function will work as a target for a Synthetic Monitor. As such, this package includes a proto definition that contains the api spec, as well as typescript types that are generated from that proto.

This is predominantly important if you want to run a programmatic workflow for which other SyntheticSDKs are not a good fit, or if you want to use another language for your Google Cloud function for which there is no direct support.

const functions = require('@google-cloud/functions-framework');
const { SyntheticResult, GenericResultV1 } = require('@google-cloud/synthetics-sdk-api');

Useful Links

changelog (log de mudanças)

Changelog

0.7.0 (2025-06-09)

Features

  • Add screenshot storage support to broken link checker (#123) (cd34e35)

Bug Fixes

  • remove-ts-proto-and-upgrade-puppeteer: Removes unnecessary ts-proto dependency and upgrade puppeteer (#148) (c3c21d7)

0.6.0 (2024-04-18)

Features

  • Update proto to support broken link screenshot support & add getExecutionRegion() functionality (#116) (be413ac)

0.5.1 (2024-01-24)

Bug Fixes

  • Trivial change to trigger api release please (ae59117)

0.5.0 (2023-11-01)

Features

0.4.1 (2023-10-24)

Bug Fixes

  • Trivial change to trigger release please (#69) (f795d59)

0.4.0 (2023-10-13)

Features

  • Makes execution id accessible in the user's code (#58) (78b2162)

0.3.1 (2023-10-12)

Bug Fixes

0.3.0 (2023-09-20)

Features

  • Adds a pathway for automatic instrumentation (84a1bc3)

0.2.0 (2023-08-30)

Features

  • Adds the raw stack trace in the synthetic monitors response (71e6afe)