autotel-plugins 0.19.25 → 0.19.27
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/dist/bigquery.cjs +393 -309
- package/dist/bigquery.d.cts +56 -44
- package/dist/bigquery.d.ts +56 -44
- package/dist/bigquery.js +389 -308
- package/dist/constants-DKKe2D25.d.cts +94 -47
- package/dist/constants-DKKe2D25.d.ts +94 -47
- package/dist/index.cjs +853 -627
- package/dist/index.d.cts +124 -4
- package/dist/index.d.ts +124 -4
- package/dist/index.js +856 -598
- package/dist/kafka.cjs +330 -226
- package/dist/kafka.d.cts +458 -345
- package/dist/kafka.d.ts +458 -345
- package/dist/kafka.js +326 -210
- package/dist/rabbitmq.cjs +117 -84
- package/dist/rabbitmq.d.cts +218 -151
- package/dist/rabbitmq.d.ts +218 -151
- package/dist/rabbitmq.js +129 -79
- package/package.json +2 -2
package/dist/bigquery.cjs
CHANGED
|
@@ -6,25 +6,25 @@ var traceHelpers = require('autotel/trace-helpers');
|
|
|
6
6
|
// src/bigquery/index.ts
|
|
7
7
|
|
|
8
8
|
// src/common/constants.ts
|
|
9
|
-
var SEMATTRS_DB_SYSTEM_NAME =
|
|
10
|
-
var SEMATTRS_DB_NAMESPACE =
|
|
11
|
-
var SEMATTRS_DB_COLLECTION_NAME =
|
|
12
|
-
var SEMATTRS_DB_OPERATION_NAME =
|
|
13
|
-
var SEMATTRS_DB_QUERY_TEXT =
|
|
14
|
-
var SEMATTRS_DB_QUERY_SUMMARY =
|
|
15
|
-
var SEMATTRS_GCP_BIGQUERY_JOB_ID =
|
|
16
|
-
var SEMATTRS_GCP_BIGQUERY_JOB_LOCATION =
|
|
17
|
-
var SEMATTRS_GCP_BIGQUERY_PROJECT_ID =
|
|
18
|
-
var SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE =
|
|
19
|
-
var SEMATTRS_GCP_BIGQUERY_QUERY_HASH =
|
|
20
|
-
var SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED =
|
|
21
|
-
var SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED =
|
|
22
|
-
var DEFAULT_TRACER_NAME =
|
|
23
|
-
var DEFAULT_DB_SYSTEM_NAME =
|
|
24
|
-
var INSTRUMENTED_FLAG =
|
|
25
|
-
var PROTOTYPE_INSTRUMENTED_FLAG =
|
|
26
|
-
var CONFIG_STORAGE_KEY =
|
|
27
|
-
var TRACER_STORAGE_KEY =
|
|
9
|
+
var SEMATTRS_DB_SYSTEM_NAME = 'db.system.name';
|
|
10
|
+
var SEMATTRS_DB_NAMESPACE = 'db.namespace';
|
|
11
|
+
var SEMATTRS_DB_COLLECTION_NAME = 'db.collection.name';
|
|
12
|
+
var SEMATTRS_DB_OPERATION_NAME = 'db.operation.name';
|
|
13
|
+
var SEMATTRS_DB_QUERY_TEXT = 'db.query.text';
|
|
14
|
+
var SEMATTRS_DB_QUERY_SUMMARY = 'db.query.summary';
|
|
15
|
+
var SEMATTRS_GCP_BIGQUERY_JOB_ID = 'gcp.bigquery.job.id';
|
|
16
|
+
var SEMATTRS_GCP_BIGQUERY_JOB_LOCATION = 'gcp.bigquery.job.location';
|
|
17
|
+
var SEMATTRS_GCP_BIGQUERY_PROJECT_ID = 'gcp.bigquery.project.id';
|
|
18
|
+
var SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE = 'gcp.bigquery.destination.table';
|
|
19
|
+
var SEMATTRS_GCP_BIGQUERY_QUERY_HASH = 'gcp.bigquery.query.hash';
|
|
20
|
+
var SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED = 'gcp.bigquery.rows.affected';
|
|
21
|
+
var SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED = 'gcp.bigquery.rows.returned';
|
|
22
|
+
var DEFAULT_TRACER_NAME = 'autotel-plugins/bigquery';
|
|
23
|
+
var DEFAULT_DB_SYSTEM_NAME = 'gcp.bigquery';
|
|
24
|
+
var INSTRUMENTED_FLAG = '__autotelBigQueryInstrumented';
|
|
25
|
+
var PROTOTYPE_INSTRUMENTED_FLAG = '__autotelBigQueryPrototypeInstrumented';
|
|
26
|
+
var CONFIG_STORAGE_KEY = '__autotelBigQueryConfig';
|
|
27
|
+
var TRACER_STORAGE_KEY = '__autotelBigQueryTracer';
|
|
28
28
|
function getInstanceConfig(instance) {
|
|
29
29
|
if (instance?.[CONFIG_STORAGE_KEY]) {
|
|
30
30
|
return instance[CONFIG_STORAGE_KEY];
|
|
@@ -72,13 +72,13 @@ function extractOperationType(query) {
|
|
|
72
72
|
function createQuerySummary(query) {
|
|
73
73
|
const operation = extractOperationType(query);
|
|
74
74
|
if (!operation) {
|
|
75
|
-
return
|
|
75
|
+
return 'UNKNOWN';
|
|
76
76
|
}
|
|
77
77
|
const patterns = {
|
|
78
78
|
SELECT: /FROM\s+(?<table>[\w.]+)/iu,
|
|
79
79
|
INSERT: /INTO\s+(?<table>[\w.]+)/iu,
|
|
80
80
|
UPDATE: /UPDATE\s+(?<table>[\w.]+)/iu,
|
|
81
|
-
DELETE: /FROM\s+(?<table>[\w.]+)/iu
|
|
81
|
+
DELETE: /FROM\s+(?<table>[\w.]+)/iu,
|
|
82
82
|
};
|
|
83
83
|
const pattern = patterns[operation];
|
|
84
84
|
if (pattern) {
|
|
@@ -93,9 +93,9 @@ function createQuerySummary(query) {
|
|
|
93
93
|
function sanitizeQuery(query) {
|
|
94
94
|
let sanitized = query.replaceAll(/'(?:[^'\\]|\\.)*'/gu, "'?'");
|
|
95
95
|
sanitized = sanitized.replaceAll(/"(?:[^"\\]|\\.)*"/gu, '"?"');
|
|
96
|
-
sanitized = sanitized.replaceAll(/\b\d+\.?\d*\b/gu,
|
|
97
|
-
sanitized = sanitized.replaceAll(/\b(?:true|false)\b/giu,
|
|
98
|
-
sanitized = sanitized.replaceAll(/\bNULL\b/giu,
|
|
96
|
+
sanitized = sanitized.replaceAll(/\b\d+\.?\d*\b/gu, '?');
|
|
97
|
+
sanitized = sanitized.replaceAll(/\b(?:true|false)\b/giu, '?');
|
|
98
|
+
sanitized = sanitized.replaceAll(/\bNULL\b/giu, '?');
|
|
99
99
|
return sanitized;
|
|
100
100
|
}
|
|
101
101
|
function truncateText(text, maxLength) {
|
|
@@ -124,7 +124,7 @@ function extractTableReference(obj) {
|
|
|
124
124
|
return {
|
|
125
125
|
projectId: obj.dataset?.parent?.projectId || obj.parent?.projectId,
|
|
126
126
|
datasetId: obj.dataset?.id || obj.parent?.datasetId,
|
|
127
|
-
tableId: obj.id
|
|
127
|
+
tableId: obj.id,
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
if (obj.metadata?.tableReference) {
|
|
@@ -139,55 +139,63 @@ function createSpan(tracer, operationName, target, projectId, config = {}) {
|
|
|
139
139
|
const spanName = target ? `${operationName} ${target}` : operationName;
|
|
140
140
|
const attributes = {
|
|
141
141
|
[SEMATTRS_DB_SYSTEM_NAME]: DEFAULT_DB_SYSTEM_NAME,
|
|
142
|
-
[SEMATTRS_DB_OPERATION_NAME]: operationName
|
|
142
|
+
[SEMATTRS_DB_OPERATION_NAME]: operationName,
|
|
143
143
|
};
|
|
144
144
|
if (projectId || config.projectId) {
|
|
145
|
-
attributes[SEMATTRS_GCP_BIGQUERY_PROJECT_ID] =
|
|
145
|
+
attributes[SEMATTRS_GCP_BIGQUERY_PROJECT_ID] =
|
|
146
|
+
projectId || config.projectId;
|
|
146
147
|
}
|
|
147
148
|
if (config.location) {
|
|
148
149
|
attributes[SEMATTRS_GCP_BIGQUERY_JOB_LOCATION] = config.location;
|
|
149
150
|
}
|
|
150
|
-
return tracer.startSpan(spanName, {
|
|
151
|
+
return tracer.startSpan(spanName, {
|
|
152
|
+
kind: autotel.SpanKind.CLIENT,
|
|
153
|
+
attributes,
|
|
154
|
+
});
|
|
151
155
|
}
|
|
152
156
|
function instrumentQueryMethod(BigQuery) {
|
|
153
157
|
const originalQuery = BigQuery.prototype.query;
|
|
154
|
-
if (typeof originalQuery !==
|
|
158
|
+
if (typeof originalQuery !== 'function') {
|
|
155
159
|
return;
|
|
156
160
|
}
|
|
157
|
-
BigQuery.prototype.query = function instrumentedQuery(
|
|
161
|
+
BigQuery.prototype.query = function instrumentedQuery(
|
|
162
|
+
query,
|
|
163
|
+
options,
|
|
164
|
+
callback,
|
|
165
|
+
) {
|
|
158
166
|
const config = getInstanceConfig(this);
|
|
159
167
|
const tracer = getInstanceTracer(this);
|
|
160
168
|
if (!config || !tracer) {
|
|
161
169
|
return originalQuery.call(this, query, options, callback);
|
|
162
170
|
}
|
|
163
|
-
const queryText = typeof query ===
|
|
171
|
+
const queryText = typeof query === 'string' ? query : query.query;
|
|
164
172
|
const projectId = extractProjectId(this);
|
|
165
173
|
const location = extractLocation(this, options);
|
|
166
|
-
const operation = queryText ? extractOperationType(queryText) :
|
|
167
|
-
const summary = queryText ? createQuerySummary(queryText) :
|
|
174
|
+
const operation = queryText ? extractOperationType(queryText) : 'QUERY';
|
|
175
|
+
const summary = queryText ? createQuerySummary(queryText) : 'QUERY';
|
|
168
176
|
const span = createSpan(
|
|
169
177
|
tracer,
|
|
170
|
-
operation ||
|
|
178
|
+
operation || 'QUERY',
|
|
171
179
|
summary,
|
|
172
180
|
projectId,
|
|
173
|
-
config
|
|
181
|
+
config,
|
|
174
182
|
);
|
|
175
183
|
if (location) {
|
|
176
184
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
177
185
|
}
|
|
178
186
|
span.setAttribute(SEMATTRS_DB_QUERY_SUMMARY, summary);
|
|
179
|
-
if (config.captureQueryText !==
|
|
180
|
-
if (config.captureQueryText ===
|
|
187
|
+
if (config.captureQueryText !== 'never' && queryText) {
|
|
188
|
+
if (config.captureQueryText === 'raw') {
|
|
181
189
|
const truncated = truncateText(
|
|
182
190
|
queryText,
|
|
183
|
-
config.maxQueryTextLength || 1e3
|
|
191
|
+
config.maxQueryTextLength || 1e3,
|
|
184
192
|
);
|
|
185
193
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
186
|
-
} else if (config.captureQueryText ===
|
|
194
|
+
} else if (config.captureQueryText === 'sanitized') {
|
|
187
195
|
const sanitized = sanitizeQuery(queryText);
|
|
188
196
|
const truncated = truncateText(
|
|
189
197
|
sanitized,
|
|
190
|
-
config.maxQueryTextLength || 1e3
|
|
198
|
+
config.maxQueryTextLength || 1e3,
|
|
191
199
|
);
|
|
192
200
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
193
201
|
}
|
|
@@ -198,16 +206,18 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
198
206
|
if (options?.destination) {
|
|
199
207
|
const dest = extractTableReference(options.destination);
|
|
200
208
|
if (dest.tableId) {
|
|
201
|
-
const destTable = dest.datasetId
|
|
209
|
+
const destTable = dest.datasetId
|
|
210
|
+
? `${dest.datasetId}.${dest.tableId}`
|
|
211
|
+
: dest.tableId;
|
|
202
212
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, destTable);
|
|
203
213
|
}
|
|
204
214
|
}
|
|
205
|
-
if (typeof callback ===
|
|
215
|
+
if (typeof callback === 'function') {
|
|
206
216
|
const wrappedCallback = (err, ...args) => {
|
|
207
217
|
if (err) {
|
|
208
218
|
traceHelpers.finalizeSpan(
|
|
209
219
|
span,
|
|
210
|
-
err instanceof Error ? err : new Error(String(err))
|
|
220
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
211
221
|
);
|
|
212
222
|
} else {
|
|
213
223
|
const [rows, response] = args;
|
|
@@ -217,7 +227,7 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
217
227
|
if (response?.jobReference?.jobId) {
|
|
218
228
|
span.setAttribute(
|
|
219
229
|
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
220
|
-
response.jobReference.jobId
|
|
230
|
+
response.jobReference.jobId,
|
|
221
231
|
);
|
|
222
232
|
}
|
|
223
233
|
traceHelpers.finalizeSpan(span);
|
|
@@ -229,32 +239,34 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
229
239
|
return traceHelpers.runWithSpan(span, () => {
|
|
230
240
|
try {
|
|
231
241
|
const result = originalQuery.call(this, query, options);
|
|
232
|
-
return Promise.resolve(result)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
242
|
+
return Promise.resolve(result)
|
|
243
|
+
.then(([rows, response]) => {
|
|
244
|
+
if (Array.isArray(rows)) {
|
|
245
|
+
span.setAttribute(
|
|
246
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
247
|
+
rows.length,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
if (response?.jobReference?.jobId) {
|
|
251
|
+
span.setAttribute(
|
|
252
|
+
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
253
|
+
response.jobReference.jobId,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
traceHelpers.finalizeSpan(span);
|
|
257
|
+
return [rows, response];
|
|
258
|
+
})
|
|
259
|
+
.catch((error) => {
|
|
260
|
+
traceHelpers.finalizeSpan(
|
|
261
|
+
span,
|
|
262
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
237
263
|
);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
span.setAttribute(
|
|
241
|
-
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
242
|
-
response.jobReference.jobId
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
traceHelpers.finalizeSpan(span);
|
|
246
|
-
return [rows, response];
|
|
247
|
-
}).catch((error) => {
|
|
248
|
-
traceHelpers.finalizeSpan(
|
|
249
|
-
span,
|
|
250
|
-
error instanceof Error ? error : new Error(String(error))
|
|
251
|
-
);
|
|
252
|
-
throw error;
|
|
253
|
-
});
|
|
264
|
+
throw error;
|
|
265
|
+
});
|
|
254
266
|
} catch (error) {
|
|
255
267
|
traceHelpers.finalizeSpan(
|
|
256
268
|
span,
|
|
257
|
-
error instanceof Error ? error : new Error(String(error))
|
|
269
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
258
270
|
);
|
|
259
271
|
throw error;
|
|
260
272
|
}
|
|
@@ -263,43 +275,45 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
263
275
|
}
|
|
264
276
|
function instrumentCreateQueryJob(BigQuery) {
|
|
265
277
|
const originalCreateQueryJob = BigQuery.prototype.createQueryJob;
|
|
266
|
-
if (typeof originalCreateQueryJob !==
|
|
278
|
+
if (typeof originalCreateQueryJob !== 'function') {
|
|
267
279
|
return;
|
|
268
280
|
}
|
|
269
|
-
BigQuery.prototype.createQueryJob = function instrumentedCreateQueryJob(
|
|
281
|
+
BigQuery.prototype.createQueryJob = function instrumentedCreateQueryJob(
|
|
282
|
+
options,
|
|
283
|
+
) {
|
|
270
284
|
const config = getInstanceConfig(this);
|
|
271
285
|
const tracer = getInstanceTracer(this);
|
|
272
286
|
if (!config || !tracer) {
|
|
273
287
|
return originalCreateQueryJob.call(this, options);
|
|
274
288
|
}
|
|
275
|
-
const queryText = typeof options ===
|
|
289
|
+
const queryText = typeof options === 'string' ? options : options.query;
|
|
276
290
|
const projectId = extractProjectId(this);
|
|
277
291
|
const location = extractLocation(this, options);
|
|
278
|
-
const operation = queryText ? extractOperationType(queryText) :
|
|
279
|
-
const summary = queryText ? createQuerySummary(queryText) :
|
|
292
|
+
const operation = queryText ? extractOperationType(queryText) : 'QUERY';
|
|
293
|
+
const summary = queryText ? createQuerySummary(queryText) : 'QUERY';
|
|
280
294
|
const span = createSpan(
|
|
281
295
|
tracer,
|
|
282
|
-
`${operation ||
|
|
296
|
+
`${operation || 'QUERY'}_JOB`,
|
|
283
297
|
summary,
|
|
284
298
|
projectId,
|
|
285
|
-
config
|
|
299
|
+
config,
|
|
286
300
|
);
|
|
287
301
|
if (location) {
|
|
288
302
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
289
303
|
}
|
|
290
304
|
span.setAttribute(SEMATTRS_DB_QUERY_SUMMARY, summary);
|
|
291
|
-
if (config.captureQueryText !==
|
|
292
|
-
if (config.captureQueryText ===
|
|
305
|
+
if (config.captureQueryText !== 'never' && queryText) {
|
|
306
|
+
if (config.captureQueryText === 'raw') {
|
|
293
307
|
const truncated = truncateText(
|
|
294
308
|
queryText,
|
|
295
|
-
config.maxQueryTextLength || 1e3
|
|
309
|
+
config.maxQueryTextLength || 1e3,
|
|
296
310
|
);
|
|
297
311
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
298
|
-
} else if (config.captureQueryText ===
|
|
312
|
+
} else if (config.captureQueryText === 'sanitized') {
|
|
299
313
|
const sanitized = sanitizeQuery(queryText);
|
|
300
314
|
const truncated = truncateText(
|
|
301
315
|
sanitized,
|
|
302
|
-
config.maxQueryTextLength || 1e3
|
|
316
|
+
config.maxQueryTextLength || 1e3,
|
|
303
317
|
);
|
|
304
318
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
305
319
|
}
|
|
@@ -310,35 +324,39 @@ function instrumentCreateQueryJob(BigQuery) {
|
|
|
310
324
|
if (options?.destination) {
|
|
311
325
|
const dest = extractTableReference(options.destination);
|
|
312
326
|
if (dest.tableId) {
|
|
313
|
-
const destTable = dest.datasetId
|
|
327
|
+
const destTable = dest.datasetId
|
|
328
|
+
? `${dest.datasetId}.${dest.tableId}`
|
|
329
|
+
: dest.tableId;
|
|
314
330
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, destTable);
|
|
315
331
|
}
|
|
316
332
|
}
|
|
317
333
|
return traceHelpers.runWithSpan(span, () => {
|
|
318
334
|
try {
|
|
319
335
|
const result = originalCreateQueryJob.call(this, options);
|
|
320
|
-
return Promise.resolve(result)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
336
|
+
return Promise.resolve(result)
|
|
337
|
+
.then(([job, response]) => {
|
|
338
|
+
if (job?.id) {
|
|
339
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
340
|
+
} else if (response?.jobReference?.jobId) {
|
|
341
|
+
span.setAttribute(
|
|
342
|
+
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
343
|
+
response.jobReference.jobId,
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
traceHelpers.finalizeSpan(span);
|
|
347
|
+
return [job, response];
|
|
348
|
+
})
|
|
349
|
+
.catch((error) => {
|
|
350
|
+
traceHelpers.finalizeSpan(
|
|
351
|
+
span,
|
|
352
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
327
353
|
);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
return [job, response];
|
|
331
|
-
}).catch((error) => {
|
|
332
|
-
traceHelpers.finalizeSpan(
|
|
333
|
-
span,
|
|
334
|
-
error instanceof Error ? error : new Error(String(error))
|
|
335
|
-
);
|
|
336
|
-
throw error;
|
|
337
|
-
});
|
|
354
|
+
throw error;
|
|
355
|
+
});
|
|
338
356
|
} catch (error) {
|
|
339
357
|
traceHelpers.finalizeSpan(
|
|
340
358
|
span,
|
|
341
|
-
error instanceof Error ? error : new Error(String(error))
|
|
359
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
342
360
|
);
|
|
343
361
|
throw error;
|
|
344
362
|
}
|
|
@@ -347,7 +365,7 @@ function instrumentCreateQueryJob(BigQuery) {
|
|
|
347
365
|
}
|
|
348
366
|
function instrumentTableInsert(Table) {
|
|
349
367
|
const originalInsert = Table.prototype.insert;
|
|
350
|
-
if (typeof originalInsert !==
|
|
368
|
+
if (typeof originalInsert !== 'function') {
|
|
351
369
|
return;
|
|
352
370
|
}
|
|
353
371
|
Table.prototype.insert = function instrumentedInsert(rows, options) {
|
|
@@ -360,10 +378,14 @@ function instrumentTableInsert(Table) {
|
|
|
360
378
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
361
379
|
const location = extractLocation(
|
|
362
380
|
this.dataset?.parent || this.parent,
|
|
363
|
-
options
|
|
381
|
+
options,
|
|
364
382
|
);
|
|
365
|
-
const target = tableRef.tableId
|
|
366
|
-
|
|
383
|
+
const target = tableRef.tableId
|
|
384
|
+
? tableRef.datasetId
|
|
385
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
386
|
+
: tableRef.tableId
|
|
387
|
+
: void 0;
|
|
388
|
+
const span = createSpan(tracer, 'INSERT', target, projectId, config);
|
|
367
389
|
if (location) {
|
|
368
390
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
369
391
|
}
|
|
@@ -378,26 +400,28 @@ function instrumentTableInsert(Table) {
|
|
|
378
400
|
return traceHelpers.runWithSpan(span, () => {
|
|
379
401
|
try {
|
|
380
402
|
const result = originalInsert.call(this, rows, options);
|
|
381
|
-
return Promise.resolve(result)
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
403
|
+
return Promise.resolve(result)
|
|
404
|
+
.then((response) => {
|
|
405
|
+
if (response?.insertErrors?.length > 0) {
|
|
406
|
+
span.setAttribute(
|
|
407
|
+
'gcp.bigquery.insert.errors',
|
|
408
|
+
response.insertErrors.length,
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
traceHelpers.finalizeSpan(span);
|
|
412
|
+
return response;
|
|
413
|
+
})
|
|
414
|
+
.catch((error) => {
|
|
415
|
+
traceHelpers.finalizeSpan(
|
|
416
|
+
span,
|
|
417
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
386
418
|
);
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return response;
|
|
390
|
-
}).catch((error) => {
|
|
391
|
-
traceHelpers.finalizeSpan(
|
|
392
|
-
span,
|
|
393
|
-
error instanceof Error ? error : new Error(String(error))
|
|
394
|
-
);
|
|
395
|
-
throw error;
|
|
396
|
-
});
|
|
419
|
+
throw error;
|
|
420
|
+
});
|
|
397
421
|
} catch (error) {
|
|
398
422
|
traceHelpers.finalizeSpan(
|
|
399
423
|
span,
|
|
400
|
-
error instanceof Error ? error : new Error(String(error))
|
|
424
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
401
425
|
);
|
|
402
426
|
throw error;
|
|
403
427
|
}
|
|
@@ -406,7 +430,7 @@ function instrumentTableInsert(Table) {
|
|
|
406
430
|
}
|
|
407
431
|
function instrumentTableGetRows(Table) {
|
|
408
432
|
const originalGetRows = Table.prototype.getRows;
|
|
409
|
-
if (typeof originalGetRows !==
|
|
433
|
+
if (typeof originalGetRows !== 'function') {
|
|
410
434
|
return;
|
|
411
435
|
}
|
|
412
436
|
Table.prototype.getRows = function instrumentedGetRows(options) {
|
|
@@ -419,10 +443,14 @@ function instrumentTableGetRows(Table) {
|
|
|
419
443
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
420
444
|
const location = extractLocation(
|
|
421
445
|
this.dataset?.parent || this.parent,
|
|
422
|
-
options
|
|
446
|
+
options,
|
|
423
447
|
);
|
|
424
|
-
const target = tableRef.tableId
|
|
425
|
-
|
|
448
|
+
const target = tableRef.tableId
|
|
449
|
+
? tableRef.datasetId
|
|
450
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
451
|
+
: tableRef.tableId
|
|
452
|
+
: void 0;
|
|
453
|
+
const span = createSpan(tracer, 'SELECT', target, projectId, config);
|
|
426
454
|
if (location) {
|
|
427
455
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
428
456
|
}
|
|
@@ -435,26 +463,28 @@ function instrumentTableGetRows(Table) {
|
|
|
435
463
|
return traceHelpers.runWithSpan(span, () => {
|
|
436
464
|
try {
|
|
437
465
|
const result = originalGetRows.call(this, options);
|
|
438
|
-
return Promise.resolve(result)
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
466
|
+
return Promise.resolve(result)
|
|
467
|
+
.then(([rows, nextQuery, apiResponse]) => {
|
|
468
|
+
if (Array.isArray(rows)) {
|
|
469
|
+
span.setAttribute(
|
|
470
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
471
|
+
rows.length,
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
traceHelpers.finalizeSpan(span);
|
|
475
|
+
return [rows, nextQuery, apiResponse];
|
|
476
|
+
})
|
|
477
|
+
.catch((error) => {
|
|
478
|
+
traceHelpers.finalizeSpan(
|
|
479
|
+
span,
|
|
480
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
443
481
|
);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return [rows, nextQuery, apiResponse];
|
|
447
|
-
}).catch((error) => {
|
|
448
|
-
traceHelpers.finalizeSpan(
|
|
449
|
-
span,
|
|
450
|
-
error instanceof Error ? error : new Error(String(error))
|
|
451
|
-
);
|
|
452
|
-
throw error;
|
|
453
|
-
});
|
|
482
|
+
throw error;
|
|
483
|
+
});
|
|
454
484
|
} catch (error) {
|
|
455
485
|
traceHelpers.finalizeSpan(
|
|
456
486
|
span,
|
|
457
|
-
error instanceof Error ? error : new Error(String(error))
|
|
487
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
458
488
|
);
|
|
459
489
|
throw error;
|
|
460
490
|
}
|
|
@@ -463,10 +493,13 @@ function instrumentTableGetRows(Table) {
|
|
|
463
493
|
}
|
|
464
494
|
function instrumentTableCreateLoadJob(Table) {
|
|
465
495
|
const originalCreateLoadJob = Table.prototype.createLoadJob;
|
|
466
|
-
if (typeof originalCreateLoadJob !==
|
|
496
|
+
if (typeof originalCreateLoadJob !== 'function') {
|
|
467
497
|
return;
|
|
468
498
|
}
|
|
469
|
-
Table.prototype.createLoadJob = function instrumentedCreateLoadJob(
|
|
499
|
+
Table.prototype.createLoadJob = function instrumentedCreateLoadJob(
|
|
500
|
+
source,
|
|
501
|
+
metadata,
|
|
502
|
+
) {
|
|
470
503
|
const config = getInstanceConfig(this);
|
|
471
504
|
const tracer = getInstanceTracer(this);
|
|
472
505
|
if (!config || !tracer) {
|
|
@@ -476,10 +509,14 @@ function instrumentTableCreateLoadJob(Table) {
|
|
|
476
509
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
477
510
|
const location = extractLocation(
|
|
478
511
|
this.dataset?.parent || this.parent,
|
|
479
|
-
metadata
|
|
512
|
+
metadata,
|
|
480
513
|
);
|
|
481
|
-
const target = tableRef.tableId
|
|
482
|
-
|
|
514
|
+
const target = tableRef.tableId
|
|
515
|
+
? tableRef.datasetId
|
|
516
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
517
|
+
: tableRef.tableId
|
|
518
|
+
: void 0;
|
|
519
|
+
const span = createSpan(tracer, 'LOAD', target, projectId, config);
|
|
483
520
|
if (location) {
|
|
484
521
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
485
522
|
}
|
|
@@ -490,28 +527,30 @@ function instrumentTableCreateLoadJob(Table) {
|
|
|
490
527
|
span.setAttribute(SEMATTRS_DB_COLLECTION_NAME, tableRef.tableId);
|
|
491
528
|
}
|
|
492
529
|
if (metadata?.sourceFormat) {
|
|
493
|
-
span.setAttribute(
|
|
530
|
+
span.setAttribute('gcp.bigquery.source.format', metadata.sourceFormat);
|
|
494
531
|
}
|
|
495
532
|
return traceHelpers.runWithSpan(span, () => {
|
|
496
533
|
try {
|
|
497
534
|
const result = originalCreateLoadJob.call(this, source, metadata);
|
|
498
|
-
return Promise.resolve(result)
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
535
|
+
return Promise.resolve(result)
|
|
536
|
+
.then(([job, response]) => {
|
|
537
|
+
if (job?.id) {
|
|
538
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
539
|
+
}
|
|
540
|
+
traceHelpers.finalizeSpan(span);
|
|
541
|
+
return [job, response];
|
|
542
|
+
})
|
|
543
|
+
.catch((error) => {
|
|
544
|
+
traceHelpers.finalizeSpan(
|
|
545
|
+
span,
|
|
546
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
547
|
+
);
|
|
548
|
+
throw error;
|
|
549
|
+
});
|
|
511
550
|
} catch (error) {
|
|
512
551
|
traceHelpers.finalizeSpan(
|
|
513
552
|
span,
|
|
514
|
-
error instanceof Error ? error : new Error(String(error))
|
|
553
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
515
554
|
);
|
|
516
555
|
throw error;
|
|
517
556
|
}
|
|
@@ -520,10 +559,13 @@ function instrumentTableCreateLoadJob(Table) {
|
|
|
520
559
|
}
|
|
521
560
|
function instrumentTableCreateCopyJob(Table) {
|
|
522
561
|
const originalCreateCopyJob = Table.prototype.createCopyJob;
|
|
523
|
-
if (typeof originalCreateCopyJob !==
|
|
562
|
+
if (typeof originalCreateCopyJob !== 'function') {
|
|
524
563
|
return;
|
|
525
564
|
}
|
|
526
|
-
Table.prototype.createCopyJob = function instrumentedCreateCopyJob(
|
|
565
|
+
Table.prototype.createCopyJob = function instrumentedCreateCopyJob(
|
|
566
|
+
destination,
|
|
567
|
+
metadata,
|
|
568
|
+
) {
|
|
527
569
|
const config = getInstanceConfig(this);
|
|
528
570
|
const tracer = getInstanceTracer(this);
|
|
529
571
|
if (!config || !tracer) {
|
|
@@ -533,16 +575,24 @@ function instrumentTableCreateCopyJob(Table) {
|
|
|
533
575
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
534
576
|
const location = extractLocation(
|
|
535
577
|
this.dataset?.parent || this.parent,
|
|
536
|
-
metadata
|
|
578
|
+
metadata,
|
|
537
579
|
);
|
|
538
|
-
const source = sourceRef.tableId
|
|
539
|
-
|
|
580
|
+
const source = sourceRef.tableId
|
|
581
|
+
? sourceRef.datasetId
|
|
582
|
+
? `${sourceRef.datasetId}.${sourceRef.tableId}`
|
|
583
|
+
: sourceRef.tableId
|
|
584
|
+
: 'unknown';
|
|
585
|
+
const span = createSpan(tracer, 'COPY', source, projectId, config);
|
|
540
586
|
if (location) {
|
|
541
587
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
542
588
|
}
|
|
543
589
|
if (destination) {
|
|
544
590
|
const destRef = extractTableReference(destination);
|
|
545
|
-
const destTable = destRef.tableId
|
|
591
|
+
const destTable = destRef.tableId
|
|
592
|
+
? destRef.datasetId
|
|
593
|
+
? `${destRef.datasetId}.${destRef.tableId}`
|
|
594
|
+
: destRef.tableId
|
|
595
|
+
: void 0;
|
|
546
596
|
if (destTable) {
|
|
547
597
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, destTable);
|
|
548
598
|
}
|
|
@@ -550,23 +600,25 @@ function instrumentTableCreateCopyJob(Table) {
|
|
|
550
600
|
return traceHelpers.runWithSpan(span, () => {
|
|
551
601
|
try {
|
|
552
602
|
const result = originalCreateCopyJob.call(this, destination, metadata);
|
|
553
|
-
return Promise.resolve(result)
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
603
|
+
return Promise.resolve(result)
|
|
604
|
+
.then(([job, response]) => {
|
|
605
|
+
if (job?.id) {
|
|
606
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
607
|
+
}
|
|
608
|
+
traceHelpers.finalizeSpan(span);
|
|
609
|
+
return [job, response];
|
|
610
|
+
})
|
|
611
|
+
.catch((error) => {
|
|
612
|
+
traceHelpers.finalizeSpan(
|
|
613
|
+
span,
|
|
614
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
615
|
+
);
|
|
616
|
+
throw error;
|
|
617
|
+
});
|
|
566
618
|
} catch (error) {
|
|
567
619
|
traceHelpers.finalizeSpan(
|
|
568
620
|
span,
|
|
569
|
-
error instanceof Error ? error : new Error(String(error))
|
|
621
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
570
622
|
);
|
|
571
623
|
throw error;
|
|
572
624
|
}
|
|
@@ -575,10 +627,13 @@ function instrumentTableCreateCopyJob(Table) {
|
|
|
575
627
|
}
|
|
576
628
|
function instrumentTableCreateExtractJob(Table) {
|
|
577
629
|
const originalCreateExtractJob = Table.prototype.createExtractJob;
|
|
578
|
-
if (typeof originalCreateExtractJob !==
|
|
630
|
+
if (typeof originalCreateExtractJob !== 'function') {
|
|
579
631
|
return;
|
|
580
632
|
}
|
|
581
|
-
Table.prototype.createExtractJob = function instrumentedCreateExtractJob(
|
|
633
|
+
Table.prototype.createExtractJob = function instrumentedCreateExtractJob(
|
|
634
|
+
destination,
|
|
635
|
+
metadata,
|
|
636
|
+
) {
|
|
582
637
|
const config = getInstanceConfig(this);
|
|
583
638
|
const tracer = getInstanceTracer(this);
|
|
584
639
|
if (!config || !tracer) {
|
|
@@ -588,10 +643,14 @@ function instrumentTableCreateExtractJob(Table) {
|
|
|
588
643
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
589
644
|
const location = extractLocation(
|
|
590
645
|
this.dataset?.parent || this.parent,
|
|
591
|
-
metadata
|
|
646
|
+
metadata,
|
|
592
647
|
);
|
|
593
|
-
const source = sourceRef.tableId
|
|
594
|
-
|
|
648
|
+
const source = sourceRef.tableId
|
|
649
|
+
? sourceRef.datasetId
|
|
650
|
+
? `${sourceRef.datasetId}.${sourceRef.tableId}`
|
|
651
|
+
: sourceRef.tableId
|
|
652
|
+
: 'unknown';
|
|
653
|
+
const span = createSpan(tracer, 'EXTRACT', source, projectId, config);
|
|
595
654
|
if (location) {
|
|
596
655
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
597
656
|
}
|
|
@@ -601,39 +660,41 @@ function instrumentTableCreateExtractJob(Table) {
|
|
|
601
660
|
if (sourceRef.tableId) {
|
|
602
661
|
span.setAttribute(SEMATTRS_DB_COLLECTION_NAME, sourceRef.tableId);
|
|
603
662
|
}
|
|
604
|
-
if (typeof destination ===
|
|
605
|
-
span.setAttribute(
|
|
663
|
+
if (typeof destination === 'string') {
|
|
664
|
+
span.setAttribute('gcp.bigquery.destination.uri', destination);
|
|
606
665
|
} else if (Array.isArray(destination) && destination.length > 0) {
|
|
607
|
-
span.setAttribute(
|
|
666
|
+
span.setAttribute('gcp.bigquery.destination.uri', destination[0]);
|
|
608
667
|
}
|
|
609
668
|
const format = metadata?.destinationFormat || metadata?.format;
|
|
610
669
|
if (format) {
|
|
611
|
-
span.setAttribute(
|
|
670
|
+
span.setAttribute('gcp.bigquery.destination.format', format);
|
|
612
671
|
}
|
|
613
672
|
return traceHelpers.runWithSpan(span, () => {
|
|
614
673
|
try {
|
|
615
674
|
const result = originalCreateExtractJob.call(
|
|
616
675
|
this,
|
|
617
676
|
destination,
|
|
618
|
-
metadata
|
|
677
|
+
metadata,
|
|
619
678
|
);
|
|
620
|
-
return Promise.resolve(result)
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
679
|
+
return Promise.resolve(result)
|
|
680
|
+
.then(([job, response]) => {
|
|
681
|
+
if (job?.id) {
|
|
682
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
683
|
+
}
|
|
684
|
+
traceHelpers.finalizeSpan(span);
|
|
685
|
+
return [job, response];
|
|
686
|
+
})
|
|
687
|
+
.catch((error) => {
|
|
688
|
+
traceHelpers.finalizeSpan(
|
|
689
|
+
span,
|
|
690
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
691
|
+
);
|
|
692
|
+
throw error;
|
|
693
|
+
});
|
|
633
694
|
} catch (error) {
|
|
634
695
|
traceHelpers.finalizeSpan(
|
|
635
696
|
span,
|
|
636
|
-
error instanceof Error ? error : new Error(String(error))
|
|
697
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
637
698
|
);
|
|
638
699
|
throw error;
|
|
639
700
|
}
|
|
@@ -642,10 +703,12 @@ function instrumentTableCreateExtractJob(Table) {
|
|
|
642
703
|
}
|
|
643
704
|
function instrumentJobGetQueryResults(Job) {
|
|
644
705
|
const originalGetQueryResults = Job.prototype.getQueryResults;
|
|
645
|
-
if (typeof originalGetQueryResults !==
|
|
706
|
+
if (typeof originalGetQueryResults !== 'function') {
|
|
646
707
|
return;
|
|
647
708
|
}
|
|
648
|
-
Job.prototype.getQueryResults = function instrumentedGetQueryResults(
|
|
709
|
+
Job.prototype.getQueryResults = function instrumentedGetQueryResults(
|
|
710
|
+
options,
|
|
711
|
+
) {
|
|
649
712
|
const config = getInstanceConfig(this);
|
|
650
713
|
const tracer = getInstanceTracer(this);
|
|
651
714
|
if (!config || !tracer) {
|
|
@@ -656,10 +719,10 @@ function instrumentJobGetQueryResults(Job) {
|
|
|
656
719
|
const location = this.location || options?.location;
|
|
657
720
|
const span = createSpan(
|
|
658
721
|
tracer,
|
|
659
|
-
|
|
722
|
+
'GET_QUERY_RESULTS',
|
|
660
723
|
void 0,
|
|
661
724
|
projectId,
|
|
662
|
-
config
|
|
725
|
+
config,
|
|
663
726
|
);
|
|
664
727
|
if (jobId) {
|
|
665
728
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, jobId);
|
|
@@ -670,26 +733,28 @@ function instrumentJobGetQueryResults(Job) {
|
|
|
670
733
|
return traceHelpers.runWithSpan(span, () => {
|
|
671
734
|
try {
|
|
672
735
|
const result = originalGetQueryResults.call(this, options);
|
|
673
|
-
return Promise.resolve(result)
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
736
|
+
return Promise.resolve(result)
|
|
737
|
+
.then(([rows, nextQuery, apiResponse]) => {
|
|
738
|
+
if (Array.isArray(rows)) {
|
|
739
|
+
span.setAttribute(
|
|
740
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
741
|
+
rows.length,
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
traceHelpers.finalizeSpan(span);
|
|
745
|
+
return [rows, nextQuery, apiResponse];
|
|
746
|
+
})
|
|
747
|
+
.catch((error) => {
|
|
748
|
+
traceHelpers.finalizeSpan(
|
|
749
|
+
span,
|
|
750
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
678
751
|
);
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
return [rows, nextQuery, apiResponse];
|
|
682
|
-
}).catch((error) => {
|
|
683
|
-
traceHelpers.finalizeSpan(
|
|
684
|
-
span,
|
|
685
|
-
error instanceof Error ? error : new Error(String(error))
|
|
686
|
-
);
|
|
687
|
-
throw error;
|
|
688
|
-
});
|
|
752
|
+
throw error;
|
|
753
|
+
});
|
|
689
754
|
} catch (error) {
|
|
690
755
|
traceHelpers.finalizeSpan(
|
|
691
756
|
span,
|
|
692
|
-
error instanceof Error ? error : new Error(String(error))
|
|
757
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
693
758
|
);
|
|
694
759
|
throw error;
|
|
695
760
|
}
|
|
@@ -698,7 +763,7 @@ function instrumentJobGetQueryResults(Job) {
|
|
|
698
763
|
}
|
|
699
764
|
function instrumentDatasetCreate(Dataset) {
|
|
700
765
|
const originalCreate = Dataset.prototype.create;
|
|
701
|
-
if (typeof originalCreate !==
|
|
766
|
+
if (typeof originalCreate !== 'function') {
|
|
702
767
|
return;
|
|
703
768
|
}
|
|
704
769
|
Dataset.prototype.create = function instrumentedCreate(options) {
|
|
@@ -712,10 +777,10 @@ function instrumentDatasetCreate(Dataset) {
|
|
|
712
777
|
const location = extractLocation(this.parent, options);
|
|
713
778
|
const span = createSpan(
|
|
714
779
|
tracer,
|
|
715
|
-
|
|
780
|
+
'CREATE_DATASET',
|
|
716
781
|
datasetId,
|
|
717
782
|
projectId,
|
|
718
|
-
config
|
|
783
|
+
config,
|
|
719
784
|
);
|
|
720
785
|
if (location) {
|
|
721
786
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
@@ -726,20 +791,22 @@ function instrumentDatasetCreate(Dataset) {
|
|
|
726
791
|
return traceHelpers.runWithSpan(span, () => {
|
|
727
792
|
try {
|
|
728
793
|
const result = originalCreate.call(this, options);
|
|
729
|
-
return Promise.resolve(result)
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
794
|
+
return Promise.resolve(result)
|
|
795
|
+
.then((response) => {
|
|
796
|
+
traceHelpers.finalizeSpan(span);
|
|
797
|
+
return response;
|
|
798
|
+
})
|
|
799
|
+
.catch((error) => {
|
|
800
|
+
traceHelpers.finalizeSpan(
|
|
801
|
+
span,
|
|
802
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
803
|
+
);
|
|
804
|
+
throw error;
|
|
805
|
+
});
|
|
739
806
|
} catch (error) {
|
|
740
807
|
traceHelpers.finalizeSpan(
|
|
741
808
|
span,
|
|
742
|
-
error instanceof Error ? error : new Error(String(error))
|
|
809
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
743
810
|
);
|
|
744
811
|
throw error;
|
|
745
812
|
}
|
|
@@ -748,7 +815,7 @@ function instrumentDatasetCreate(Dataset) {
|
|
|
748
815
|
}
|
|
749
816
|
function instrumentDatasetDelete(Dataset) {
|
|
750
817
|
const originalDelete = Dataset.prototype.delete;
|
|
751
|
-
if (typeof originalDelete !==
|
|
818
|
+
if (typeof originalDelete !== 'function') {
|
|
752
819
|
return;
|
|
753
820
|
}
|
|
754
821
|
Dataset.prototype.delete = function instrumentedDelete(options) {
|
|
@@ -761,10 +828,10 @@ function instrumentDatasetDelete(Dataset) {
|
|
|
761
828
|
const projectId = extractProjectId(this.parent);
|
|
762
829
|
const span = createSpan(
|
|
763
830
|
tracer,
|
|
764
|
-
|
|
831
|
+
'DELETE_DATASET',
|
|
765
832
|
datasetId,
|
|
766
833
|
projectId,
|
|
767
|
-
config
|
|
834
|
+
config,
|
|
768
835
|
);
|
|
769
836
|
if (datasetId) {
|
|
770
837
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, datasetId);
|
|
@@ -772,20 +839,22 @@ function instrumentDatasetDelete(Dataset) {
|
|
|
772
839
|
return traceHelpers.runWithSpan(span, () => {
|
|
773
840
|
try {
|
|
774
841
|
const result = originalDelete.call(this, options);
|
|
775
|
-
return Promise.resolve(result)
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
842
|
+
return Promise.resolve(result)
|
|
843
|
+
.then((response) => {
|
|
844
|
+
traceHelpers.finalizeSpan(span);
|
|
845
|
+
return response;
|
|
846
|
+
})
|
|
847
|
+
.catch((error) => {
|
|
848
|
+
traceHelpers.finalizeSpan(
|
|
849
|
+
span,
|
|
850
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
851
|
+
);
|
|
852
|
+
throw error;
|
|
853
|
+
});
|
|
785
854
|
} catch (error) {
|
|
786
855
|
traceHelpers.finalizeSpan(
|
|
787
856
|
span,
|
|
788
|
-
error instanceof Error ? error : new Error(String(error))
|
|
857
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
789
858
|
);
|
|
790
859
|
throw error;
|
|
791
860
|
}
|
|
@@ -794,10 +863,14 @@ function instrumentDatasetDelete(Dataset) {
|
|
|
794
863
|
}
|
|
795
864
|
function instrumentBigQueryCreateDataset(BigQuery) {
|
|
796
865
|
const originalCreateDataset = BigQuery.prototype.createDataset;
|
|
797
|
-
if (typeof originalCreateDataset !==
|
|
866
|
+
if (typeof originalCreateDataset !== 'function') {
|
|
798
867
|
return;
|
|
799
868
|
}
|
|
800
|
-
BigQuery.prototype.createDataset = function instrumentedCreateDataset(
|
|
869
|
+
BigQuery.prototype.createDataset = function instrumentedCreateDataset(
|
|
870
|
+
id,
|
|
871
|
+
options,
|
|
872
|
+
callback,
|
|
873
|
+
) {
|
|
801
874
|
const config = getInstanceConfig(this);
|
|
802
875
|
const tracer = getInstanceTracer(this);
|
|
803
876
|
if (!config || !tracer || !config.instrumentAdminOps) {
|
|
@@ -808,10 +881,10 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
808
881
|
const location = extractLocation(this, options);
|
|
809
882
|
const span = createSpan(
|
|
810
883
|
tracer,
|
|
811
|
-
|
|
884
|
+
'CREATE_DATASET',
|
|
812
885
|
datasetId,
|
|
813
886
|
projectId,
|
|
814
|
-
config
|
|
887
|
+
config,
|
|
815
888
|
);
|
|
816
889
|
if (location) {
|
|
817
890
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
@@ -819,12 +892,12 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
819
892
|
if (datasetId) {
|
|
820
893
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, datasetId);
|
|
821
894
|
}
|
|
822
|
-
if (typeof callback ===
|
|
895
|
+
if (typeof callback === 'function') {
|
|
823
896
|
const wrappedCallback = (err, ...args) => {
|
|
824
897
|
if (err) {
|
|
825
898
|
traceHelpers.finalizeSpan(
|
|
826
899
|
span,
|
|
827
|
-
err instanceof Error ? err : new Error(String(err))
|
|
900
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
828
901
|
);
|
|
829
902
|
} else {
|
|
830
903
|
traceHelpers.finalizeSpan(span);
|
|
@@ -836,20 +909,22 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
836
909
|
return traceHelpers.runWithSpan(span, () => {
|
|
837
910
|
try {
|
|
838
911
|
const result = originalCreateDataset.call(this, id, options);
|
|
839
|
-
return Promise.resolve(result)
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
912
|
+
return Promise.resolve(result)
|
|
913
|
+
.then((response) => {
|
|
914
|
+
traceHelpers.finalizeSpan(span);
|
|
915
|
+
return response;
|
|
916
|
+
})
|
|
917
|
+
.catch((error) => {
|
|
918
|
+
traceHelpers.finalizeSpan(
|
|
919
|
+
span,
|
|
920
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
921
|
+
);
|
|
922
|
+
throw error;
|
|
923
|
+
});
|
|
849
924
|
} catch (error) {
|
|
850
925
|
traceHelpers.finalizeSpan(
|
|
851
926
|
span,
|
|
852
|
-
error instanceof Error ? error : new Error(String(error))
|
|
927
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
853
928
|
);
|
|
854
929
|
throw error;
|
|
855
930
|
}
|
|
@@ -858,7 +933,7 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
858
933
|
}
|
|
859
934
|
function instrumentTableCreate(Table) {
|
|
860
935
|
const originalCreate = Table.prototype.create;
|
|
861
|
-
if (typeof originalCreate !==
|
|
936
|
+
if (typeof originalCreate !== 'function') {
|
|
862
937
|
return;
|
|
863
938
|
}
|
|
864
939
|
Table.prototype.create = function instrumentedCreate(options) {
|
|
@@ -869,8 +944,12 @@ function instrumentTableCreate(Table) {
|
|
|
869
944
|
}
|
|
870
945
|
const tableRef = extractTableReference(this);
|
|
871
946
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
872
|
-
const target = tableRef.tableId
|
|
873
|
-
|
|
947
|
+
const target = tableRef.tableId
|
|
948
|
+
? tableRef.datasetId
|
|
949
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
950
|
+
: tableRef.tableId
|
|
951
|
+
: void 0;
|
|
952
|
+
const span = createSpan(tracer, 'CREATE_TABLE', target, projectId, config);
|
|
874
953
|
if (tableRef.datasetId) {
|
|
875
954
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, tableRef.datasetId);
|
|
876
955
|
}
|
|
@@ -880,20 +959,22 @@ function instrumentTableCreate(Table) {
|
|
|
880
959
|
return traceHelpers.runWithSpan(span, () => {
|
|
881
960
|
try {
|
|
882
961
|
const result = originalCreate.call(this, options);
|
|
883
|
-
return Promise.resolve(result)
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
962
|
+
return Promise.resolve(result)
|
|
963
|
+
.then((response) => {
|
|
964
|
+
traceHelpers.finalizeSpan(span);
|
|
965
|
+
return response;
|
|
966
|
+
})
|
|
967
|
+
.catch((error) => {
|
|
968
|
+
traceHelpers.finalizeSpan(
|
|
969
|
+
span,
|
|
970
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
971
|
+
);
|
|
972
|
+
throw error;
|
|
973
|
+
});
|
|
893
974
|
} catch (error) {
|
|
894
975
|
traceHelpers.finalizeSpan(
|
|
895
976
|
span,
|
|
896
|
-
error instanceof Error ? error : new Error(String(error))
|
|
977
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
897
978
|
);
|
|
898
979
|
throw error;
|
|
899
980
|
}
|
|
@@ -902,7 +983,7 @@ function instrumentTableCreate(Table) {
|
|
|
902
983
|
}
|
|
903
984
|
function instrumentTableDelete(Table) {
|
|
904
985
|
const originalDelete = Table.prototype.delete;
|
|
905
|
-
if (typeof originalDelete !==
|
|
986
|
+
if (typeof originalDelete !== 'function') {
|
|
906
987
|
return;
|
|
907
988
|
}
|
|
908
989
|
Table.prototype.delete = function instrumentedDelete(options) {
|
|
@@ -913,8 +994,12 @@ function instrumentTableDelete(Table) {
|
|
|
913
994
|
}
|
|
914
995
|
const tableRef = extractTableReference(this);
|
|
915
996
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
916
|
-
const target = tableRef.tableId
|
|
917
|
-
|
|
997
|
+
const target = tableRef.tableId
|
|
998
|
+
? tableRef.datasetId
|
|
999
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
1000
|
+
: tableRef.tableId
|
|
1001
|
+
: void 0;
|
|
1002
|
+
const span = createSpan(tracer, 'DELETE_TABLE', target, projectId, config);
|
|
918
1003
|
if (tableRef.datasetId) {
|
|
919
1004
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, tableRef.datasetId);
|
|
920
1005
|
}
|
|
@@ -924,20 +1009,22 @@ function instrumentTableDelete(Table) {
|
|
|
924
1009
|
return traceHelpers.runWithSpan(span, () => {
|
|
925
1010
|
try {
|
|
926
1011
|
const result = originalDelete.call(this, options);
|
|
927
|
-
return Promise.resolve(result)
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1012
|
+
return Promise.resolve(result)
|
|
1013
|
+
.then((response) => {
|
|
1014
|
+
traceHelpers.finalizeSpan(span);
|
|
1015
|
+
return response;
|
|
1016
|
+
})
|
|
1017
|
+
.catch((error) => {
|
|
1018
|
+
traceHelpers.finalizeSpan(
|
|
1019
|
+
span,
|
|
1020
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
1021
|
+
);
|
|
1022
|
+
throw error;
|
|
1023
|
+
});
|
|
937
1024
|
} catch (error) {
|
|
938
1025
|
traceHelpers.finalizeSpan(
|
|
939
1026
|
span,
|
|
940
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1027
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
941
1028
|
);
|
|
942
1029
|
throw error;
|
|
943
1030
|
}
|
|
@@ -953,15 +1040,15 @@ function instrumentBigQuery(bigquery, config) {
|
|
|
953
1040
|
return bigquery;
|
|
954
1041
|
}
|
|
955
1042
|
const finalConfig = {
|
|
956
|
-
projectId: config?.projectId ||
|
|
957
|
-
location: config?.location ||
|
|
1043
|
+
projectId: config?.projectId || '',
|
|
1044
|
+
location: config?.location || '',
|
|
958
1045
|
tracerName: config?.tracerName || DEFAULT_TRACER_NAME,
|
|
959
|
-
captureQueryText: config?.captureQueryText ||
|
|
1046
|
+
captureQueryText: config?.captureQueryText || 'summary',
|
|
960
1047
|
maxQueryTextLength: config?.maxQueryTextLength || 1e3,
|
|
961
1048
|
includeQueryHash: config?.includeQueryHash ?? true,
|
|
962
1049
|
instrumentAdminOps: config?.instrumentAdminOps ?? false,
|
|
963
1050
|
instrumentBqmlOps: config?.instrumentBqmlOps ?? false,
|
|
964
|
-
instrumentRoutineOps: config?.instrumentRoutineOps ?? false
|
|
1051
|
+
instrumentRoutineOps: config?.instrumentRoutineOps ?? false,
|
|
965
1052
|
};
|
|
966
1053
|
const tracer = autotel.otelTrace.getTracer(finalConfig.tracerName);
|
|
967
1054
|
bq[CONFIG_STORAGE_KEY] = finalConfig;
|
|
@@ -973,18 +1060,17 @@ function instrumentBigQuery(bigquery, config) {
|
|
|
973
1060
|
instrumentBigQueryCreateDataset(BigQuery);
|
|
974
1061
|
if (bq.dataset) {
|
|
975
1062
|
try {
|
|
976
|
-
const tempDataset = bq.dataset(
|
|
1063
|
+
const tempDataset = bq.dataset('__temp__');
|
|
977
1064
|
const Dataset = tempDataset.constructor;
|
|
978
1065
|
instrumentDatasetCreate(Dataset);
|
|
979
1066
|
instrumentDatasetDelete(Dataset);
|
|
980
1067
|
tempDataset.dataset = null;
|
|
981
|
-
} catch {
|
|
982
|
-
}
|
|
1068
|
+
} catch {}
|
|
983
1069
|
}
|
|
984
1070
|
if (bq.dataset) {
|
|
985
1071
|
try {
|
|
986
|
-
const tempDataset = bq.dataset(
|
|
987
|
-
const tempTable = tempDataset.table(
|
|
1072
|
+
const tempDataset = bq.dataset('__temp__');
|
|
1073
|
+
const tempTable = tempDataset.table('__temp__');
|
|
988
1074
|
const Table = tempTable.constructor;
|
|
989
1075
|
instrumentTableInsert(Table);
|
|
990
1076
|
instrumentTableGetRows(Table);
|
|
@@ -995,17 +1081,15 @@ function instrumentBigQuery(bigquery, config) {
|
|
|
995
1081
|
instrumentTableDelete(Table);
|
|
996
1082
|
tempTable.table = null;
|
|
997
1083
|
tempDataset.dataset = null;
|
|
998
|
-
} catch {
|
|
999
|
-
}
|
|
1084
|
+
} catch {}
|
|
1000
1085
|
}
|
|
1001
1086
|
if (bq.job) {
|
|
1002
1087
|
try {
|
|
1003
|
-
const tempJob = bq.job(
|
|
1088
|
+
const tempJob = bq.job('__temp__');
|
|
1004
1089
|
const Job = tempJob.constructor;
|
|
1005
1090
|
instrumentJobGetQueryResults(Job);
|
|
1006
1091
|
tempJob.job = null;
|
|
1007
|
-
} catch {
|
|
1008
|
-
}
|
|
1092
|
+
} catch {}
|
|
1009
1093
|
}
|
|
1010
1094
|
BigQuery[PROTOTYPE_INSTRUMENTED_FLAG] = true;
|
|
1011
1095
|
}
|
|
@@ -1025,4 +1109,4 @@ var BigQueryInstrumentation = class {
|
|
|
1025
1109
|
exports.BigQueryInstrumentation = BigQueryInstrumentation;
|
|
1026
1110
|
exports.instrumentBigQuery = instrumentBigQuery;
|
|
1027
1111
|
//# sourceMappingURL=bigquery.cjs.map
|
|
1028
|
-
//# sourceMappingURL=bigquery.cjs.map
|
|
1112
|
+
//# sourceMappingURL=bigquery.cjs.map
|