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