Global

Members

NODEJS_DEFAULT_LIBRARY_VERSION

Default library version to be used Using release-please annotations to update DEFAULT_INSTRUMENTATION_VERSION with latest version. See https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files

W3C_TRACE_PARENT_HEADER

Header that carries span context across W3C compliant infrastructure.

X_CLOUD_TRACE_HEADER

Header that carries span context across Google infrastructure.

(constant) entry_1

Common construct and functions used by both Log and LogSync

(constant) gapicConfig

Client JSON configuration object, loaded from src/v2/config_service_v2_client_config.json. This file defines retry strategy and timeouts for all API methods in this library.

(constant) gapicConfig

Client JSON configuration object, loaded from src/v2/logging_service_v2_client_config.json. This file defines retry strategy and timeouts for all API methods in this library.

(constant) gapicConfig

Client JSON configuration object, loaded from src/v2/metrics_service_v2_client_config.json. This file defines retry strategy and timeouts for all API methods in this library.

v2

Reference to the low-level auto-generated clients for the V2 Logging service.

Properties:
Name Type Description
LoggingServiceV2Client constructor

Reference to v2.LoggingServiceV2Client

ConfigServiceV2Client constructor

Reference to v2.ConfigServiceV2Client

MetricsServiceV2Client constructor

Reference to v2.MetricsServiceV2Client

Methods

createDiagnosticEntry(libraryName, libraryVersion) → {Entry}

The helper method to generate a log entry with diagnostic instrumentation data.

Parameters:
Name Type Description
libraryName string

The name of the logging library to be reported. Should be prefixed with 'nodejs'. Will be truncated if longer than 14 characters.

libraryVersion string

The version of the logging library to be reported. Will be truncated if longer than 14 characters.

Returns:
Type Description
Entry

The entry with diagnostic instrumentation data.

decodeValue(value) → {*}

Decode a protobuf Struct's value.

Parameters:
Name Type Description
value object

A Struct's Field message.

Returns:
Type Description
*
  • The decoded value.

(async) detectServiceContext()

For logged errors, users can provide a service context. This enables errors to be picked up Cloud Error Reporting. For more information see this guide and the official documentation.

formatLogName(projectId, name)

Format the name of a log. A log's full name is in the format of 'projects/{projectId}/logs/{logName}'.

Parameters:
Name Type Description
projectId
name

(async) getCloudFunctionDescriptor() → {object}

Create a descriptor for Cloud Functions.

Returns:
Type Description
object

(async) getCloudRunDescriptor() → {object}

Create a descriptor for Cloud Run.

Returns:
Type Description
object

getContextFromOtelContext(projectId)

getContextFromOtelContext looks for the active open telemetry span context per Open Telemetry specifications for tracing contexts.

Parameters:
Name Type Description
projectId

getContextFromTraceParent(headerWrapper, projectId)

getOrInjectTraceParent looks for the HTTP header 'traceparent' per W3C specifications for OpenTelemetry and OpenCensus Read more about W3C protocol: https://www.w3.org/TR/trace-context/

Parameters:
Name Type Description
headerWrapper
projectId

getContextFromXCloudTrace(headerWrapper, projectId)

getContextFromXCloudTrace looks for the HTTP header 'x-cloud-trace-context' per Google Cloud specifications for Cloud Tracing.

Parameters:
Name Type Description
headerWrapper
projectId

(async) getDefaultResource()

Attempt to contact the metadata service and determine, based on request success and environment variables, what type of resource the library is operating on.

(async) getGAEDescriptor() → {object}

Create a descriptor for Google App Engine.

Returns:
Type Description
object

(async) getGCEDescriptor() → {object}

Create a descriptor for Google Compute Engine.

Returns:
Type Description
object

(async) getGKEDescriptor() → {object}

Create a descriptor for Google Container Engine.

Returns:
Type Description
object

getGlobalDescriptor() → {object}

Create a global descriptor.

Returns:
Type Description
object

getNodejsLibraryVersion() → {string}

The helper function to retrieve current library version from annotated NODEJS_DEFAULT_LIBRARY_VERSION

Returns:
Type Description
string

A current library version.

getOrInjectContext(req, projectId, inject)

getOrInjectContext returns a CloudTraceContext with as many available trace and span properties as possible. It examines HTTP headers for trace context. Optionally, it can inject a Google compliant trace context when no context is available from headers.

Parameters:
Name Type Description
req
projectId
inject

isRawHttpRequest(req)

isRawHttpRequest detects whether a request object extends the http.IncomingMessage class. It should return true on HTTP compliant requests and all requests created by an http.Server.

Parameters:
Name Type Description
req

isValidInfo(info)

The helper function which checks if given InstrumentationInfo is valid.

Parameters:
Name Type Description
info InstrumentationInfo

The info to be validated.

Returns:
Type Description

true if given info is valid, false otherwise

makeCloudTraceHeader()

makeCloudTraceHeader generates valid X-Cloud-Trace-Context trace and spanId.

makeHeaderWrapper(req)

makeHeaderWrapper returns a wrapper with set and get header functionality, returning null if the incoming request object doesn't contain the 'header' propery.

Parameters:
Name Type Description
req

makeHttpRequestData(req, res, latencyMilliseconds)

makeHttpRequestData turns raw incoming HTTPRequests into structured HTTPRequest objects interpreted by Cloud Logging.

Parameters:
Name Type Description
req
res
latencyMilliseconds

makeMiddleware(projectId, makeChildLogger, emitRequestLog)

Generates an express middleware that installs a request-specific logger on the request object. It optionally can do HttpRequest timing that can be used for generating request logs. This can be used to integrate with logging libraries such as winston and bunyan.

Parameters:
Name Type Description
projectId

Generated traceIds will be associated with this project.

makeChildLogger

A function that generates logger instances that will be installed onto req as req.log. The logger should include the trace in each log entry's metadata (associated with the LOGGING_TRACE_KEY property.

emitRequestLog

Optional. A function that will emit a parent request log. While some environments like GAE and GCF emit parent request logs automatically, other environments do not. When provided this function will be called with a populated CloudLoggingHttpRequest which can be emitted as request log.

parseTraceParentHeader(headerWrapper)

parseTraceParentHeader is a custom implementation of the parseTraceParent function in @opentelemetry-core/trace. For more information see https://www.w3.org/TR/trace-context/

Parameters:
Name Type Description
headerWrapper

parseXCloudTraceHeader(headerWrapper)

parseXCloudTraceHeader looks for trace context in X-Cloud-Trace-Context header

Parameters:
Name Type Description
headerWrapper

populateInstrumentationInfo(entry)

This method helps to populate entries with instrumentation data

Parameters:
Name Type Description
entry Entry

The entry or array of entries to be populated with instrumentation info

Returns:
Type Description

[Entry[], boolean] Array of entries which contains an entry with current library instrumentation info and boolean flag indicating if instrumentation was added or not in this call

setInstrumentationStatus(value)

The helper method used to set a status of a flag which indicates if instrumentation info already written or not.

Parameters:
Name Type Description
value boolean

The value to be set.

Returns:
Type Description

The value of the flag before it is set.

snakecaseKeys(labels)

snakecaseKeys turns label keys from camel case to snake case.

Parameters:
Name Type Description
labels

toCloudTraceContext(anyContext, context, projectId)

toCloudTraceContext converts any context format to cloudTraceContext format.

Parameters:
Name Type Description
anyContext
context
projectId

toNanosAndSecondsObj(date)

Converts Date to nanoseconds format suported by Logging. See https://cloud.google.com/logging/docs/agent/logging/configuration#timestamp-processing for more details

Parameters:
Name Type Description
date

The date to be converted to Logging nanos and seconds format

truncateValue(value, maxLen) → {string}

A helper function to truncate a value (library name or version for example). The value is truncated when it is longer than {maxLen} chars and '*' is added instead of truncated suffix.

Parameters:
Name Type Description
value object | string

The value to be truncated.

maxLen number

The max length to be used for truncation.

Returns:
Type Description
string

The truncated value.

validateAndUpdateInstrumentation(infoList) → {InstrumentationInfo}

This method validates that provided instrumentation info list is valid and also adds current library info to a list.

Parameters:
Name Type Description
infoList InstrumentationInfo

The array of InstrumentationInfo to be validated and updated.

Returns:
Type Description
InstrumentationInfo

The updated list of InstrumentationInfo.

zuluToDateObj(zuluTime)

zuluToDateObj RFC3339 "Zulu" timestamp into a format that can be parsed to a JS Date Object.

Parameters:
Name Type Description
zuluTime

Type Definitions

ClientConfig

Properties:
Name Type Attributes Default Description
projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option above is not necessary. NOTE: .pem and .p12 require you to specify the email option as well.

email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
autoRetry boolean <optional>
true

Automatically retry requests if the response is related to rate limits or certain intermittent server errors. We will exponentially backoff subsequent requests by default.

maxRetries number <optional>
3

Maximum number of automatic retries attempted before returning the error.

promise Constructor <optional>

Custom promise module to use instead of native Promises.

TailEntriesRequest

Query object for streaming entries.

Properties:
Name Type Attributes Default Description
resourceNames Array.<string> | string <optional>

Names of project resources to stream logs out of.

filter string <optional>

An advanced logs filter. An empty filter matches all log entries.

bufferWindow number <optional>
2

A setting to balance the tradeoff between viewing the log entries as they are being written and viewing them in ascending order.

log string <optional>

A name of the log specifying to only return entries from this log.

gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.