google-logging-utils-internal 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/LICENSE +203 -0
- package/package/README.md +83 -0
- package/package/lib/auth.d.mts +33 -0
- package/package/lib/auth.d.ts +33 -0
- package/package/lib/auth.js +70 -0
- package/package/lib/auth.js.map +1 -0
- package/package/lib/auth.mjs +45 -0
- package/package/lib/auth.mjs.map +1 -0
- package/package/lib/gcpLogger.d.mts +25 -0
- package/package/lib/gcpLogger.d.ts +25 -0
- package/package/lib/gcpLogger.js +118 -0
- package/package/lib/gcpLogger.js.map +1 -0
- package/package/lib/gcpLogger.mjs +82 -0
- package/package/lib/gcpLogger.mjs.map +1 -0
- package/package/lib/gcpOpenTelemetry.d.mts +59 -0
- package/package/lib/gcpOpenTelemetry.d.ts +59 -0
- package/package/lib/gcpOpenTelemetry.js +374 -0
- package/package/lib/gcpOpenTelemetry.js.map +1 -0
- package/package/lib/gcpOpenTelemetry.mjs +364 -0
- package/package/lib/gcpOpenTelemetry.mjs.map +1 -0
- package/package/lib/index.d.mts +36 -0
- package/package/lib/index.d.ts +36 -0
- package/package/lib/index.js +56 -0
- package/package/lib/index.js.map +1 -0
- package/package/lib/index.mjs +29 -0
- package/package/lib/index.mjs.map +1 -0
- package/package/lib/metrics.d.mts +65 -0
- package/package/lib/metrics.d.ts +65 -0
- package/package/lib/metrics.js +91 -0
- package/package/lib/metrics.js.map +1 -0
- package/package/lib/metrics.mjs +65 -0
- package/package/lib/metrics.mjs.map +1 -0
- package/package/lib/model-armor.d.mts +59 -0
- package/package/lib/model-armor.d.ts +59 -0
- package/package/lib/model-armor.js +205 -0
- package/package/lib/model-armor.js.map +1 -0
- package/package/lib/model-armor.mjs +181 -0
- package/package/lib/model-armor.mjs.map +1 -0
- package/package/lib/telemetry/action.d.mts +27 -0
- package/package/lib/telemetry/action.d.ts +27 -0
- package/package/lib/telemetry/action.js +92 -0
- package/package/lib/telemetry/action.js.map +1 -0
- package/package/lib/telemetry/action.mjs +73 -0
- package/package/lib/telemetry/action.mjs.map +1 -0
- package/package/lib/telemetry/defaults.d.mts +30 -0
- package/package/lib/telemetry/defaults.d.ts +30 -0
- package/package/lib/telemetry/defaults.js +70 -0
- package/package/lib/telemetry/defaults.js.map +1 -0
- package/package/lib/telemetry/defaults.mjs +46 -0
- package/package/lib/telemetry/defaults.mjs.map +1 -0
- package/package/lib/telemetry/engagement.d.mts +35 -0
- package/package/lib/telemetry/engagement.d.ts +35 -0
- package/package/lib/telemetry/engagement.js +106 -0
- package/package/lib/telemetry/engagement.js.map +1 -0
- package/package/lib/telemetry/engagement.mjs +85 -0
- package/package/lib/telemetry/engagement.mjs.map +1 -0
- package/package/lib/telemetry/feature.d.mts +35 -0
- package/package/lib/telemetry/feature.d.ts +35 -0
- package/package/lib/telemetry/feature.js +142 -0
- package/package/lib/telemetry/feature.js.map +1 -0
- package/package/lib/telemetry/feature.mjs +127 -0
- package/package/lib/telemetry/feature.mjs.map +1 -0
- package/package/lib/telemetry/generate.d.mts +53 -0
- package/package/lib/telemetry/generate.d.ts +53 -0
- package/package/lib/telemetry/generate.js +326 -0
- package/package/lib/telemetry/generate.js.map +1 -0
- package/package/lib/telemetry/generate.mjs +314 -0
- package/package/lib/telemetry/generate.mjs.map +1 -0
- package/package/lib/telemetry/path.d.mts +32 -0
- package/package/lib/telemetry/path.d.ts +32 -0
- package/package/lib/telemetry/path.js +91 -0
- package/package/lib/telemetry/path.js.map +1 -0
- package/package/lib/telemetry/path.mjs +78 -0
- package/package/lib/telemetry/path.mjs.map +1 -0
- package/package/lib/types.d.mts +121 -0
- package/package/lib/types.d.ts +121 -0
- package/package/lib/types.js +17 -0
- package/package/lib/types.js.map +1 -0
- package/package/lib/types.mjs +1 -0
- package/package/lib/types.mjs.map +1 -0
- package/package/lib/utils.d.mts +57 -0
- package/package/lib/utils.d.ts +57 -0
- package/package/lib/utils.js +143 -0
- package/package/lib/utils.js.map +1 -0
- package/package/lib/utils.mjs +104 -0
- package/package/lib/utils.mjs.map +1 -0
- package/package/package.json +90 -0
- package/package/src/auth.ts +89 -0
- package/package/src/gcpLogger.ts +124 -0
- package/package/src/gcpOpenTelemetry.ts +485 -0
- package/package/src/index.ts +59 -0
- package/package/src/metrics.ts +122 -0
- package/package/src/model-armor.ts +317 -0
- package/package/src/telemetry/action.ts +106 -0
- package/package/src/telemetry/defaults.ts +72 -0
- package/package/src/telemetry/engagement.ts +120 -0
- package/package/src/telemetry/feature.ts +170 -0
- package/package/src/telemetry/generate.ts +454 -0
- package/package/src/telemetry/path.ts +111 -0
- package/package/src/types.ts +133 -0
- package/package/src/utils.ts +175 -0
- package/package/tests/logs_no_input_output_test.ts +267 -0
- package/package/tests/logs_session_test.ts +219 -0
- package/package/tests/logs_test.ts +633 -0
- package/package/tests/metrics_test.ts +792 -0
- package/package/tests/model_armor_test.ts +336 -0
- package/package/tests/traces_test.ts +380 -0
- package/package/typedoc.json +3 -0
- package/package.json +10 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MetricExporter
|
|
3
|
+
} from "@google-cloud/opentelemetry-cloud-monitoring-exporter";
|
|
4
|
+
import { TraceExporter } from "@google-cloud/opentelemetry-cloud-trace-exporter";
|
|
5
|
+
import { GcpDetectorSync } from "@google-cloud/opentelemetry-resource-util";
|
|
6
|
+
import { SpanStatusCode, TraceFlags } from "@opentelemetry/api";
|
|
7
|
+
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
|
|
8
|
+
import { PinoInstrumentation } from "@opentelemetry/instrumentation-pino";
|
|
9
|
+
import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";
|
|
10
|
+
import { Resource } from "@opentelemetry/resources";
|
|
11
|
+
import {
|
|
12
|
+
AggregationTemporality,
|
|
13
|
+
DefaultAggregation,
|
|
14
|
+
ExponentialHistogramAggregation,
|
|
15
|
+
InMemoryMetricExporter,
|
|
16
|
+
InstrumentType,
|
|
17
|
+
PeriodicExportingMetricReader
|
|
18
|
+
} from "@opentelemetry/sdk-metrics";
|
|
19
|
+
import {
|
|
20
|
+
BatchSpanProcessor,
|
|
21
|
+
InMemorySpanExporter
|
|
22
|
+
} from "@opentelemetry/sdk-trace-base";
|
|
23
|
+
import { GENKIT_VERSION } from "genkit";
|
|
24
|
+
import { logger } from "genkit/logging";
|
|
25
|
+
import { actionTelemetry } from "./telemetry/action.js";
|
|
26
|
+
import { engagementTelemetry } from "./telemetry/engagement.js";
|
|
27
|
+
import { featuresTelemetry } from "./telemetry/feature.js";
|
|
28
|
+
import { generateTelemetry } from "./telemetry/generate.js";
|
|
29
|
+
import { pathsTelemetry } from "./telemetry/path.js";
|
|
30
|
+
import {
|
|
31
|
+
metricsDenied,
|
|
32
|
+
metricsDeniedHelpText,
|
|
33
|
+
tracingDenied,
|
|
34
|
+
tracingDeniedHelpText
|
|
35
|
+
} from "./utils.js";
|
|
36
|
+
let metricExporter;
|
|
37
|
+
let spanProcessor;
|
|
38
|
+
let spanExporter;
|
|
39
|
+
class GcpOpenTelemetry {
|
|
40
|
+
config;
|
|
41
|
+
resource;
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.config = config;
|
|
44
|
+
this.resource = new Resource({ type: "global" }).merge(
|
|
45
|
+
new GcpDetectorSync().detect()
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Log hook for writing trace and span metadata to log messages in the format
|
|
50
|
+
* required by GCP.
|
|
51
|
+
*/
|
|
52
|
+
gcpTraceLogHook = (span, record) => {
|
|
53
|
+
const spanContext = span.spanContext();
|
|
54
|
+
const isSampled = !!(spanContext.traceFlags & TraceFlags.SAMPLED);
|
|
55
|
+
const projectId = this.config.projectId;
|
|
56
|
+
record["logging.googleapis.com/trace"] ??= `projects/${projectId}/traces/${spanContext.traceId}`;
|
|
57
|
+
record["logging.googleapis.com/trace_sampled"] ??= isSampled ? "1" : "0";
|
|
58
|
+
record["logging.googleapis.com/spanId"] ??= spanContext.spanId;
|
|
59
|
+
delete record["span_id"];
|
|
60
|
+
delete record["trace_id"];
|
|
61
|
+
delete record["trace_flags"];
|
|
62
|
+
};
|
|
63
|
+
async getConfig() {
|
|
64
|
+
spanProcessor = new BatchSpanProcessor(await this.createSpanExporter());
|
|
65
|
+
return {
|
|
66
|
+
resource: this.resource,
|
|
67
|
+
spanProcessor,
|
|
68
|
+
sampler: this.config.sampler,
|
|
69
|
+
instrumentations: this.getInstrumentations(),
|
|
70
|
+
metricReader: await this.createMetricReader()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async createSpanExporter() {
|
|
74
|
+
spanExporter = new AdjustingTraceExporter(
|
|
75
|
+
this.shouldExportTraces() ? new TraceExporter({
|
|
76
|
+
// provided projectId should take precedence over env vars, etc
|
|
77
|
+
projectId: this.config.projectId,
|
|
78
|
+
// creds for non-GCP environments, in lieu of using ADC.
|
|
79
|
+
credentials: this.config.credentials
|
|
80
|
+
}) : new InMemorySpanExporter(),
|
|
81
|
+
this.config.exportInputAndOutput,
|
|
82
|
+
this.config.projectId,
|
|
83
|
+
getErrorHandler(
|
|
84
|
+
(err) => {
|
|
85
|
+
return tracingDenied(err);
|
|
86
|
+
},
|
|
87
|
+
await tracingDeniedHelpText()
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
return spanExporter;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates a {MetricReader} for pushing metrics out to GCP via OpenTelemetry.
|
|
94
|
+
*/
|
|
95
|
+
async createMetricReader() {
|
|
96
|
+
metricExporter = await this.buildMetricExporter();
|
|
97
|
+
return new PeriodicExportingMetricReader({
|
|
98
|
+
exportIntervalMillis: this.config.metricExportIntervalMillis,
|
|
99
|
+
exportTimeoutMillis: this.config.metricExportTimeoutMillis,
|
|
100
|
+
exporter: metricExporter
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** Gets all open telemetry instrumentations as configured by the plugin. */
|
|
104
|
+
getInstrumentations() {
|
|
105
|
+
let instrumentations = [];
|
|
106
|
+
if (this.config.autoInstrumentation) {
|
|
107
|
+
instrumentations = getNodeAutoInstrumentations(
|
|
108
|
+
this.config.autoInstrumentationConfig
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return instrumentations.concat(this.getDefaultLoggingInstrumentations()).concat(this.config.instrumentations ?? []);
|
|
112
|
+
}
|
|
113
|
+
shouldExportTraces() {
|
|
114
|
+
return this.config.export && !this.config.disableTraces;
|
|
115
|
+
}
|
|
116
|
+
shouldExportMetrics() {
|
|
117
|
+
return this.config.export && !this.config.disableMetrics;
|
|
118
|
+
}
|
|
119
|
+
/** Always configure the Pino and Winston instrumentations */
|
|
120
|
+
getDefaultLoggingInstrumentations() {
|
|
121
|
+
return [
|
|
122
|
+
new WinstonInstrumentation({ logHook: this.gcpTraceLogHook }),
|
|
123
|
+
new PinoInstrumentation({ logHook: this.gcpTraceLogHook })
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
async buildMetricExporter() {
|
|
127
|
+
const exporter = this.shouldExportMetrics() ? new MetricExporterWrapper(
|
|
128
|
+
{
|
|
129
|
+
userAgent: {
|
|
130
|
+
product: "genkit",
|
|
131
|
+
version: GENKIT_VERSION
|
|
132
|
+
},
|
|
133
|
+
// provided projectId should take precedence over env vars, etc
|
|
134
|
+
projectId: this.config.projectId,
|
|
135
|
+
// creds for non-GCP environments, in lieu of using ADC.
|
|
136
|
+
credentials: this.config.credentials
|
|
137
|
+
},
|
|
138
|
+
getErrorHandler(
|
|
139
|
+
(err) => {
|
|
140
|
+
return metricsDenied(err);
|
|
141
|
+
},
|
|
142
|
+
await metricsDeniedHelpText()
|
|
143
|
+
)
|
|
144
|
+
) : new InMemoryMetricExporter(AggregationTemporality.DELTA);
|
|
145
|
+
return exporter;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
class MetricExporterWrapper extends MetricExporter {
|
|
149
|
+
constructor(options, errorHandler) {
|
|
150
|
+
super(options);
|
|
151
|
+
this.errorHandler = errorHandler;
|
|
152
|
+
}
|
|
153
|
+
promise = new Promise((resolve) => resolve());
|
|
154
|
+
async export(metrics, resultCallback) {
|
|
155
|
+
await this.promise;
|
|
156
|
+
this.modifyStartTimes(metrics);
|
|
157
|
+
this.promise = new Promise((resolve) => {
|
|
158
|
+
super.export(metrics, (result) => {
|
|
159
|
+
try {
|
|
160
|
+
if (this.errorHandler && result.error) {
|
|
161
|
+
this.errorHandler(result.error);
|
|
162
|
+
}
|
|
163
|
+
resultCallback(result);
|
|
164
|
+
} finally {
|
|
165
|
+
resolve();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
selectAggregation(instrumentType) {
|
|
171
|
+
if (instrumentType === InstrumentType.HISTOGRAM) {
|
|
172
|
+
return new ExponentialHistogramAggregation();
|
|
173
|
+
}
|
|
174
|
+
return new DefaultAggregation();
|
|
175
|
+
}
|
|
176
|
+
selectAggregationTemporality(instrumentType) {
|
|
177
|
+
return AggregationTemporality.DELTA;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Modify the start times of each data point to ensure no
|
|
181
|
+
* overlap with previous exports.
|
|
182
|
+
*
|
|
183
|
+
* Cloud metrics do not support delta metrics for custom metrics
|
|
184
|
+
* and will convert any DELTA aggregations to CUMULATIVE ones on
|
|
185
|
+
* export. There is implicit overlap in the start/end times that
|
|
186
|
+
* the Metric reader is sending -- the end_time of the previous
|
|
187
|
+
* export will become the start_time of the current export. The
|
|
188
|
+
* overlap in times means that only one of those records will
|
|
189
|
+
* persist and the other will be overwritten. This
|
|
190
|
+
* method adds a thousandth of a second to ensure discrete export
|
|
191
|
+
* timeframes.
|
|
192
|
+
*/
|
|
193
|
+
modifyStartTimes(metrics) {
|
|
194
|
+
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
195
|
+
scopeMetric.metrics.forEach((metric) => {
|
|
196
|
+
metric.dataPoints.forEach((dataPoint) => {
|
|
197
|
+
dataPoint.startTime[1] = dataPoint.startTime[1] + 1e6;
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async shutdown() {
|
|
203
|
+
return await this.forceFlush();
|
|
204
|
+
}
|
|
205
|
+
async forceFlush() {
|
|
206
|
+
await this.promise;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
class AdjustingTraceExporter {
|
|
210
|
+
constructor(exporter, logInputAndOutput, projectId, errorHandler) {
|
|
211
|
+
this.exporter = exporter;
|
|
212
|
+
this.logInputAndOutput = logInputAndOutput;
|
|
213
|
+
this.projectId = projectId;
|
|
214
|
+
this.errorHandler = errorHandler;
|
|
215
|
+
}
|
|
216
|
+
export(spans, resultCallback) {
|
|
217
|
+
this.exporter?.export(this.adjust(spans), (result) => {
|
|
218
|
+
if (this.errorHandler && result.error) {
|
|
219
|
+
this.errorHandler(result.error);
|
|
220
|
+
}
|
|
221
|
+
resultCallback(result);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
shutdown() {
|
|
225
|
+
return this.exporter?.shutdown();
|
|
226
|
+
}
|
|
227
|
+
getExporter() {
|
|
228
|
+
return this.exporter;
|
|
229
|
+
}
|
|
230
|
+
forceFlush() {
|
|
231
|
+
if (this.exporter?.forceFlush) {
|
|
232
|
+
return this.exporter.forceFlush();
|
|
233
|
+
}
|
|
234
|
+
return Promise.resolve();
|
|
235
|
+
}
|
|
236
|
+
adjust(spans) {
|
|
237
|
+
return spans.map((span) => {
|
|
238
|
+
this.tickTelemetry(span);
|
|
239
|
+
span = this.redactInputOutput(span);
|
|
240
|
+
span = this.markErrorSpanAsError(span);
|
|
241
|
+
span = this.markFailedSpan(span);
|
|
242
|
+
span = this.markGenkitFeature(span);
|
|
243
|
+
span = this.markGenkitModel(span);
|
|
244
|
+
span = this.normalizeLabels(span);
|
|
245
|
+
return span;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
tickTelemetry(span) {
|
|
249
|
+
const attributes = span.attributes;
|
|
250
|
+
if (!Object.keys(attributes).includes("genkit:type")) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const type = attributes["genkit:type"];
|
|
254
|
+
const subtype = attributes["genkit:metadata:subtype"];
|
|
255
|
+
const isRoot = !!span.attributes["genkit:isRoot"];
|
|
256
|
+
pathsTelemetry.tick(span, this.logInputAndOutput, this.projectId);
|
|
257
|
+
if (isRoot) {
|
|
258
|
+
featuresTelemetry.tick(span, this.logInputAndOutput, this.projectId);
|
|
259
|
+
span.attributes["genkit:rootState"] = span.attributes["genkit:state"];
|
|
260
|
+
} else {
|
|
261
|
+
if (type === "action" && subtype === "model") {
|
|
262
|
+
generateTelemetry.tick(span, this.logInputAndOutput, this.projectId);
|
|
263
|
+
}
|
|
264
|
+
if (type === "action" && subtype === "tool") {
|
|
265
|
+
}
|
|
266
|
+
if (type === "action" || type === "flow" || type == "flowStep" || type == "util") {
|
|
267
|
+
actionTelemetry.tick(span, this.logInputAndOutput, this.projectId);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (type === "userEngagement") {
|
|
271
|
+
engagementTelemetry.tick(span, this.logInputAndOutput, this.projectId);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
redactInputOutput(span) {
|
|
275
|
+
const hasInput = "genkit:input" in span.attributes;
|
|
276
|
+
const hasOutput = "genkit:output" in span.attributes;
|
|
277
|
+
return !hasInput && !hasOutput ? span : {
|
|
278
|
+
...span,
|
|
279
|
+
spanContext: span.spanContext,
|
|
280
|
+
attributes: {
|
|
281
|
+
...span.attributes,
|
|
282
|
+
"genkit:input": "<redacted>",
|
|
283
|
+
"genkit:output": "<redacted>"
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// This is a workaround for GCP Trace to mark a span with a red
|
|
288
|
+
// exclamation mark indicating that it is an error.
|
|
289
|
+
markErrorSpanAsError(span) {
|
|
290
|
+
return span.status.code !== SpanStatusCode.ERROR ? span : {
|
|
291
|
+
...span,
|
|
292
|
+
spanContext: span.spanContext,
|
|
293
|
+
attributes: {
|
|
294
|
+
...span.attributes,
|
|
295
|
+
"/http/status_code": "599"
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
normalizeLabels(span) {
|
|
300
|
+
const normalized = {};
|
|
301
|
+
for (const [key, value] of Object.entries(span.attributes)) {
|
|
302
|
+
normalized[key.replace(/\:/g, "/")] = value;
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
...span,
|
|
306
|
+
spanContext: span.spanContext,
|
|
307
|
+
attributes: normalized
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
markFailedSpan(span) {
|
|
311
|
+
if (span.attributes["genkit:isFailureSource"]) {
|
|
312
|
+
span.attributes["genkit:failedSpan"] = span.attributes["genkit:name"];
|
|
313
|
+
span.attributes["genkit:failedPath"] = span.attributes["genkit:path"];
|
|
314
|
+
}
|
|
315
|
+
return span;
|
|
316
|
+
}
|
|
317
|
+
markGenkitFeature(span) {
|
|
318
|
+
if (span.attributes["genkit:isRoot"] && !!span.attributes["genkit:name"]) {
|
|
319
|
+
span.attributes["genkit:feature"] = span.attributes["genkit:name"];
|
|
320
|
+
}
|
|
321
|
+
return span;
|
|
322
|
+
}
|
|
323
|
+
markGenkitModel(span) {
|
|
324
|
+
if (span.attributes["genkit:metadata:subtype"] === "model" && !!span.attributes["genkit:name"]) {
|
|
325
|
+
span.attributes["genkit:model"] = span.attributes["genkit:name"];
|
|
326
|
+
}
|
|
327
|
+
return span;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function getErrorHandler(shouldLogFn, helpText) {
|
|
331
|
+
let instructionsLogged = false;
|
|
332
|
+
return (err) => {
|
|
333
|
+
const defaultLogger = logger.defaultLogger;
|
|
334
|
+
if (err && shouldLogFn(err)) {
|
|
335
|
+
if (!instructionsLogged) {
|
|
336
|
+
instructionsLogged = true;
|
|
337
|
+
defaultLogger.error(
|
|
338
|
+
`Unable to send telemetry to Google Cloud: ${err.message}
|
|
339
|
+
|
|
340
|
+
${helpText}
|
|
341
|
+
`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
} else if (err) {
|
|
345
|
+
defaultLogger.error(`Unable to send telemetry to Google Cloud: ${err}`);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function __getMetricExporterForTesting() {
|
|
350
|
+
return metricExporter;
|
|
351
|
+
}
|
|
352
|
+
function __getSpanExporterForTesting() {
|
|
353
|
+
return spanExporter.getExporter();
|
|
354
|
+
}
|
|
355
|
+
function __forceFlushSpansForTesting() {
|
|
356
|
+
spanProcessor.forceFlush();
|
|
357
|
+
}
|
|
358
|
+
export {
|
|
359
|
+
GcpOpenTelemetry,
|
|
360
|
+
__forceFlushSpansForTesting,
|
|
361
|
+
__getMetricExporterForTesting,
|
|
362
|
+
__getSpanExporterForTesting
|
|
363
|
+
};
|
|
364
|
+
//# sourceMappingURL=gcpOpenTelemetry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gcpOpenTelemetry.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n MetricExporter,\n type ExporterOptions,\n} from '@google-cloud/opentelemetry-cloud-monitoring-exporter';\nimport { TraceExporter } from '@google-cloud/opentelemetry-cloud-trace-exporter';\nimport { GcpDetectorSync } from '@google-cloud/opentelemetry-resource-util';\nimport { SpanStatusCode, TraceFlags, type Span } from '@opentelemetry/api';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { type ExportResult } from '@opentelemetry/core';\nimport type { Instrumentation } from '@opentelemetry/instrumentation';\nimport { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';\nimport { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston';\nimport { Resource } from '@opentelemetry/resources';\nimport {\n AggregationTemporality,\n DefaultAggregation,\n ExponentialHistogramAggregation,\n InMemoryMetricExporter,\n InstrumentType,\n PeriodicExportingMetricReader,\n type PushMetricExporter,\n type ResourceMetrics,\n} from '@opentelemetry/sdk-metrics';\nimport type { NodeSDKConfiguration } from '@opentelemetry/sdk-node';\nimport {\n BatchSpanProcessor,\n InMemorySpanExporter,\n type ReadableSpan,\n type SpanExporter,\n} from '@opentelemetry/sdk-trace-base';\nimport { GENKIT_VERSION } from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { actionTelemetry } from './telemetry/action.js';\nimport { engagementTelemetry } from './telemetry/engagement.js';\nimport { featuresTelemetry } from './telemetry/feature.js';\nimport { generateTelemetry } from './telemetry/generate.js';\nimport { pathsTelemetry } from './telemetry/path.js';\nimport type { GcpTelemetryConfig } from './types.js';\nimport {\n metricsDenied,\n metricsDeniedHelpText,\n tracingDenied,\n tracingDeniedHelpText,\n} from './utils.js';\n\nlet metricExporter: PushMetricExporter;\nlet spanProcessor: BatchSpanProcessor;\nlet spanExporter: AdjustingTraceExporter;\n\n/**\n * Provides a {TelemetryConfig} for exporting OpenTelemetry data (Traces,\n * Metrics, and Logs) to the Google Cloud Operations Suite.\n */\nexport class GcpOpenTelemetry {\n private readonly config: GcpTelemetryConfig;\n private readonly resource: Resource;\n\n constructor(config: GcpTelemetryConfig) {\n this.config = config;\n this.resource = new Resource({ type: 'global' }).merge(\n new GcpDetectorSync().detect()\n );\n }\n\n /**\n * Log hook for writing trace and span metadata to log messages in the format\n * required by GCP.\n */\n private gcpTraceLogHook = (span: Span, record: any) => {\n const spanContext = span.spanContext();\n const isSampled = !!(spanContext.traceFlags & TraceFlags.SAMPLED);\n const projectId = this.config.projectId;\n\n record['logging.googleapis.com/trace'] ??=\n `projects/${projectId}/traces/${spanContext.traceId}`;\n record['logging.googleapis.com/trace_sampled'] ??= isSampled ? '1' : '0';\n record['logging.googleapis.com/spanId'] ??= spanContext.spanId;\n\n // Clear out the duplicate trace and span information in the log metadata.\n // These will be incorrect for logs written during span export time since\n // the logs are written after the span has fully executed. Those logs are\n // explicitly tied to the correct span in createCommonLogAttributes in\n // utils.ts.\n delete record['span_id'];\n delete record['trace_id'];\n delete record['trace_flags'];\n };\n\n async getConfig(): Promise<Partial<NodeSDKConfiguration>> {\n spanProcessor = new BatchSpanProcessor(await this.createSpanExporter());\n return {\n resource: this.resource,\n spanProcessor: spanProcessor,\n sampler: this.config.sampler,\n instrumentations: this.getInstrumentations(),\n metricReader: await this.createMetricReader(),\n };\n }\n\n private async createSpanExporter(): Promise<SpanExporter> {\n spanExporter = new AdjustingTraceExporter(\n this.shouldExportTraces()\n ? new TraceExporter({\n // provided projectId should take precedence over env vars, etc\n projectId: this.config.projectId,\n // creds for non-GCP environments, in lieu of using ADC.\n credentials: this.config.credentials,\n })\n : new InMemorySpanExporter(),\n this.config.exportInputAndOutput,\n this.config.projectId,\n getErrorHandler(\n (err) => {\n return tracingDenied(err);\n },\n await tracingDeniedHelpText()\n )\n );\n return spanExporter;\n }\n\n /**\n * Creates a {MetricReader} for pushing metrics out to GCP via OpenTelemetry.\n */\n private async createMetricReader(): Promise<PeriodicExportingMetricReader> {\n metricExporter = await this.buildMetricExporter();\n return new PeriodicExportingMetricReader({\n exportIntervalMillis: this.config.metricExportIntervalMillis,\n exportTimeoutMillis: this.config.metricExportTimeoutMillis,\n exporter: metricExporter,\n });\n }\n\n /** Gets all open telemetry instrumentations as configured by the plugin. */\n private getInstrumentations() {\n let instrumentations: Instrumentation[] = [];\n\n if (this.config.autoInstrumentation) {\n instrumentations = getNodeAutoInstrumentations(\n this.config.autoInstrumentationConfig\n );\n }\n\n return instrumentations\n .concat(this.getDefaultLoggingInstrumentations())\n .concat(this.config.instrumentations ?? []);\n }\n\n private shouldExportTraces(): boolean {\n return this.config.export && !this.config.disableTraces;\n }\n\n private shouldExportMetrics(): boolean {\n return this.config.export && !this.config.disableMetrics;\n }\n\n /** Always configure the Pino and Winston instrumentations */\n private getDefaultLoggingInstrumentations(): Instrumentation[] {\n return [\n new WinstonInstrumentation({ logHook: this.gcpTraceLogHook }),\n new PinoInstrumentation({ logHook: this.gcpTraceLogHook }),\n ];\n }\n\n private async buildMetricExporter(): Promise<PushMetricExporter> {\n const exporter: PushMetricExporter = this.shouldExportMetrics()\n ? new MetricExporterWrapper(\n {\n userAgent: {\n product: 'genkit',\n version: GENKIT_VERSION,\n },\n // provided projectId should take precedence over env vars, etc\n projectId: this.config.projectId,\n // creds for non-GCP environments, in lieu of using ADC.\n credentials: this.config.credentials,\n },\n getErrorHandler(\n (err) => {\n return metricsDenied(err);\n },\n await metricsDeniedHelpText()\n )\n )\n : new InMemoryMetricExporter(AggregationTemporality.DELTA);\n return exporter;\n }\n}\n\n/**\n * Rewrites the export method to include an error handler which logs\n * helpful information about how to set up metrics/telemetry in GCP.\n */\nclass MetricExporterWrapper extends MetricExporter {\n private promise = new Promise<void>((resolve) => resolve());\n\n constructor(\n options?: ExporterOptions,\n private errorHandler?: (error: Error) => void\n ) {\n super(options);\n }\n\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n await this.promise;\n this.modifyStartTimes(metrics);\n this.promise = new Promise<void>((resolve) => {\n super.export(metrics, (result) => {\n try {\n if (this.errorHandler && result.error) {\n this.errorHandler(result.error);\n }\n resultCallback(result);\n } finally {\n resolve();\n }\n });\n });\n }\n\n selectAggregation(instrumentType: InstrumentType) {\n if (instrumentType === InstrumentType.HISTOGRAM) {\n return new ExponentialHistogramAggregation();\n }\n return new DefaultAggregation();\n }\n\n selectAggregationTemporality(instrumentType: InstrumentType) {\n return AggregationTemporality.DELTA;\n }\n\n /**\n * Modify the start times of each data point to ensure no\n * overlap with previous exports.\n *\n * Cloud metrics do not support delta metrics for custom metrics\n * and will convert any DELTA aggregations to CUMULATIVE ones on\n * export. There is implicit overlap in the start/end times that\n * the Metric reader is sending -- the end_time of the previous\n * export will become the start_time of the current export. The\n * overlap in times means that only one of those records will\n * persist and the other will be overwritten. This\n * method adds a thousandth of a second to ensure discrete export\n * timeframes.\n */\n private modifyStartTimes(metrics: ResourceMetrics): void {\n metrics.scopeMetrics.forEach((scopeMetric) => {\n scopeMetric.metrics.forEach((metric) => {\n metric.dataPoints.forEach((dataPoint) => {\n dataPoint.startTime[1] = dataPoint.startTime[1] + 1_000_000;\n });\n });\n });\n }\n\n async shutdown(): Promise<void> {\n return await this.forceFlush();\n }\n\n async forceFlush(): Promise<void> {\n await this.promise;\n }\n}\n\n/**\n * Adjusts spans before exporting to GCP. Redacts model input\n * and output content, and augments span attributes before sending to GCP.\n */\nclass AdjustingTraceExporter implements SpanExporter {\n constructor(\n private exporter: SpanExporter,\n private logInputAndOutput: boolean,\n private projectId?: string,\n private errorHandler?: (error: Error) => void\n ) {}\n\n export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): void {\n this.exporter?.export(this.adjust(spans), (result) => {\n if (this.errorHandler && result.error) {\n this.errorHandler(result.error);\n }\n resultCallback(result);\n });\n }\n\n shutdown(): Promise<void> {\n return this.exporter?.shutdown();\n }\n\n getExporter(): SpanExporter {\n return this.exporter;\n }\n\n forceFlush(): Promise<void> {\n if (this.exporter?.forceFlush) {\n return this.exporter.forceFlush();\n }\n return Promise.resolve();\n }\n\n private adjust(spans: ReadableSpan[]): ReadableSpan[] {\n return spans.map((span) => {\n this.tickTelemetry(span);\n\n span = this.redactInputOutput(span);\n span = this.markErrorSpanAsError(span);\n span = this.markFailedSpan(span);\n span = this.markGenkitFeature(span);\n span = this.markGenkitModel(span);\n span = this.normalizeLabels(span);\n return span;\n });\n }\n\n private tickTelemetry(span: ReadableSpan) {\n const attributes = span.attributes;\n if (!Object.keys(attributes).includes('genkit:type')) {\n return;\n }\n\n const type = attributes['genkit:type'] as string;\n const subtype = attributes['genkit:metadata:subtype'] as string;\n const isRoot = !!span.attributes['genkit:isRoot'];\n\n pathsTelemetry.tick(span, this.logInputAndOutput, this.projectId);\n if (isRoot) {\n // Report top level feature request and latency only for root spans\n // Log input to and output from to the feature\n featuresTelemetry.tick(span, this.logInputAndOutput, this.projectId);\n // Set root status explicitly\n span.attributes['genkit:rootState'] = span.attributes['genkit:state'];\n } else {\n if (type === 'action' && subtype === 'model') {\n // Report generate metrics () for all model actions\n generateTelemetry.tick(span, this.logInputAndOutput, this.projectId);\n }\n if (type === 'action' && subtype === 'tool') {\n // TODO: Report input and output for tool actions\n }\n if (\n type === 'action' ||\n type === 'flow' ||\n type == 'flowStep' ||\n type == 'util'\n ) {\n // Report request and latency metrics for all actions\n actionTelemetry.tick(span, this.logInputAndOutput, this.projectId);\n }\n }\n if (type === 'userEngagement') {\n // Report user acceptance and feedback metrics\n engagementTelemetry.tick(span, this.logInputAndOutput, this.projectId);\n }\n }\n\n private redactInputOutput(span: ReadableSpan): ReadableSpan {\n const hasInput = 'genkit:input' in span.attributes;\n const hasOutput = 'genkit:output' in span.attributes;\n\n return !hasInput && !hasOutput\n ? span\n : {\n ...span,\n spanContext: span.spanContext,\n attributes: {\n ...span.attributes,\n 'genkit:input': '<redacted>',\n 'genkit:output': '<redacted>',\n },\n };\n }\n\n // This is a workaround for GCP Trace to mark a span with a red\n // exclamation mark indicating that it is an error.\n private markErrorSpanAsError(span: ReadableSpan): ReadableSpan {\n return span.status.code !== SpanStatusCode.ERROR\n ? span\n : {\n ...span,\n spanContext: span.spanContext,\n attributes: {\n ...span.attributes,\n '/http/status_code': '599',\n },\n };\n }\n\n private normalizeLabels(span: ReadableSpan): ReadableSpan {\n const normalized = {} as Record<string, any>;\n for (const [key, value] of Object.entries(span.attributes)) {\n normalized[key.replace(/\\:/g, '/')] = value;\n }\n return {\n ...span,\n spanContext: span.spanContext,\n attributes: normalized,\n };\n }\n\n private markFailedSpan(span: ReadableSpan): ReadableSpan {\n if (span.attributes['genkit:isFailureSource']) {\n span.attributes['genkit:failedSpan'] = span.attributes['genkit:name'];\n span.attributes['genkit:failedPath'] = span.attributes['genkit:path'];\n }\n return span;\n }\n\n private markGenkitFeature(span: ReadableSpan): ReadableSpan {\n if (span.attributes['genkit:isRoot'] && !!span.attributes['genkit:name']) {\n span.attributes['genkit:feature'] = span.attributes['genkit:name'];\n }\n return span;\n }\n\n private markGenkitModel(span: ReadableSpan): ReadableSpan {\n if (\n span.attributes['genkit:metadata:subtype'] === 'model' &&\n !!span.attributes['genkit:name']\n ) {\n span.attributes['genkit:model'] = span.attributes['genkit:name'];\n }\n return span;\n }\n}\n\nfunction getErrorHandler(\n shouldLogFn: (err: Error) => boolean,\n helpText: string\n): (err: Error) => void {\n // only log the first time\n let instructionsLogged = false;\n\n return (err) => {\n // Use the defaultLogger so that logs don't get swallowed by the open\n // telemetry exporter\n const defaultLogger = logger.defaultLogger;\n if (err && shouldLogFn(err)) {\n if (!instructionsLogged) {\n instructionsLogged = true;\n defaultLogger.error(\n `Unable to send telemetry to Google Cloud: ${err.message}\\n\\n${helpText}\\n`\n );\n }\n } else if (err) {\n defaultLogger.error(`Unable to send telemetry to Google Cloud: ${err}`);\n }\n };\n}\n\n/** @hidden */\nexport function __getMetricExporterForTesting(): InMemoryMetricExporter {\n return metricExporter as InMemoryMetricExporter;\n}\n\n/** @hidden */\nexport function __getSpanExporterForTesting(): InMemorySpanExporter {\n return spanExporter.getExporter() as InMemorySpanExporter;\n}\n\n/** @hidden */\nexport function __forceFlushSpansForTesting() {\n spanProcessor.forceFlush();\n}\n"],"mappings":"AAgBA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,kBAA6B;AACtD,SAAS,mCAAmC;AAG5C,SAAS,2BAA2B;AACpC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ACzE;AAAA,MACF;AAAA,IACF,WAAW,KAAK;AACd,oBAAc,MAAM,6CAA6C,GAAG,EAAE;AAAA,IACxE;AAAA,EACF;AACF;AAGO,SAAS,gCAAwD;AACtE,SAAO;AACT;AAGO,SAAS,8BAAoD;AAClE,SAAO,aAAa,YAAY;AAClC;AAGO,SAAS,8BAA8B;AAC5C,gBAAc,WAAW;AAC3B;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GcpTelemetryConfigOptions } from './types.mjs';
|
|
2
|
+
export { GcpLogger, __addTransportStreamForTesting, __useJsonFormatForTesting } from './gcpLogger.mjs';
|
|
3
|
+
export { GcpOpenTelemetry, __forceFlushSpansForTesting, __getMetricExporterForTesting, __getSpanExporterForTesting } from './gcpOpenTelemetry.mjs';
|
|
4
|
+
import '@opentelemetry/auto-instrumentations-node';
|
|
5
|
+
import '@opentelemetry/instrumentation';
|
|
6
|
+
import '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import 'google-auth-library';
|
|
8
|
+
import 'winston';
|
|
9
|
+
import 'stream';
|
|
10
|
+
import '@opentelemetry/sdk-metrics';
|
|
11
|
+
import '@opentelemetry/sdk-node';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright 2024 Google LLC
|
|
15
|
+
*
|
|
16
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License.
|
|
18
|
+
* You may obtain a copy of the License at
|
|
19
|
+
*
|
|
20
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
23
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
+
* See the License for the specific language governing permissions and
|
|
26
|
+
* limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enables telemetry export to the Google Cloud Observability suite.
|
|
31
|
+
*
|
|
32
|
+
* @param options configuration options
|
|
33
|
+
*/
|
|
34
|
+
declare function enableGoogleCloudTelemetry(options?: GcpTelemetryConfigOptions): Promise<void>;
|
|
35
|
+
|
|
36
|
+
export { GcpTelemetryConfigOptions, enableGoogleCloudTelemetry };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GcpTelemetryConfigOptions } from './types.js';
|
|
2
|
+
export { GcpLogger, __addTransportStreamForTesting, __useJsonFormatForTesting } from './gcpLogger.js';
|
|
3
|
+
export { GcpOpenTelemetry, __forceFlushSpansForTesting, __getMetricExporterForTesting, __getSpanExporterForTesting } from './gcpOpenTelemetry.js';
|
|
4
|
+
import '@opentelemetry/auto-instrumentations-node';
|
|
5
|
+
import '@opentelemetry/instrumentation';
|
|
6
|
+
import '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import 'google-auth-library';
|
|
8
|
+
import 'winston';
|
|
9
|
+
import 'stream';
|
|
10
|
+
import '@opentelemetry/sdk-metrics';
|
|
11
|
+
import '@opentelemetry/sdk-node';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright 2024 Google LLC
|
|
15
|
+
*
|
|
16
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License.
|
|
18
|
+
* You may obtain a copy of the License at
|
|
19
|
+
*
|
|
20
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
23
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
+
* See the License for the specific language governing permissions and
|
|
26
|
+
* limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enables telemetry export to the Google Cloud Observability suite.
|
|
31
|
+
*
|
|
32
|
+
* @param options configuration options
|
|
33
|
+
*/
|
|
34
|
+
declare function enableGoogleCloudTelemetry(options?: GcpTelemetryConfigOptions): Promise<void>;
|
|
35
|
+
|
|
36
|
+
export { GcpTelemetryConfigOptions, enableGoogleCloudTelemetry };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
enableGoogleCloudTelemetry: () => enableGoogleCloudTelemetry
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(index_exports);
|
|
25
|
+
var import_genkit = require("genkit");
|
|
26
|
+
var import_logging = require("genkit/logging");
|
|
27
|
+
var import_tracing = require("genkit/tracing");
|
|
28
|
+
var import_auth = require("./auth.js");
|
|
29
|
+
var import_gcpLogger = require("./gcpLogger.js");
|
|
30
|
+
var import_gcpOpenTelemetry = require("./gcpOpenTelemetry.js");
|
|
31
|
+
var import_defaults = require("./telemetry/defaults.js");
|
|
32
|
+
__reExport(index_exports, require("./gcpLogger.js"), module.exports);
|
|
33
|
+
__reExport(index_exports, require("./gcpOpenTelemetry.js"), module.exports);
|
|
34
|
+
function enableGoogleCloudTelemetry(options) {
|
|
35
|
+
return (0, import_tracing.enableTelemetry)(
|
|
36
|
+
configureGcpPlugin(options).then(async (pluginConfig) => {
|
|
37
|
+
import_logging.logger.init(await new import_gcpLogger.GcpLogger(pluginConfig).getLogger((0, import_genkit.getCurrentEnv)()));
|
|
38
|
+
return new import_gcpOpenTelemetry.GcpOpenTelemetry(pluginConfig).getConfig();
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
async function configureGcpPlugin(options) {
|
|
43
|
+
const envOptions = await (0, import_auth.credentialsFromEnvironment)();
|
|
44
|
+
return {
|
|
45
|
+
projectId: options?.projectId || envOptions.projectId,
|
|
46
|
+
credentials: options?.credentials || envOptions.credentials,
|
|
47
|
+
...import_defaults.TelemetryConfigs.defaults(options)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
enableGoogleCloudTelemetry,
|
|
53
|
+
...require("./gcpLogger.js"),
|
|
54
|
+
...require("./gcpOpenTelemetry.js")
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getCurrentEnv } from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { enableTelemetry } from 'genkit/tracing';\nimport { credentialsFromEnvironment } from './auth.js';\nimport { GcpLogger } from './gcpLogger.js';\nimport { GcpOpenTelemetry } from './gcpOpenTelemetry.js';\nimport { TelemetryConfigs } from './telemetry/defaults.js';\nimport type { GcpTelemetryConfig, GcpTelemetryConfigOptions } from './types.js';\n\n/**\n * Enables telemetry export to the Google Cloud Observability suite.\n *\n * @param options configuration options\n */\nexport function enableGoogleCloudTelemetry(\n options?: GcpTelemetryConfigOptions\n) {\n return enableTelemetry(\n configureGcpPlugin(options).then(async (pluginConfig) => {\n logger.init(await new GcpLogger(pluginConfig).getLogger(getCurrentEnv()));\n return new GcpOpenTelemetry(pluginConfig).getConfig();\n })\n );\n}\n\n/**\n * Create a configuration object for the plugin.\n * Not normally needed, but exposed for use by the Firebase plugin.\n */\nasync function configureGcpPlugin(\n options?: GcpTelemetryConfigOptions\n): Promise<GcpTelemetryConfig> {\n const envOptions = await credentialsFromEnvironment();\n return {\n projectId: options?.projectId || envOptions.projectId,\n credentials: options?.credentials || envOptions.credentials,\n ...TelemetryConfigs.defaults(options),\n };\n}\n\nexport * from './gcpLogger.js';\nexport * from './gcpOpenTelemetry.js';\nexport type { GcpTelemetryConfigOptions } from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAA8B;AAC9B,qBAAuB;AACvB,qBAAgC;AAChC,kBAA2C;AAC3C,uBAA0B;AAC1B,8BAAiC;AACjC,sBAAiC;AAkCjC,0BAAc,2BAxDd;AAyDA,0BAAc,kCAzDd;AA8BO,SAAS,2BACd,SACA;AACA,aAAO;AAAA,IACL,mBAAmB,OAAO,EAAE,KAAK,OAAO,iBAAiB;AACvD,4BAAO,KAAK,MAAM,IAAI,2BAAU,YAAY,EAAE,cAAU,6BAAc,CAAC,CAAC;AACxE,aAAO,IAAI,yCAAiB,YAAY,EAAE,UAAU;AAAA,IACtD,CAAC;AAAA,EACH;AACF;AAMA,eAAe,mBACb,SAC6B;AAC7B,QAAM,aAAa,UAAM,wCAA2B;AACpD,SAAO;AAAA,IACL,WAAW,SAAS,aAAa,WAAW;AAAA,IAC5C,aAAa,SAAS,eAAe,WAAW;AAAA,IAChD,GAAG,iCAAiB,SAAS,OAAO;AAAA,EACtC;AACF;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getCurrentEnv } from "genkit";
|
|
2
|
+
import { logger } from "genkit/logging";
|
|
3
|
+
import { enableTelemetry } from "genkit/tracing";
|
|
4
|
+
import { credentialsFromEnvironment } from "./auth.js";
|
|
5
|
+
import { GcpLogger } from "./gcpLogger.js";
|
|
6
|
+
import { GcpOpenTelemetry } from "./gcpOpenTelemetry.js";
|
|
7
|
+
import { TelemetryConfigs } from "./telemetry/defaults.js";
|
|
8
|
+
function enableGoogleCloudTelemetry(options) {
|
|
9
|
+
return enableTelemetry(
|
|
10
|
+
configureGcpPlugin(options).then(async (pluginConfig) => {
|
|
11
|
+
logger.init(await new GcpLogger(pluginConfig).getLogger(getCurrentEnv()));
|
|
12
|
+
return new GcpOpenTelemetry(pluginConfig).getConfig();
|
|
13
|
+
})
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
async function configureGcpPlugin(options) {
|
|
17
|
+
const envOptions = await credentialsFromEnvironment();
|
|
18
|
+
return {
|
|
19
|
+
projectId: options?.projectId || envOptions.projectId,
|
|
20
|
+
credentials: options?.credentials || envOptions.credentials,
|
|
21
|
+
...TelemetryConfigs.defaults(options)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export * from "./gcpLogger.js";
|
|
25
|
+
export * from "./gcpOpenTelemetry.js";
|
|
26
|
+
export {
|
|
27
|
+
enableGoogleCloudTelemetry
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getCurrentEnv } from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { enableTelemetry } from 'genkit/tracing';\nimport { credentialsFromEnvironment } from './auth.js';\nimport { GcpLogger } from './gcpLogger.js';\nimport { GcpOpenTelemetry } from './gcpOpenTelemetry.js';\nimport { TelemetryConfigs } from './telemetry/defaults.js';\nimport type { GcpTelemetryConfig, GcpTelemetryConfigOptions } from './types.js';\n\n/**\n * Enables telemetry export to the Google Cloud Observability suite.\n *\n * @param options configuration options\n */\nexport function enableGoogleCloudTelemetry(\n options?: GcpTelemetryConfigOptions\n) {\n return enableTelemetry(\n configureGcpPlugin(options).then(async (pluginConfig) => {\n logger.init(await new GcpLogger(pluginConfig).getLogger(getCurrentEnv()));\n return new GcpOpenTelemetry(pluginConfig).getConfig();\n })\n );\n}\n\n/**\n * Create a configuration object for the plugin.\n * Not normally needed, but exposed for use by the Firebase plugin.\n */\nasync function configureGcpPlugin(\n options?: GcpTelemetryConfigOptions\n): Promise<GcpTelemetryConfig> {\n const envOptions = await credentialsFromEnvironment();\n return {\n projectId: options?.projectId || envOptions.projectId,\n credentials: options?.credentials || envOptions.credentials,\n ...TelemetryConfigs.defaults(options),\n };\n}\n\nexport * from './gcpLogger.js';\nexport * from './gcpOpenTelemetry.js';\nexport type { GcpTelemetryConfigOptions } from './types.js';\n"],"mappings":"AAgBA,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAQ1B,SAAS,2BACd,SACA;AACA,SAAO;AAAA,IACL,mBAAmB,OAAO,EAAE,KAAK,OAAO,iBAAiB;AACvD,aAAO,KAAK,MAAM,IAAI,UAAU,YAAY,EAAE,UAAU,cAAc,CAAC,CAAC;AACxE,aAAO,IAAI,iBAAiB,YAAY,EAAE,UAAU;AAAA,IACtD,CAAC;AAAA,EACH;AACF;AAMA,eAAe,mBACb,SAC6B;AAC7B,QAAM,aAAa,MAAM,2BAA2B;AACpD,SAAO;AAAA,IACL,WAAW,SAAS,aAAa,WAAW;AAAA,IAC5C,aAAa,SAAS,eAAe,WAAW;AAAA,IAChD,GAAG,iBAAiB,SAAS,OAAO;AAAA,EACtC;AACF;AAEA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Meter, Counter, Histogram } from '@opentelemetry/api';
|
|
2
|
+
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright 2024 Google LLC
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
declare const METER_NAME = "genkit";
|
|
21
|
+
declare const METRIC_NAME_PREFIX = "genkit";
|
|
22
|
+
declare function internalMetricNamespaceWrap(...namespaces: any[]): string;
|
|
23
|
+
type MetricCreateFn<T> = (meter: Meter) => T;
|
|
24
|
+
/**
|
|
25
|
+
* Wrapper for OpenTelemetry metrics.
|
|
26
|
+
*
|
|
27
|
+
* The OpenTelemetry {MeterProvider} can only be accessed through the metrics
|
|
28
|
+
* API after the NodeSDK library has been initialized. To prevent race
|
|
29
|
+
* conditions we defer the instantiation of the metric to when it is first
|
|
30
|
+
* ticked.
|
|
31
|
+
*/
|
|
32
|
+
declare class Metric<T> {
|
|
33
|
+
readonly createFn: MetricCreateFn<T>;
|
|
34
|
+
readonly meterName: string;
|
|
35
|
+
metric?: T;
|
|
36
|
+
constructor(createFn: MetricCreateFn<T>, meterName?: string);
|
|
37
|
+
get(): T;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Wrapper for an OpenTelemetry Counter.
|
|
41
|
+
*
|
|
42
|
+
* By using this wrapper, we defer initialization of the counter until it is
|
|
43
|
+
* need, which ensures that the OpenTelemetry SDK has been initialized before
|
|
44
|
+
* the metric has been defined.
|
|
45
|
+
*/
|
|
46
|
+
declare class MetricCounter extends Metric<Counter> {
|
|
47
|
+
constructor(name: string, options: any);
|
|
48
|
+
add(val?: number, opts?: any): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wrapper for an OpenTelemetry Histogram.
|
|
52
|
+
*
|
|
53
|
+
* By using this wrapper, we defer initialization of the counter until it is
|
|
54
|
+
* need, which ensures that the OpenTelemetry SDK has been initialized before
|
|
55
|
+
* the metric has been defined.
|
|
56
|
+
*/
|
|
57
|
+
declare class MetricHistogram extends Metric<Histogram> {
|
|
58
|
+
constructor(name: string, options: any);
|
|
59
|
+
record(val?: number, opts?: any): void;
|
|
60
|
+
}
|
|
61
|
+
interface Telemetry {
|
|
62
|
+
tick(span: ReadableSpan, logIO: boolean, projectId?: string): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { METER_NAME, METRIC_NAME_PREFIX, MetricCounter, MetricHistogram, type Telemetry, internalMetricNamespaceWrap };
|