1 | /*!
|
2 | * Copyright 2015 Google Inc. All Rights Reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | import { google } from '../protos/protos';
|
17 | import { CloudLoggingHttpRequest, RawHttpRequest } from './utils/http-request';
|
18 | export declare const INSERT_ID_KEY = "logging.googleapis.com/insertId";
|
19 | export declare const LABELS_KEY = "logging.googleapis.com/labels";
|
20 | export declare const OPERATION_KEY = "logging.googleapis.com/operation";
|
21 | export declare const SOURCE_LOCATION_KEY = "logging.googleapis.com/sourceLocation";
|
22 | export declare const SPAN_ID_KEY = "logging.googleapis.com/spanId";
|
23 | export declare const TRACE_KEY = "logging.googleapis.com/trace";
|
24 | export declare const TRACE_SAMPLED_KEY = "logging.googleapis.com/trace_sampled";
|
25 | export type Timestamp = google.protobuf.ITimestamp | Date | string;
|
26 | export type LogSeverity = google.logging.type.LogSeverity | string;
|
27 | export type HttpRequest = google.logging.type.IHttpRequest | CloudLoggingHttpRequest | RawHttpRequest;
|
28 | export type LogEntry = Omit<google.logging.v2.ILogEntry, 'timestamp' | 'severity' | 'httpRequest'> & {
|
29 | timestamp?: Timestamp | null;
|
30 | severity?: LogSeverity | null;
|
31 | httpRequest?: HttpRequest | null;
|
32 | };
|
33 | export type Data = any;
|
34 | export interface EntryJson {
|
35 | timestamp: Timestamp;
|
36 | insertId: number;
|
37 | jsonPayload?: google.protobuf.IStruct;
|
38 | textPayload?: string;
|
39 | httpRequest?: google.logging.type.IHttpRequest;
|
40 | trace?: string;
|
41 | spanId?: string;
|
42 | traceSampled?: boolean;
|
43 | }
|
44 | export interface StructuredJson {
|
45 | message?: string | object;
|
46 | httpRequest?: object;
|
47 | timestamp?: Timestamp;
|
48 | [INSERT_ID_KEY]?: string;
|
49 | [OPERATION_KEY]?: object;
|
50 | [SOURCE_LOCATION_KEY]?: object;
|
51 | [LABELS_KEY]?: object;
|
52 | [SPAN_ID_KEY]?: string;
|
53 | [TRACE_KEY]?: string;
|
54 | [TRACE_SAMPLED_KEY]?: boolean;
|
55 | logName?: string;
|
56 | resource?: object;
|
57 | [key: string]: unknown;
|
58 | }
|
59 | export interface ToJsonOptions {
|
60 | removeCircular?: boolean;
|
61 | }
|
62 | /**
|
63 | * Create an entry object to define new data to insert into a meta.
|
64 | *
|
65 | * Note, {@link https://cloud.google.com/logging/quotas|Cloud Logging Quotas and limits}
|
66 | * dictates that the maximum log entry size, including all
|
67 | * {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry|LogEntry Resource properties},
|
68 | * cannot exceed approximately 256 KB.
|
69 | *
|
70 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry|LogEntry JSON representation}
|
71 | *
|
72 | * @class
|
73 | *
|
74 | * @param {?object} [metadata] See a
|
75 | * [LogEntry
|
76 | * Resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).
|
77 | * @param {object|string} data The data to use as the value for this log
|
78 | * entry.
|
79 | *
|
80 | * If providing an object, these value types are supported:
|
81 | * - `String`
|
82 | * - `Number`
|
83 | * - `Boolean`
|
84 | * - `Buffer`
|
85 | * - `Object`
|
86 | * - `Array`
|
87 | *
|
88 | * Any other types are stringified with `String(value)`.
|
89 | *
|
90 | * @example
|
91 | * ```
|
92 | * const {Logging} = require('@google-cloud/logging');
|
93 | * const logging = new Logging();
|
94 | * const syslog = logging.log('syslog');
|
95 | *
|
96 | * const metadata = {
|
97 | * resource: {
|
98 | * type: 'gce_instance',
|
99 | * labels: {
|
100 | * zone: 'global',
|
101 | * instance_id: '3'
|
102 | * }
|
103 | * }
|
104 | * };
|
105 | *
|
106 | * const entry = syslog.entry(metadata, {
|
107 | * delegate: 'my_username'
|
108 | * });
|
109 | *
|
110 | * syslog.alert(entry, (err, apiResponse) => {
|
111 | * if (!err) {
|
112 | * // Log entry inserted successfully.
|
113 | * }
|
114 | * });
|
115 | *
|
116 | * //-
|
117 | * // You will also receive `Entry` objects when using
|
118 | * // Logging#getEntries() and Log#getEntries().
|
119 | * //-
|
120 | * logging.getEntries((err, entries) => {
|
121 | * if (!err) {
|
122 | * // entries[0].data = The data value from the log entry.
|
123 | * }
|
124 | * });
|
125 | * ```
|
126 | */
|
127 | declare class Entry {
|
128 | metadata: LogEntry;
|
129 | data: Data;
|
130 | constructor(metadata?: LogEntry, data?: Data);
|
131 | /**
|
132 | * Serialize an entry to the format the API expects. Read more:
|
133 | * https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
|
134 | *
|
135 | * @param {object} [options] Configuration object.
|
136 | * boolean} [options.removeCircular] Replace circular references in an
{ |
137 | * object with a string value, `[Circular]`.
|
138 | * string} [projectId] GCP Project ID.
{ |
139 | */
|
140 | toJSON(options?: ToJsonOptions, projectId?: string): EntryJson;
|
141 | /**
|
142 | * Serialize an entry to a standard format for any transports, e.g. agents.
|
143 | * Read more: https://cloud.google.com/logging/docs/structured-logging
|
144 | */
|
145 | toStructuredJSON(projectId?: string, useMessageField?: boolean): StructuredJson;
|
146 | /**
|
147 | * extractTraceContext extracts trace and span information from OpenTelemetry
|
148 | * span context or raw HTTP request headers.
|
149 | * @private
|
150 | */
|
151 | private extractTraceContext;
|
152 | /**
|
153 | * Create an Entry object from an API response, such as `entries:list`.
|
154 | *
|
155 | * @private
|
156 | *
|
157 | * @param {object} entry An API representation of an entry. See a
|
158 | * {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry| LogEntry}.
|
159 | * @returns {Entry}
|
160 | */
|
161 | static fromApiResponse_(entry: google.logging.v2.LogEntry): Entry;
|
162 | /**
|
163 | * Determines whether `value` is a JavaScript object.
|
164 | * @param value The value to be checked
|
165 | * @returns true if `value` is a JavaScript object, false otherwise
|
166 | */
|
167 | private isObject;
|
168 | }
|
169 | /**
|
170 | * Reference to the {@link Entry} class.
|
171 | * @name module:@google-cloud/logging.Entry
|
172 | * @see Entry
|
173 | */
|
174 | export { Entry };
|