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/index.js
CHANGED
|
@@ -1,60 +1,75 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
otelTrace,
|
|
3
|
+
propagation,
|
|
4
|
+
ROOT_CONTEXT,
|
|
5
|
+
context,
|
|
6
|
+
SpanKind,
|
|
7
|
+
SpanStatusCode,
|
|
8
|
+
} from 'autotel';
|
|
2
9
|
import { runWithSpan, finalizeSpan } from 'autotel/trace-helpers';
|
|
3
10
|
import { metrics } from '@opentelemetry/api';
|
|
4
11
|
|
|
5
12
|
// src/common/constants.ts
|
|
6
|
-
var SEMATTRS_DB_SYSTEM =
|
|
7
|
-
var SEMATTRS_DB_SYSTEM_NAME =
|
|
8
|
-
var SEMATTRS_DB_OPERATION =
|
|
9
|
-
var SEMATTRS_DB_STATEMENT =
|
|
10
|
-
var SEMATTRS_DB_NAME =
|
|
11
|
-
var SEMATTRS_DB_NAMESPACE =
|
|
12
|
-
var SEMATTRS_DB_COLLECTION_NAME =
|
|
13
|
-
var SEMATTRS_DB_OPERATION_NAME =
|
|
14
|
-
var SEMATTRS_DB_QUERY_TEXT =
|
|
15
|
-
var SEMATTRS_DB_QUERY_SUMMARY =
|
|
16
|
-
var SEMATTRS_NET_PEER_NAME =
|
|
17
|
-
var SEMATTRS_NET_PEER_PORT =
|
|
18
|
-
var SEMATTRS_MESSAGING_SYSTEM =
|
|
19
|
-
var SEMATTRS_MESSAGING_DESTINATION_NAME =
|
|
20
|
-
var SEMATTRS_MESSAGING_OPERATION =
|
|
21
|
-
var SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP =
|
|
22
|
-
var SEMATTRS_MESSAGING_KAFKA_PARTITION =
|
|
23
|
-
var SEMATTRS_MESSAGING_KAFKA_OFFSET =
|
|
24
|
-
var SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY =
|
|
25
|
-
var SEMATTRS_LINKED_TRACE_ID_COUNT =
|
|
26
|
-
var SEMATTRS_LINKED_TRACE_ID_HASH =
|
|
27
|
-
var CORRELATION_ID_HEADER =
|
|
28
|
-
var SEMATTRS_GCP_BIGQUERY_JOB_ID =
|
|
29
|
-
var SEMATTRS_GCP_BIGQUERY_JOB_LOCATION =
|
|
30
|
-
var SEMATTRS_GCP_BIGQUERY_PROJECT_ID =
|
|
31
|
-
var SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE =
|
|
32
|
-
var SEMATTRS_GCP_BIGQUERY_SOURCE_TABLES =
|
|
33
|
-
var SEMATTRS_GCP_BIGQUERY_STATEMENT_TYPE =
|
|
34
|
-
var SEMATTRS_GCP_BIGQUERY_QUERY_HASH =
|
|
35
|
-
var SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED =
|
|
36
|
-
var SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED =
|
|
37
|
-
var SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS =
|
|
38
|
-
var SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY =
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
|
|
13
|
+
var SEMATTRS_DB_SYSTEM = 'db.system';
|
|
14
|
+
var SEMATTRS_DB_SYSTEM_NAME = 'db.system.name';
|
|
15
|
+
var SEMATTRS_DB_OPERATION = 'db.operation';
|
|
16
|
+
var SEMATTRS_DB_STATEMENT = 'db.statement';
|
|
17
|
+
var SEMATTRS_DB_NAME = 'db.name';
|
|
18
|
+
var SEMATTRS_DB_NAMESPACE = 'db.namespace';
|
|
19
|
+
var SEMATTRS_DB_COLLECTION_NAME = 'db.collection.name';
|
|
20
|
+
var SEMATTRS_DB_OPERATION_NAME = 'db.operation.name';
|
|
21
|
+
var SEMATTRS_DB_QUERY_TEXT = 'db.query.text';
|
|
22
|
+
var SEMATTRS_DB_QUERY_SUMMARY = 'db.query.summary';
|
|
23
|
+
var SEMATTRS_NET_PEER_NAME = 'net.peer.name';
|
|
24
|
+
var SEMATTRS_NET_PEER_PORT = 'net.peer.port';
|
|
25
|
+
var SEMATTRS_MESSAGING_SYSTEM = 'messaging.system';
|
|
26
|
+
var SEMATTRS_MESSAGING_DESTINATION_NAME = 'messaging.destination.name';
|
|
27
|
+
var SEMATTRS_MESSAGING_OPERATION = 'messaging.operation';
|
|
28
|
+
var SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP = 'messaging.kafka.consumer.group';
|
|
29
|
+
var SEMATTRS_MESSAGING_KAFKA_PARTITION = 'messaging.kafka.partition';
|
|
30
|
+
var SEMATTRS_MESSAGING_KAFKA_OFFSET = 'messaging.kafka.offset';
|
|
31
|
+
var SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY = 'messaging.kafka.message.key';
|
|
32
|
+
var SEMATTRS_LINKED_TRACE_ID_COUNT = 'linked_trace_id_count';
|
|
33
|
+
var SEMATTRS_LINKED_TRACE_ID_HASH = 'linked_trace_id_hash';
|
|
34
|
+
var CORRELATION_ID_HEADER = 'x-correlation-id';
|
|
35
|
+
var SEMATTRS_GCP_BIGQUERY_JOB_ID = 'gcp.bigquery.job.id';
|
|
36
|
+
var SEMATTRS_GCP_BIGQUERY_JOB_LOCATION = 'gcp.bigquery.job.location';
|
|
37
|
+
var SEMATTRS_GCP_BIGQUERY_PROJECT_ID = 'gcp.bigquery.project.id';
|
|
38
|
+
var SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE = 'gcp.bigquery.destination.table';
|
|
39
|
+
var SEMATTRS_GCP_BIGQUERY_SOURCE_TABLES = 'gcp.bigquery.source.tables';
|
|
40
|
+
var SEMATTRS_GCP_BIGQUERY_STATEMENT_TYPE = 'gcp.bigquery.statement_type';
|
|
41
|
+
var SEMATTRS_GCP_BIGQUERY_QUERY_HASH = 'gcp.bigquery.query.hash';
|
|
42
|
+
var SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED = 'gcp.bigquery.rows.affected';
|
|
43
|
+
var SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED = 'gcp.bigquery.rows.returned';
|
|
44
|
+
var SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS = 'gcp.bigquery.schema.fields';
|
|
45
|
+
var SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY =
|
|
46
|
+
'messaging.rabbitmq.destination.routing_key';
|
|
47
|
+
var SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE =
|
|
48
|
+
'messaging.rabbitmq.destination.exchange';
|
|
49
|
+
var SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT = 'messaging.rabbitmq.ack_result';
|
|
50
|
+
var SEMATTRS_MESSAGING_RABBITMQ_REQUEUE = 'messaging.rabbitmq.requeue';
|
|
51
|
+
var SEMATTRS_MESSAGING_MESSAGE_ID = 'messaging.message.id';
|
|
52
|
+
var SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID =
|
|
53
|
+
'messaging.message.conversation_id';
|
|
54
|
+
var SEMATTRS_MESSAGING_CONSUMER_ID = 'messaging.consumer.id';
|
|
55
|
+
var SEMATTRS_MESSAGING_OPERATION_NAME = 'messaging.operation.name';
|
|
56
|
+
var SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT = 'messaging.batch.message_count';
|
|
57
|
+
var SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET =
|
|
58
|
+
'messaging.kafka.batch.first_offset';
|
|
59
|
+
var SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET =
|
|
60
|
+
'messaging.kafka.batch.last_offset';
|
|
61
|
+
var SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED =
|
|
62
|
+
'messaging.kafka.batch.messages_processed';
|
|
63
|
+
var SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED =
|
|
64
|
+
'messaging.kafka.batch.messages_failed';
|
|
65
|
+
var SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS =
|
|
66
|
+
'messaging.kafka.batch.processing_time_ms';
|
|
67
|
+
var DEFAULT_TRACER_NAME = 'autotel-plugins/bigquery';
|
|
68
|
+
var DEFAULT_DB_SYSTEM_NAME = 'gcp.bigquery';
|
|
69
|
+
var INSTRUMENTED_FLAG = '__autotelBigQueryInstrumented';
|
|
70
|
+
var PROTOTYPE_INSTRUMENTED_FLAG = '__autotelBigQueryPrototypeInstrumented';
|
|
71
|
+
var CONFIG_STORAGE_KEY = '__autotelBigQueryConfig';
|
|
72
|
+
var TRACER_STORAGE_KEY = '__autotelBigQueryTracer';
|
|
58
73
|
function getInstanceConfig(instance) {
|
|
59
74
|
if (instance?.[CONFIG_STORAGE_KEY]) {
|
|
60
75
|
return instance[CONFIG_STORAGE_KEY];
|
|
@@ -102,13 +117,13 @@ function extractOperationType(query) {
|
|
|
102
117
|
function createQuerySummary(query) {
|
|
103
118
|
const operation = extractOperationType(query);
|
|
104
119
|
if (!operation) {
|
|
105
|
-
return
|
|
120
|
+
return 'UNKNOWN';
|
|
106
121
|
}
|
|
107
122
|
const patterns = {
|
|
108
123
|
SELECT: /FROM\s+(?<table>[\w.]+)/iu,
|
|
109
124
|
INSERT: /INTO\s+(?<table>[\w.]+)/iu,
|
|
110
125
|
UPDATE: /UPDATE\s+(?<table>[\w.]+)/iu,
|
|
111
|
-
DELETE: /FROM\s+(?<table>[\w.]+)/iu
|
|
126
|
+
DELETE: /FROM\s+(?<table>[\w.]+)/iu,
|
|
112
127
|
};
|
|
113
128
|
const pattern = patterns[operation];
|
|
114
129
|
if (pattern) {
|
|
@@ -123,9 +138,9 @@ function createQuerySummary(query) {
|
|
|
123
138
|
function sanitizeQuery(query) {
|
|
124
139
|
let sanitized = query.replaceAll(/'(?:[^'\\]|\\.)*'/gu, "'?'");
|
|
125
140
|
sanitized = sanitized.replaceAll(/"(?:[^"\\]|\\.)*"/gu, '"?"');
|
|
126
|
-
sanitized = sanitized.replaceAll(/\b\d+\.?\d*\b/gu,
|
|
127
|
-
sanitized = sanitized.replaceAll(/\b(?:true|false)\b/giu,
|
|
128
|
-
sanitized = sanitized.replaceAll(/\bNULL\b/giu,
|
|
141
|
+
sanitized = sanitized.replaceAll(/\b\d+\.?\d*\b/gu, '?');
|
|
142
|
+
sanitized = sanitized.replaceAll(/\b(?:true|false)\b/giu, '?');
|
|
143
|
+
sanitized = sanitized.replaceAll(/\bNULL\b/giu, '?');
|
|
129
144
|
return sanitized;
|
|
130
145
|
}
|
|
131
146
|
function truncateText(text, maxLength) {
|
|
@@ -154,7 +169,7 @@ function extractTableReference(obj) {
|
|
|
154
169
|
return {
|
|
155
170
|
projectId: obj.dataset?.parent?.projectId || obj.parent?.projectId,
|
|
156
171
|
datasetId: obj.dataset?.id || obj.parent?.datasetId,
|
|
157
|
-
tableId: obj.id
|
|
172
|
+
tableId: obj.id,
|
|
158
173
|
};
|
|
159
174
|
}
|
|
160
175
|
if (obj.metadata?.tableReference) {
|
|
@@ -169,10 +184,11 @@ function createSpan(tracer, operationName, target, projectId, config = {}) {
|
|
|
169
184
|
const spanName = target ? `${operationName} ${target}` : operationName;
|
|
170
185
|
const attributes = {
|
|
171
186
|
[SEMATTRS_DB_SYSTEM_NAME]: DEFAULT_DB_SYSTEM_NAME,
|
|
172
|
-
[SEMATTRS_DB_OPERATION_NAME]: operationName
|
|
187
|
+
[SEMATTRS_DB_OPERATION_NAME]: operationName,
|
|
173
188
|
};
|
|
174
189
|
if (projectId || config.projectId) {
|
|
175
|
-
attributes[SEMATTRS_GCP_BIGQUERY_PROJECT_ID] =
|
|
190
|
+
attributes[SEMATTRS_GCP_BIGQUERY_PROJECT_ID] =
|
|
191
|
+
projectId || config.projectId;
|
|
176
192
|
}
|
|
177
193
|
if (config.location) {
|
|
178
194
|
attributes[SEMATTRS_GCP_BIGQUERY_JOB_LOCATION] = config.location;
|
|
@@ -181,43 +197,47 @@ function createSpan(tracer, operationName, target, projectId, config = {}) {
|
|
|
181
197
|
}
|
|
182
198
|
function instrumentQueryMethod(BigQuery) {
|
|
183
199
|
const originalQuery = BigQuery.prototype.query;
|
|
184
|
-
if (typeof originalQuery !==
|
|
200
|
+
if (typeof originalQuery !== 'function') {
|
|
185
201
|
return;
|
|
186
202
|
}
|
|
187
|
-
BigQuery.prototype.query = function instrumentedQuery(
|
|
203
|
+
BigQuery.prototype.query = function instrumentedQuery(
|
|
204
|
+
query,
|
|
205
|
+
options,
|
|
206
|
+
callback,
|
|
207
|
+
) {
|
|
188
208
|
const config = getInstanceConfig(this);
|
|
189
209
|
const tracer = getInstanceTracer(this);
|
|
190
210
|
if (!config || !tracer) {
|
|
191
211
|
return originalQuery.call(this, query, options, callback);
|
|
192
212
|
}
|
|
193
|
-
const queryText = typeof query ===
|
|
213
|
+
const queryText = typeof query === 'string' ? query : query.query;
|
|
194
214
|
const projectId = extractProjectId(this);
|
|
195
215
|
const location = extractLocation(this, options);
|
|
196
|
-
const operation = queryText ? extractOperationType(queryText) :
|
|
197
|
-
const summary = queryText ? createQuerySummary(queryText) :
|
|
216
|
+
const operation = queryText ? extractOperationType(queryText) : 'QUERY';
|
|
217
|
+
const summary = queryText ? createQuerySummary(queryText) : 'QUERY';
|
|
198
218
|
const span = createSpan(
|
|
199
219
|
tracer,
|
|
200
|
-
operation ||
|
|
220
|
+
operation || 'QUERY',
|
|
201
221
|
summary,
|
|
202
222
|
projectId,
|
|
203
|
-
config
|
|
223
|
+
config,
|
|
204
224
|
);
|
|
205
225
|
if (location) {
|
|
206
226
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
207
227
|
}
|
|
208
228
|
span.setAttribute(SEMATTRS_DB_QUERY_SUMMARY, summary);
|
|
209
|
-
if (config.captureQueryText !==
|
|
210
|
-
if (config.captureQueryText ===
|
|
229
|
+
if (config.captureQueryText !== 'never' && queryText) {
|
|
230
|
+
if (config.captureQueryText === 'raw') {
|
|
211
231
|
const truncated = truncateText(
|
|
212
232
|
queryText,
|
|
213
|
-
config.maxQueryTextLength || 1e3
|
|
233
|
+
config.maxQueryTextLength || 1e3,
|
|
214
234
|
);
|
|
215
235
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
216
|
-
} else if (config.captureQueryText ===
|
|
236
|
+
} else if (config.captureQueryText === 'sanitized') {
|
|
217
237
|
const sanitized = sanitizeQuery(queryText);
|
|
218
238
|
const truncated = truncateText(
|
|
219
239
|
sanitized,
|
|
220
|
-
config.maxQueryTextLength || 1e3
|
|
240
|
+
config.maxQueryTextLength || 1e3,
|
|
221
241
|
);
|
|
222
242
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
223
243
|
}
|
|
@@ -228,16 +248,18 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
228
248
|
if (options?.destination) {
|
|
229
249
|
const dest = extractTableReference(options.destination);
|
|
230
250
|
if (dest.tableId) {
|
|
231
|
-
const destTable = dest.datasetId
|
|
251
|
+
const destTable = dest.datasetId
|
|
252
|
+
? `${dest.datasetId}.${dest.tableId}`
|
|
253
|
+
: dest.tableId;
|
|
232
254
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, destTable);
|
|
233
255
|
}
|
|
234
256
|
}
|
|
235
|
-
if (typeof callback ===
|
|
257
|
+
if (typeof callback === 'function') {
|
|
236
258
|
const wrappedCallback = (err, ...args) => {
|
|
237
259
|
if (err) {
|
|
238
260
|
finalizeSpan(
|
|
239
261
|
span,
|
|
240
|
-
err instanceof Error ? err : new Error(String(err))
|
|
262
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
241
263
|
);
|
|
242
264
|
} else {
|
|
243
265
|
const [rows, response] = args;
|
|
@@ -247,7 +269,7 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
247
269
|
if (response?.jobReference?.jobId) {
|
|
248
270
|
span.setAttribute(
|
|
249
271
|
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
250
|
-
response.jobReference.jobId
|
|
272
|
+
response.jobReference.jobId,
|
|
251
273
|
);
|
|
252
274
|
}
|
|
253
275
|
finalizeSpan(span);
|
|
@@ -259,32 +281,34 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
259
281
|
return runWithSpan(span, () => {
|
|
260
282
|
try {
|
|
261
283
|
const result = originalQuery.call(this, query, options);
|
|
262
|
-
return Promise.resolve(result)
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
284
|
+
return Promise.resolve(result)
|
|
285
|
+
.then(([rows, response]) => {
|
|
286
|
+
if (Array.isArray(rows)) {
|
|
287
|
+
span.setAttribute(
|
|
288
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
289
|
+
rows.length,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
if (response?.jobReference?.jobId) {
|
|
293
|
+
span.setAttribute(
|
|
294
|
+
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
295
|
+
response.jobReference.jobId,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
finalizeSpan(span);
|
|
299
|
+
return [rows, response];
|
|
300
|
+
})
|
|
301
|
+
.catch((error) => {
|
|
302
|
+
finalizeSpan(
|
|
303
|
+
span,
|
|
304
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
273
305
|
);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return [rows, response];
|
|
277
|
-
}).catch((error) => {
|
|
278
|
-
finalizeSpan(
|
|
279
|
-
span,
|
|
280
|
-
error instanceof Error ? error : new Error(String(error))
|
|
281
|
-
);
|
|
282
|
-
throw error;
|
|
283
|
-
});
|
|
306
|
+
throw error;
|
|
307
|
+
});
|
|
284
308
|
} catch (error) {
|
|
285
309
|
finalizeSpan(
|
|
286
310
|
span,
|
|
287
|
-
error instanceof Error ? error : new Error(String(error))
|
|
311
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
288
312
|
);
|
|
289
313
|
throw error;
|
|
290
314
|
}
|
|
@@ -293,43 +317,45 @@ function instrumentQueryMethod(BigQuery) {
|
|
|
293
317
|
}
|
|
294
318
|
function instrumentCreateQueryJob(BigQuery) {
|
|
295
319
|
const originalCreateQueryJob = BigQuery.prototype.createQueryJob;
|
|
296
|
-
if (typeof originalCreateQueryJob !==
|
|
320
|
+
if (typeof originalCreateQueryJob !== 'function') {
|
|
297
321
|
return;
|
|
298
322
|
}
|
|
299
|
-
BigQuery.prototype.createQueryJob = function instrumentedCreateQueryJob(
|
|
323
|
+
BigQuery.prototype.createQueryJob = function instrumentedCreateQueryJob(
|
|
324
|
+
options,
|
|
325
|
+
) {
|
|
300
326
|
const config = getInstanceConfig(this);
|
|
301
327
|
const tracer = getInstanceTracer(this);
|
|
302
328
|
if (!config || !tracer) {
|
|
303
329
|
return originalCreateQueryJob.call(this, options);
|
|
304
330
|
}
|
|
305
|
-
const queryText = typeof options ===
|
|
331
|
+
const queryText = typeof options === 'string' ? options : options.query;
|
|
306
332
|
const projectId = extractProjectId(this);
|
|
307
333
|
const location = extractLocation(this, options);
|
|
308
|
-
const operation = queryText ? extractOperationType(queryText) :
|
|
309
|
-
const summary = queryText ? createQuerySummary(queryText) :
|
|
334
|
+
const operation = queryText ? extractOperationType(queryText) : 'QUERY';
|
|
335
|
+
const summary = queryText ? createQuerySummary(queryText) : 'QUERY';
|
|
310
336
|
const span = createSpan(
|
|
311
337
|
tracer,
|
|
312
|
-
`${operation ||
|
|
338
|
+
`${operation || 'QUERY'}_JOB`,
|
|
313
339
|
summary,
|
|
314
340
|
projectId,
|
|
315
|
-
config
|
|
341
|
+
config,
|
|
316
342
|
);
|
|
317
343
|
if (location) {
|
|
318
344
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
319
345
|
}
|
|
320
346
|
span.setAttribute(SEMATTRS_DB_QUERY_SUMMARY, summary);
|
|
321
|
-
if (config.captureQueryText !==
|
|
322
|
-
if (config.captureQueryText ===
|
|
347
|
+
if (config.captureQueryText !== 'never' && queryText) {
|
|
348
|
+
if (config.captureQueryText === 'raw') {
|
|
323
349
|
const truncated = truncateText(
|
|
324
350
|
queryText,
|
|
325
|
-
config.maxQueryTextLength || 1e3
|
|
351
|
+
config.maxQueryTextLength || 1e3,
|
|
326
352
|
);
|
|
327
353
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
328
|
-
} else if (config.captureQueryText ===
|
|
354
|
+
} else if (config.captureQueryText === 'sanitized') {
|
|
329
355
|
const sanitized = sanitizeQuery(queryText);
|
|
330
356
|
const truncated = truncateText(
|
|
331
357
|
sanitized,
|
|
332
|
-
config.maxQueryTextLength || 1e3
|
|
358
|
+
config.maxQueryTextLength || 1e3,
|
|
333
359
|
);
|
|
334
360
|
span.setAttribute(SEMATTRS_DB_QUERY_TEXT, truncated);
|
|
335
361
|
}
|
|
@@ -340,35 +366,39 @@ function instrumentCreateQueryJob(BigQuery) {
|
|
|
340
366
|
if (options?.destination) {
|
|
341
367
|
const dest = extractTableReference(options.destination);
|
|
342
368
|
if (dest.tableId) {
|
|
343
|
-
const destTable = dest.datasetId
|
|
369
|
+
const destTable = dest.datasetId
|
|
370
|
+
? `${dest.datasetId}.${dest.tableId}`
|
|
371
|
+
: dest.tableId;
|
|
344
372
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, destTable);
|
|
345
373
|
}
|
|
346
374
|
}
|
|
347
375
|
return runWithSpan(span, () => {
|
|
348
376
|
try {
|
|
349
377
|
const result = originalCreateQueryJob.call(this, options);
|
|
350
|
-
return Promise.resolve(result)
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
378
|
+
return Promise.resolve(result)
|
|
379
|
+
.then(([job, response]) => {
|
|
380
|
+
if (job?.id) {
|
|
381
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
382
|
+
} else if (response?.jobReference?.jobId) {
|
|
383
|
+
span.setAttribute(
|
|
384
|
+
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
385
|
+
response.jobReference.jobId,
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
finalizeSpan(span);
|
|
389
|
+
return [job, response];
|
|
390
|
+
})
|
|
391
|
+
.catch((error) => {
|
|
392
|
+
finalizeSpan(
|
|
393
|
+
span,
|
|
394
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
357
395
|
);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
return [job, response];
|
|
361
|
-
}).catch((error) => {
|
|
362
|
-
finalizeSpan(
|
|
363
|
-
span,
|
|
364
|
-
error instanceof Error ? error : new Error(String(error))
|
|
365
|
-
);
|
|
366
|
-
throw error;
|
|
367
|
-
});
|
|
396
|
+
throw error;
|
|
397
|
+
});
|
|
368
398
|
} catch (error) {
|
|
369
399
|
finalizeSpan(
|
|
370
400
|
span,
|
|
371
|
-
error instanceof Error ? error : new Error(String(error))
|
|
401
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
372
402
|
);
|
|
373
403
|
throw error;
|
|
374
404
|
}
|
|
@@ -377,7 +407,7 @@ function instrumentCreateQueryJob(BigQuery) {
|
|
|
377
407
|
}
|
|
378
408
|
function instrumentTableInsert(Table) {
|
|
379
409
|
const originalInsert = Table.prototype.insert;
|
|
380
|
-
if (typeof originalInsert !==
|
|
410
|
+
if (typeof originalInsert !== 'function') {
|
|
381
411
|
return;
|
|
382
412
|
}
|
|
383
413
|
Table.prototype.insert = function instrumentedInsert(rows, options) {
|
|
@@ -390,10 +420,14 @@ function instrumentTableInsert(Table) {
|
|
|
390
420
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
391
421
|
const location = extractLocation(
|
|
392
422
|
this.dataset?.parent || this.parent,
|
|
393
|
-
options
|
|
423
|
+
options,
|
|
394
424
|
);
|
|
395
|
-
const target = tableRef.tableId
|
|
396
|
-
|
|
425
|
+
const target = tableRef.tableId
|
|
426
|
+
? tableRef.datasetId
|
|
427
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
428
|
+
: tableRef.tableId
|
|
429
|
+
: void 0;
|
|
430
|
+
const span = createSpan(tracer, 'INSERT', target, projectId, config);
|
|
397
431
|
if (location) {
|
|
398
432
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
399
433
|
}
|
|
@@ -408,26 +442,28 @@ function instrumentTableInsert(Table) {
|
|
|
408
442
|
return runWithSpan(span, () => {
|
|
409
443
|
try {
|
|
410
444
|
const result = originalInsert.call(this, rows, options);
|
|
411
|
-
return Promise.resolve(result)
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
445
|
+
return Promise.resolve(result)
|
|
446
|
+
.then((response) => {
|
|
447
|
+
if (response?.insertErrors?.length > 0) {
|
|
448
|
+
span.setAttribute(
|
|
449
|
+
'gcp.bigquery.insert.errors',
|
|
450
|
+
response.insertErrors.length,
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
finalizeSpan(span);
|
|
454
|
+
return response;
|
|
455
|
+
})
|
|
456
|
+
.catch((error) => {
|
|
457
|
+
finalizeSpan(
|
|
458
|
+
span,
|
|
459
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
416
460
|
);
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return response;
|
|
420
|
-
}).catch((error) => {
|
|
421
|
-
finalizeSpan(
|
|
422
|
-
span,
|
|
423
|
-
error instanceof Error ? error : new Error(String(error))
|
|
424
|
-
);
|
|
425
|
-
throw error;
|
|
426
|
-
});
|
|
461
|
+
throw error;
|
|
462
|
+
});
|
|
427
463
|
} catch (error) {
|
|
428
464
|
finalizeSpan(
|
|
429
465
|
span,
|
|
430
|
-
error instanceof Error ? error : new Error(String(error))
|
|
466
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
431
467
|
);
|
|
432
468
|
throw error;
|
|
433
469
|
}
|
|
@@ -436,7 +472,7 @@ function instrumentTableInsert(Table) {
|
|
|
436
472
|
}
|
|
437
473
|
function instrumentTableGetRows(Table) {
|
|
438
474
|
const originalGetRows = Table.prototype.getRows;
|
|
439
|
-
if (typeof originalGetRows !==
|
|
475
|
+
if (typeof originalGetRows !== 'function') {
|
|
440
476
|
return;
|
|
441
477
|
}
|
|
442
478
|
Table.prototype.getRows = function instrumentedGetRows(options) {
|
|
@@ -449,10 +485,14 @@ function instrumentTableGetRows(Table) {
|
|
|
449
485
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
450
486
|
const location = extractLocation(
|
|
451
487
|
this.dataset?.parent || this.parent,
|
|
452
|
-
options
|
|
488
|
+
options,
|
|
453
489
|
);
|
|
454
|
-
const target = tableRef.tableId
|
|
455
|
-
|
|
490
|
+
const target = tableRef.tableId
|
|
491
|
+
? tableRef.datasetId
|
|
492
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
493
|
+
: tableRef.tableId
|
|
494
|
+
: void 0;
|
|
495
|
+
const span = createSpan(tracer, 'SELECT', target, projectId, config);
|
|
456
496
|
if (location) {
|
|
457
497
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
458
498
|
}
|
|
@@ -465,26 +505,28 @@ function instrumentTableGetRows(Table) {
|
|
|
465
505
|
return runWithSpan(span, () => {
|
|
466
506
|
try {
|
|
467
507
|
const result = originalGetRows.call(this, options);
|
|
468
|
-
return Promise.resolve(result)
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
508
|
+
return Promise.resolve(result)
|
|
509
|
+
.then(([rows, nextQuery, apiResponse]) => {
|
|
510
|
+
if (Array.isArray(rows)) {
|
|
511
|
+
span.setAttribute(
|
|
512
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
513
|
+
rows.length,
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
finalizeSpan(span);
|
|
517
|
+
return [rows, nextQuery, apiResponse];
|
|
518
|
+
})
|
|
519
|
+
.catch((error) => {
|
|
520
|
+
finalizeSpan(
|
|
521
|
+
span,
|
|
522
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
473
523
|
);
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
return [rows, nextQuery, apiResponse];
|
|
477
|
-
}).catch((error) => {
|
|
478
|
-
finalizeSpan(
|
|
479
|
-
span,
|
|
480
|
-
error instanceof Error ? error : new Error(String(error))
|
|
481
|
-
);
|
|
482
|
-
throw error;
|
|
483
|
-
});
|
|
524
|
+
throw error;
|
|
525
|
+
});
|
|
484
526
|
} catch (error) {
|
|
485
527
|
finalizeSpan(
|
|
486
528
|
span,
|
|
487
|
-
error instanceof Error ? error : new Error(String(error))
|
|
529
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
488
530
|
);
|
|
489
531
|
throw error;
|
|
490
532
|
}
|
|
@@ -493,10 +535,13 @@ function instrumentTableGetRows(Table) {
|
|
|
493
535
|
}
|
|
494
536
|
function instrumentTableCreateLoadJob(Table) {
|
|
495
537
|
const originalCreateLoadJob = Table.prototype.createLoadJob;
|
|
496
|
-
if (typeof originalCreateLoadJob !==
|
|
538
|
+
if (typeof originalCreateLoadJob !== 'function') {
|
|
497
539
|
return;
|
|
498
540
|
}
|
|
499
|
-
Table.prototype.createLoadJob = function instrumentedCreateLoadJob(
|
|
541
|
+
Table.prototype.createLoadJob = function instrumentedCreateLoadJob(
|
|
542
|
+
source,
|
|
543
|
+
metadata,
|
|
544
|
+
) {
|
|
500
545
|
const config = getInstanceConfig(this);
|
|
501
546
|
const tracer = getInstanceTracer(this);
|
|
502
547
|
if (!config || !tracer) {
|
|
@@ -506,10 +551,14 @@ function instrumentTableCreateLoadJob(Table) {
|
|
|
506
551
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
507
552
|
const location = extractLocation(
|
|
508
553
|
this.dataset?.parent || this.parent,
|
|
509
|
-
metadata
|
|
554
|
+
metadata,
|
|
510
555
|
);
|
|
511
|
-
const target = tableRef.tableId
|
|
512
|
-
|
|
556
|
+
const target = tableRef.tableId
|
|
557
|
+
? tableRef.datasetId
|
|
558
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
559
|
+
: tableRef.tableId
|
|
560
|
+
: void 0;
|
|
561
|
+
const span = createSpan(tracer, 'LOAD', target, projectId, config);
|
|
513
562
|
if (location) {
|
|
514
563
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
515
564
|
}
|
|
@@ -520,28 +569,30 @@ function instrumentTableCreateLoadJob(Table) {
|
|
|
520
569
|
span.setAttribute(SEMATTRS_DB_COLLECTION_NAME, tableRef.tableId);
|
|
521
570
|
}
|
|
522
571
|
if (metadata?.sourceFormat) {
|
|
523
|
-
span.setAttribute(
|
|
572
|
+
span.setAttribute('gcp.bigquery.source.format', metadata.sourceFormat);
|
|
524
573
|
}
|
|
525
574
|
return runWithSpan(span, () => {
|
|
526
575
|
try {
|
|
527
576
|
const result = originalCreateLoadJob.call(this, source, metadata);
|
|
528
|
-
return Promise.resolve(result)
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
577
|
+
return Promise.resolve(result)
|
|
578
|
+
.then(([job, response]) => {
|
|
579
|
+
if (job?.id) {
|
|
580
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
581
|
+
}
|
|
582
|
+
finalizeSpan(span);
|
|
583
|
+
return [job, response];
|
|
584
|
+
})
|
|
585
|
+
.catch((error) => {
|
|
586
|
+
finalizeSpan(
|
|
587
|
+
span,
|
|
588
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
589
|
+
);
|
|
590
|
+
throw error;
|
|
591
|
+
});
|
|
541
592
|
} catch (error) {
|
|
542
593
|
finalizeSpan(
|
|
543
594
|
span,
|
|
544
|
-
error instanceof Error ? error : new Error(String(error))
|
|
595
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
545
596
|
);
|
|
546
597
|
throw error;
|
|
547
598
|
}
|
|
@@ -550,10 +601,13 @@ function instrumentTableCreateLoadJob(Table) {
|
|
|
550
601
|
}
|
|
551
602
|
function instrumentTableCreateCopyJob(Table) {
|
|
552
603
|
const originalCreateCopyJob = Table.prototype.createCopyJob;
|
|
553
|
-
if (typeof originalCreateCopyJob !==
|
|
604
|
+
if (typeof originalCreateCopyJob !== 'function') {
|
|
554
605
|
return;
|
|
555
606
|
}
|
|
556
|
-
Table.prototype.createCopyJob = function instrumentedCreateCopyJob(
|
|
607
|
+
Table.prototype.createCopyJob = function instrumentedCreateCopyJob(
|
|
608
|
+
destination,
|
|
609
|
+
metadata,
|
|
610
|
+
) {
|
|
557
611
|
const config = getInstanceConfig(this);
|
|
558
612
|
const tracer = getInstanceTracer(this);
|
|
559
613
|
if (!config || !tracer) {
|
|
@@ -563,16 +617,24 @@ function instrumentTableCreateCopyJob(Table) {
|
|
|
563
617
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
564
618
|
const location = extractLocation(
|
|
565
619
|
this.dataset?.parent || this.parent,
|
|
566
|
-
metadata
|
|
620
|
+
metadata,
|
|
567
621
|
);
|
|
568
|
-
const source = sourceRef.tableId
|
|
569
|
-
|
|
622
|
+
const source = sourceRef.tableId
|
|
623
|
+
? sourceRef.datasetId
|
|
624
|
+
? `${sourceRef.datasetId}.${sourceRef.tableId}`
|
|
625
|
+
: sourceRef.tableId
|
|
626
|
+
: 'unknown';
|
|
627
|
+
const span = createSpan(tracer, 'COPY', source, projectId, config);
|
|
570
628
|
if (location) {
|
|
571
629
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
572
630
|
}
|
|
573
631
|
if (destination) {
|
|
574
632
|
const destRef = extractTableReference(destination);
|
|
575
|
-
const destTable = destRef.tableId
|
|
633
|
+
const destTable = destRef.tableId
|
|
634
|
+
? destRef.datasetId
|
|
635
|
+
? `${destRef.datasetId}.${destRef.tableId}`
|
|
636
|
+
: destRef.tableId
|
|
637
|
+
: void 0;
|
|
576
638
|
if (destTable) {
|
|
577
639
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, destTable);
|
|
578
640
|
}
|
|
@@ -580,23 +642,25 @@ function instrumentTableCreateCopyJob(Table) {
|
|
|
580
642
|
return runWithSpan(span, () => {
|
|
581
643
|
try {
|
|
582
644
|
const result = originalCreateCopyJob.call(this, destination, metadata);
|
|
583
|
-
return Promise.resolve(result)
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
645
|
+
return Promise.resolve(result)
|
|
646
|
+
.then(([job, response]) => {
|
|
647
|
+
if (job?.id) {
|
|
648
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
649
|
+
}
|
|
650
|
+
finalizeSpan(span);
|
|
651
|
+
return [job, response];
|
|
652
|
+
})
|
|
653
|
+
.catch((error) => {
|
|
654
|
+
finalizeSpan(
|
|
655
|
+
span,
|
|
656
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
657
|
+
);
|
|
658
|
+
throw error;
|
|
659
|
+
});
|
|
596
660
|
} catch (error) {
|
|
597
661
|
finalizeSpan(
|
|
598
662
|
span,
|
|
599
|
-
error instanceof Error ? error : new Error(String(error))
|
|
663
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
600
664
|
);
|
|
601
665
|
throw error;
|
|
602
666
|
}
|
|
@@ -605,10 +669,13 @@ function instrumentTableCreateCopyJob(Table) {
|
|
|
605
669
|
}
|
|
606
670
|
function instrumentTableCreateExtractJob(Table) {
|
|
607
671
|
const originalCreateExtractJob = Table.prototype.createExtractJob;
|
|
608
|
-
if (typeof originalCreateExtractJob !==
|
|
672
|
+
if (typeof originalCreateExtractJob !== 'function') {
|
|
609
673
|
return;
|
|
610
674
|
}
|
|
611
|
-
Table.prototype.createExtractJob = function instrumentedCreateExtractJob(
|
|
675
|
+
Table.prototype.createExtractJob = function instrumentedCreateExtractJob(
|
|
676
|
+
destination,
|
|
677
|
+
metadata,
|
|
678
|
+
) {
|
|
612
679
|
const config = getInstanceConfig(this);
|
|
613
680
|
const tracer = getInstanceTracer(this);
|
|
614
681
|
if (!config || !tracer) {
|
|
@@ -618,10 +685,14 @@ function instrumentTableCreateExtractJob(Table) {
|
|
|
618
685
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
619
686
|
const location = extractLocation(
|
|
620
687
|
this.dataset?.parent || this.parent,
|
|
621
|
-
metadata
|
|
688
|
+
metadata,
|
|
622
689
|
);
|
|
623
|
-
const source = sourceRef.tableId
|
|
624
|
-
|
|
690
|
+
const source = sourceRef.tableId
|
|
691
|
+
? sourceRef.datasetId
|
|
692
|
+
? `${sourceRef.datasetId}.${sourceRef.tableId}`
|
|
693
|
+
: sourceRef.tableId
|
|
694
|
+
: 'unknown';
|
|
695
|
+
const span = createSpan(tracer, 'EXTRACT', source, projectId, config);
|
|
625
696
|
if (location) {
|
|
626
697
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
627
698
|
}
|
|
@@ -631,39 +702,41 @@ function instrumentTableCreateExtractJob(Table) {
|
|
|
631
702
|
if (sourceRef.tableId) {
|
|
632
703
|
span.setAttribute(SEMATTRS_DB_COLLECTION_NAME, sourceRef.tableId);
|
|
633
704
|
}
|
|
634
|
-
if (typeof destination ===
|
|
635
|
-
span.setAttribute(
|
|
705
|
+
if (typeof destination === 'string') {
|
|
706
|
+
span.setAttribute('gcp.bigquery.destination.uri', destination);
|
|
636
707
|
} else if (Array.isArray(destination) && destination.length > 0) {
|
|
637
|
-
span.setAttribute(
|
|
708
|
+
span.setAttribute('gcp.bigquery.destination.uri', destination[0]);
|
|
638
709
|
}
|
|
639
710
|
const format = metadata?.destinationFormat || metadata?.format;
|
|
640
711
|
if (format) {
|
|
641
|
-
span.setAttribute(
|
|
712
|
+
span.setAttribute('gcp.bigquery.destination.format', format);
|
|
642
713
|
}
|
|
643
714
|
return runWithSpan(span, () => {
|
|
644
715
|
try {
|
|
645
716
|
const result = originalCreateExtractJob.call(
|
|
646
717
|
this,
|
|
647
718
|
destination,
|
|
648
|
-
metadata
|
|
719
|
+
metadata,
|
|
649
720
|
);
|
|
650
|
-
return Promise.resolve(result)
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
721
|
+
return Promise.resolve(result)
|
|
722
|
+
.then(([job, response]) => {
|
|
723
|
+
if (job?.id) {
|
|
724
|
+
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, job.id);
|
|
725
|
+
}
|
|
726
|
+
finalizeSpan(span);
|
|
727
|
+
return [job, response];
|
|
728
|
+
})
|
|
729
|
+
.catch((error) => {
|
|
730
|
+
finalizeSpan(
|
|
731
|
+
span,
|
|
732
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
733
|
+
);
|
|
734
|
+
throw error;
|
|
735
|
+
});
|
|
663
736
|
} catch (error) {
|
|
664
737
|
finalizeSpan(
|
|
665
738
|
span,
|
|
666
|
-
error instanceof Error ? error : new Error(String(error))
|
|
739
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
667
740
|
);
|
|
668
741
|
throw error;
|
|
669
742
|
}
|
|
@@ -672,10 +745,12 @@ function instrumentTableCreateExtractJob(Table) {
|
|
|
672
745
|
}
|
|
673
746
|
function instrumentJobGetQueryResults(Job) {
|
|
674
747
|
const originalGetQueryResults = Job.prototype.getQueryResults;
|
|
675
|
-
if (typeof originalGetQueryResults !==
|
|
748
|
+
if (typeof originalGetQueryResults !== 'function') {
|
|
676
749
|
return;
|
|
677
750
|
}
|
|
678
|
-
Job.prototype.getQueryResults = function instrumentedGetQueryResults(
|
|
751
|
+
Job.prototype.getQueryResults = function instrumentedGetQueryResults(
|
|
752
|
+
options,
|
|
753
|
+
) {
|
|
679
754
|
const config = getInstanceConfig(this);
|
|
680
755
|
const tracer = getInstanceTracer(this);
|
|
681
756
|
if (!config || !tracer) {
|
|
@@ -686,10 +761,10 @@ function instrumentJobGetQueryResults(Job) {
|
|
|
686
761
|
const location = this.location || options?.location;
|
|
687
762
|
const span = createSpan(
|
|
688
763
|
tracer,
|
|
689
|
-
|
|
764
|
+
'GET_QUERY_RESULTS',
|
|
690
765
|
void 0,
|
|
691
766
|
projectId,
|
|
692
|
-
config
|
|
767
|
+
config,
|
|
693
768
|
);
|
|
694
769
|
if (jobId) {
|
|
695
770
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_ID, jobId);
|
|
@@ -700,26 +775,28 @@ function instrumentJobGetQueryResults(Job) {
|
|
|
700
775
|
return runWithSpan(span, () => {
|
|
701
776
|
try {
|
|
702
777
|
const result = originalGetQueryResults.call(this, options);
|
|
703
|
-
return Promise.resolve(result)
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
778
|
+
return Promise.resolve(result)
|
|
779
|
+
.then(([rows, nextQuery, apiResponse]) => {
|
|
780
|
+
if (Array.isArray(rows)) {
|
|
781
|
+
span.setAttribute(
|
|
782
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
783
|
+
rows.length,
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
finalizeSpan(span);
|
|
787
|
+
return [rows, nextQuery, apiResponse];
|
|
788
|
+
})
|
|
789
|
+
.catch((error) => {
|
|
790
|
+
finalizeSpan(
|
|
791
|
+
span,
|
|
792
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
708
793
|
);
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return [rows, nextQuery, apiResponse];
|
|
712
|
-
}).catch((error) => {
|
|
713
|
-
finalizeSpan(
|
|
714
|
-
span,
|
|
715
|
-
error instanceof Error ? error : new Error(String(error))
|
|
716
|
-
);
|
|
717
|
-
throw error;
|
|
718
|
-
});
|
|
794
|
+
throw error;
|
|
795
|
+
});
|
|
719
796
|
} catch (error) {
|
|
720
797
|
finalizeSpan(
|
|
721
798
|
span,
|
|
722
|
-
error instanceof Error ? error : new Error(String(error))
|
|
799
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
723
800
|
);
|
|
724
801
|
throw error;
|
|
725
802
|
}
|
|
@@ -728,7 +805,7 @@ function instrumentJobGetQueryResults(Job) {
|
|
|
728
805
|
}
|
|
729
806
|
function instrumentDatasetCreate(Dataset) {
|
|
730
807
|
const originalCreate = Dataset.prototype.create;
|
|
731
|
-
if (typeof originalCreate !==
|
|
808
|
+
if (typeof originalCreate !== 'function') {
|
|
732
809
|
return;
|
|
733
810
|
}
|
|
734
811
|
Dataset.prototype.create = function instrumentedCreate(options) {
|
|
@@ -742,10 +819,10 @@ function instrumentDatasetCreate(Dataset) {
|
|
|
742
819
|
const location = extractLocation(this.parent, options);
|
|
743
820
|
const span = createSpan(
|
|
744
821
|
tracer,
|
|
745
|
-
|
|
822
|
+
'CREATE_DATASET',
|
|
746
823
|
datasetId,
|
|
747
824
|
projectId,
|
|
748
|
-
config
|
|
825
|
+
config,
|
|
749
826
|
);
|
|
750
827
|
if (location) {
|
|
751
828
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
@@ -756,20 +833,22 @@ function instrumentDatasetCreate(Dataset) {
|
|
|
756
833
|
return runWithSpan(span, () => {
|
|
757
834
|
try {
|
|
758
835
|
const result = originalCreate.call(this, options);
|
|
759
|
-
return Promise.resolve(result)
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
836
|
+
return Promise.resolve(result)
|
|
837
|
+
.then((response) => {
|
|
838
|
+
finalizeSpan(span);
|
|
839
|
+
return response;
|
|
840
|
+
})
|
|
841
|
+
.catch((error) => {
|
|
842
|
+
finalizeSpan(
|
|
843
|
+
span,
|
|
844
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
845
|
+
);
|
|
846
|
+
throw error;
|
|
847
|
+
});
|
|
769
848
|
} catch (error) {
|
|
770
849
|
finalizeSpan(
|
|
771
850
|
span,
|
|
772
|
-
error instanceof Error ? error : new Error(String(error))
|
|
851
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
773
852
|
);
|
|
774
853
|
throw error;
|
|
775
854
|
}
|
|
@@ -778,7 +857,7 @@ function instrumentDatasetCreate(Dataset) {
|
|
|
778
857
|
}
|
|
779
858
|
function instrumentDatasetDelete(Dataset) {
|
|
780
859
|
const originalDelete = Dataset.prototype.delete;
|
|
781
|
-
if (typeof originalDelete !==
|
|
860
|
+
if (typeof originalDelete !== 'function') {
|
|
782
861
|
return;
|
|
783
862
|
}
|
|
784
863
|
Dataset.prototype.delete = function instrumentedDelete(options) {
|
|
@@ -791,10 +870,10 @@ function instrumentDatasetDelete(Dataset) {
|
|
|
791
870
|
const projectId = extractProjectId(this.parent);
|
|
792
871
|
const span = createSpan(
|
|
793
872
|
tracer,
|
|
794
|
-
|
|
873
|
+
'DELETE_DATASET',
|
|
795
874
|
datasetId,
|
|
796
875
|
projectId,
|
|
797
|
-
config
|
|
876
|
+
config,
|
|
798
877
|
);
|
|
799
878
|
if (datasetId) {
|
|
800
879
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, datasetId);
|
|
@@ -802,20 +881,22 @@ function instrumentDatasetDelete(Dataset) {
|
|
|
802
881
|
return runWithSpan(span, () => {
|
|
803
882
|
try {
|
|
804
883
|
const result = originalDelete.call(this, options);
|
|
805
|
-
return Promise.resolve(result)
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
884
|
+
return Promise.resolve(result)
|
|
885
|
+
.then((response) => {
|
|
886
|
+
finalizeSpan(span);
|
|
887
|
+
return response;
|
|
888
|
+
})
|
|
889
|
+
.catch((error) => {
|
|
890
|
+
finalizeSpan(
|
|
891
|
+
span,
|
|
892
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
893
|
+
);
|
|
894
|
+
throw error;
|
|
895
|
+
});
|
|
815
896
|
} catch (error) {
|
|
816
897
|
finalizeSpan(
|
|
817
898
|
span,
|
|
818
|
-
error instanceof Error ? error : new Error(String(error))
|
|
899
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
819
900
|
);
|
|
820
901
|
throw error;
|
|
821
902
|
}
|
|
@@ -824,10 +905,14 @@ function instrumentDatasetDelete(Dataset) {
|
|
|
824
905
|
}
|
|
825
906
|
function instrumentBigQueryCreateDataset(BigQuery) {
|
|
826
907
|
const originalCreateDataset = BigQuery.prototype.createDataset;
|
|
827
|
-
if (typeof originalCreateDataset !==
|
|
908
|
+
if (typeof originalCreateDataset !== 'function') {
|
|
828
909
|
return;
|
|
829
910
|
}
|
|
830
|
-
BigQuery.prototype.createDataset = function instrumentedCreateDataset(
|
|
911
|
+
BigQuery.prototype.createDataset = function instrumentedCreateDataset(
|
|
912
|
+
id,
|
|
913
|
+
options,
|
|
914
|
+
callback,
|
|
915
|
+
) {
|
|
831
916
|
const config = getInstanceConfig(this);
|
|
832
917
|
const tracer = getInstanceTracer(this);
|
|
833
918
|
if (!config || !tracer || !config.instrumentAdminOps) {
|
|
@@ -838,10 +923,10 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
838
923
|
const location = extractLocation(this, options);
|
|
839
924
|
const span = createSpan(
|
|
840
925
|
tracer,
|
|
841
|
-
|
|
926
|
+
'CREATE_DATASET',
|
|
842
927
|
datasetId,
|
|
843
928
|
projectId,
|
|
844
|
-
config
|
|
929
|
+
config,
|
|
845
930
|
);
|
|
846
931
|
if (location) {
|
|
847
932
|
span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
|
|
@@ -849,12 +934,12 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
849
934
|
if (datasetId) {
|
|
850
935
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, datasetId);
|
|
851
936
|
}
|
|
852
|
-
if (typeof callback ===
|
|
937
|
+
if (typeof callback === 'function') {
|
|
853
938
|
const wrappedCallback = (err, ...args) => {
|
|
854
939
|
if (err) {
|
|
855
940
|
finalizeSpan(
|
|
856
941
|
span,
|
|
857
|
-
err instanceof Error ? err : new Error(String(err))
|
|
942
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
858
943
|
);
|
|
859
944
|
} else {
|
|
860
945
|
finalizeSpan(span);
|
|
@@ -866,20 +951,22 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
866
951
|
return runWithSpan(span, () => {
|
|
867
952
|
try {
|
|
868
953
|
const result = originalCreateDataset.call(this, id, options);
|
|
869
|
-
return Promise.resolve(result)
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
954
|
+
return Promise.resolve(result)
|
|
955
|
+
.then((response) => {
|
|
956
|
+
finalizeSpan(span);
|
|
957
|
+
return response;
|
|
958
|
+
})
|
|
959
|
+
.catch((error) => {
|
|
960
|
+
finalizeSpan(
|
|
961
|
+
span,
|
|
962
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
963
|
+
);
|
|
964
|
+
throw error;
|
|
965
|
+
});
|
|
879
966
|
} catch (error) {
|
|
880
967
|
finalizeSpan(
|
|
881
968
|
span,
|
|
882
|
-
error instanceof Error ? error : new Error(String(error))
|
|
969
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
883
970
|
);
|
|
884
971
|
throw error;
|
|
885
972
|
}
|
|
@@ -888,7 +975,7 @@ function instrumentBigQueryCreateDataset(BigQuery) {
|
|
|
888
975
|
}
|
|
889
976
|
function instrumentTableCreate(Table) {
|
|
890
977
|
const originalCreate = Table.prototype.create;
|
|
891
|
-
if (typeof originalCreate !==
|
|
978
|
+
if (typeof originalCreate !== 'function') {
|
|
892
979
|
return;
|
|
893
980
|
}
|
|
894
981
|
Table.prototype.create = function instrumentedCreate(options) {
|
|
@@ -899,8 +986,12 @@ function instrumentTableCreate(Table) {
|
|
|
899
986
|
}
|
|
900
987
|
const tableRef = extractTableReference(this);
|
|
901
988
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
902
|
-
const target = tableRef.tableId
|
|
903
|
-
|
|
989
|
+
const target = tableRef.tableId
|
|
990
|
+
? tableRef.datasetId
|
|
991
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
992
|
+
: tableRef.tableId
|
|
993
|
+
: void 0;
|
|
994
|
+
const span = createSpan(tracer, 'CREATE_TABLE', target, projectId, config);
|
|
904
995
|
if (tableRef.datasetId) {
|
|
905
996
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, tableRef.datasetId);
|
|
906
997
|
}
|
|
@@ -910,20 +1001,22 @@ function instrumentTableCreate(Table) {
|
|
|
910
1001
|
return runWithSpan(span, () => {
|
|
911
1002
|
try {
|
|
912
1003
|
const result = originalCreate.call(this, options);
|
|
913
|
-
return Promise.resolve(result)
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1004
|
+
return Promise.resolve(result)
|
|
1005
|
+
.then((response) => {
|
|
1006
|
+
finalizeSpan(span);
|
|
1007
|
+
return response;
|
|
1008
|
+
})
|
|
1009
|
+
.catch((error) => {
|
|
1010
|
+
finalizeSpan(
|
|
1011
|
+
span,
|
|
1012
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
1013
|
+
);
|
|
1014
|
+
throw error;
|
|
1015
|
+
});
|
|
923
1016
|
} catch (error) {
|
|
924
1017
|
finalizeSpan(
|
|
925
1018
|
span,
|
|
926
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1019
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
927
1020
|
);
|
|
928
1021
|
throw error;
|
|
929
1022
|
}
|
|
@@ -932,7 +1025,7 @@ function instrumentTableCreate(Table) {
|
|
|
932
1025
|
}
|
|
933
1026
|
function instrumentTableDelete(Table) {
|
|
934
1027
|
const originalDelete = Table.prototype.delete;
|
|
935
|
-
if (typeof originalDelete !==
|
|
1028
|
+
if (typeof originalDelete !== 'function') {
|
|
936
1029
|
return;
|
|
937
1030
|
}
|
|
938
1031
|
Table.prototype.delete = function instrumentedDelete(options) {
|
|
@@ -943,8 +1036,12 @@ function instrumentTableDelete(Table) {
|
|
|
943
1036
|
}
|
|
944
1037
|
const tableRef = extractTableReference(this);
|
|
945
1038
|
const projectId = extractProjectId(this.dataset?.parent || this.parent);
|
|
946
|
-
const target = tableRef.tableId
|
|
947
|
-
|
|
1039
|
+
const target = tableRef.tableId
|
|
1040
|
+
? tableRef.datasetId
|
|
1041
|
+
? `${tableRef.datasetId}.${tableRef.tableId}`
|
|
1042
|
+
: tableRef.tableId
|
|
1043
|
+
: void 0;
|
|
1044
|
+
const span = createSpan(tracer, 'DELETE_TABLE', target, projectId, config);
|
|
948
1045
|
if (tableRef.datasetId) {
|
|
949
1046
|
span.setAttribute(SEMATTRS_DB_NAMESPACE, tableRef.datasetId);
|
|
950
1047
|
}
|
|
@@ -954,20 +1051,22 @@ function instrumentTableDelete(Table) {
|
|
|
954
1051
|
return runWithSpan(span, () => {
|
|
955
1052
|
try {
|
|
956
1053
|
const result = originalDelete.call(this, options);
|
|
957
|
-
return Promise.resolve(result)
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1054
|
+
return Promise.resolve(result)
|
|
1055
|
+
.then((response) => {
|
|
1056
|
+
finalizeSpan(span);
|
|
1057
|
+
return response;
|
|
1058
|
+
})
|
|
1059
|
+
.catch((error) => {
|
|
1060
|
+
finalizeSpan(
|
|
1061
|
+
span,
|
|
1062
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
1063
|
+
);
|
|
1064
|
+
throw error;
|
|
1065
|
+
});
|
|
967
1066
|
} catch (error) {
|
|
968
1067
|
finalizeSpan(
|
|
969
1068
|
span,
|
|
970
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1069
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
971
1070
|
);
|
|
972
1071
|
throw error;
|
|
973
1072
|
}
|
|
@@ -983,15 +1082,15 @@ function instrumentBigQuery(bigquery, config) {
|
|
|
983
1082
|
return bigquery;
|
|
984
1083
|
}
|
|
985
1084
|
const finalConfig = {
|
|
986
|
-
projectId: config?.projectId ||
|
|
987
|
-
location: config?.location ||
|
|
1085
|
+
projectId: config?.projectId || '',
|
|
1086
|
+
location: config?.location || '',
|
|
988
1087
|
tracerName: config?.tracerName || DEFAULT_TRACER_NAME,
|
|
989
|
-
captureQueryText: config?.captureQueryText ||
|
|
1088
|
+
captureQueryText: config?.captureQueryText || 'summary',
|
|
990
1089
|
maxQueryTextLength: config?.maxQueryTextLength || 1e3,
|
|
991
1090
|
includeQueryHash: config?.includeQueryHash ?? true,
|
|
992
1091
|
instrumentAdminOps: config?.instrumentAdminOps ?? false,
|
|
993
1092
|
instrumentBqmlOps: config?.instrumentBqmlOps ?? false,
|
|
994
|
-
instrumentRoutineOps: config?.instrumentRoutineOps ?? false
|
|
1093
|
+
instrumentRoutineOps: config?.instrumentRoutineOps ?? false,
|
|
995
1094
|
};
|
|
996
1095
|
const tracer = otelTrace.getTracer(finalConfig.tracerName);
|
|
997
1096
|
bq[CONFIG_STORAGE_KEY] = finalConfig;
|
|
@@ -1003,18 +1102,17 @@ function instrumentBigQuery(bigquery, config) {
|
|
|
1003
1102
|
instrumentBigQueryCreateDataset(BigQuery);
|
|
1004
1103
|
if (bq.dataset) {
|
|
1005
1104
|
try {
|
|
1006
|
-
const tempDataset = bq.dataset(
|
|
1105
|
+
const tempDataset = bq.dataset('__temp__');
|
|
1007
1106
|
const Dataset = tempDataset.constructor;
|
|
1008
1107
|
instrumentDatasetCreate(Dataset);
|
|
1009
1108
|
instrumentDatasetDelete(Dataset);
|
|
1010
1109
|
tempDataset.dataset = null;
|
|
1011
|
-
} catch {
|
|
1012
|
-
}
|
|
1110
|
+
} catch {}
|
|
1013
1111
|
}
|
|
1014
1112
|
if (bq.dataset) {
|
|
1015
1113
|
try {
|
|
1016
|
-
const tempDataset = bq.dataset(
|
|
1017
|
-
const tempTable = tempDataset.table(
|
|
1114
|
+
const tempDataset = bq.dataset('__temp__');
|
|
1115
|
+
const tempTable = tempDataset.table('__temp__');
|
|
1018
1116
|
const Table = tempTable.constructor;
|
|
1019
1117
|
instrumentTableInsert(Table);
|
|
1020
1118
|
instrumentTableGetRows(Table);
|
|
@@ -1025,17 +1123,15 @@ function instrumentBigQuery(bigquery, config) {
|
|
|
1025
1123
|
instrumentTableDelete(Table);
|
|
1026
1124
|
tempTable.table = null;
|
|
1027
1125
|
tempDataset.dataset = null;
|
|
1028
|
-
} catch {
|
|
1029
|
-
}
|
|
1126
|
+
} catch {}
|
|
1030
1127
|
}
|
|
1031
1128
|
if (bq.job) {
|
|
1032
1129
|
try {
|
|
1033
|
-
const tempJob = bq.job(
|
|
1130
|
+
const tempJob = bq.job('__temp__');
|
|
1034
1131
|
const Job = tempJob.constructor;
|
|
1035
1132
|
instrumentJobGetQueryResults(Job);
|
|
1036
1133
|
tempJob.job = null;
|
|
1037
|
-
} catch {
|
|
1038
|
-
}
|
|
1134
|
+
} catch {}
|
|
1039
1135
|
}
|
|
1040
1136
|
BigQuery[PROTOTYPE_INSTRUMENTED_FLAG] = true;
|
|
1041
1137
|
}
|
|
@@ -1061,7 +1157,7 @@ function normalizeHeaders(headers) {
|
|
|
1061
1157
|
if (value === void 0) {
|
|
1062
1158
|
continue;
|
|
1063
1159
|
}
|
|
1064
|
-
normalized[key] = Buffer.isBuffer(value) ? value.toString(
|
|
1160
|
+
normalized[key] = Buffer.isBuffer(value) ? value.toString('utf8') : value;
|
|
1065
1161
|
}
|
|
1066
1162
|
return normalized;
|
|
1067
1163
|
}
|
|
@@ -1077,7 +1173,7 @@ var caseInsensitiveGetter = {
|
|
|
1077
1173
|
},
|
|
1078
1174
|
keys(carrier) {
|
|
1079
1175
|
return Object.keys(carrier);
|
|
1080
|
-
}
|
|
1176
|
+
},
|
|
1081
1177
|
};
|
|
1082
1178
|
function extractTraceContext(headers) {
|
|
1083
1179
|
return propagation.extract(ROOT_CONTEXT, headers, caseInsensitiveGetter);
|
|
@@ -1085,11 +1181,11 @@ function extractTraceContext(headers) {
|
|
|
1085
1181
|
var headerSetter = {
|
|
1086
1182
|
set(carrier, key, value) {
|
|
1087
1183
|
carrier[key] = value;
|
|
1088
|
-
}
|
|
1184
|
+
},
|
|
1089
1185
|
};
|
|
1090
1186
|
function deriveCorrelationId() {
|
|
1091
1187
|
const activeBaggage = propagation.getActiveBaggage();
|
|
1092
|
-
const baggageCorrelationId = activeBaggage?.getEntry(
|
|
1188
|
+
const baggageCorrelationId = activeBaggage?.getEntry('correlation-id');
|
|
1093
1189
|
if (baggageCorrelationId?.value) {
|
|
1094
1190
|
return baggageCorrelationId.value;
|
|
1095
1191
|
}
|
|
@@ -1098,7 +1194,7 @@ function deriveCorrelationId() {
|
|
|
1098
1194
|
const spanContext = activeSpan.spanContext();
|
|
1099
1195
|
return spanContext.traceId.slice(0, 16);
|
|
1100
1196
|
}
|
|
1101
|
-
return
|
|
1197
|
+
return '';
|
|
1102
1198
|
}
|
|
1103
1199
|
function extractCorrelationId(headers) {
|
|
1104
1200
|
const lowerKey = CORRELATION_ID_HEADER.toLowerCase();
|
|
@@ -1121,21 +1217,26 @@ function injectTraceHeaders(base = {}, options = {}) {
|
|
|
1121
1217
|
}
|
|
1122
1218
|
return carrier;
|
|
1123
1219
|
}
|
|
1124
|
-
var DEFAULT_TRACER_NAME2 =
|
|
1220
|
+
var DEFAULT_TRACER_NAME2 = 'autotel-plugins/kafka';
|
|
1125
1221
|
function isValidSpanContext(spanContext) {
|
|
1126
|
-
return !!(
|
|
1222
|
+
return !!(
|
|
1223
|
+
spanContext &&
|
|
1224
|
+
spanContext.traceId &&
|
|
1225
|
+
spanContext.spanId &&
|
|
1226
|
+
otelTrace.isSpanContextValid(spanContext)
|
|
1227
|
+
);
|
|
1127
1228
|
}
|
|
1128
1229
|
async function withProcessingSpan(descriptor, fn) {
|
|
1129
1230
|
const {
|
|
1130
1231
|
name,
|
|
1131
1232
|
headers,
|
|
1132
|
-
contextMode =
|
|
1233
|
+
contextMode = 'inherit',
|
|
1133
1234
|
links = [],
|
|
1134
1235
|
topic,
|
|
1135
1236
|
consumerGroup,
|
|
1136
1237
|
partition,
|
|
1137
1238
|
offset,
|
|
1138
|
-
key
|
|
1239
|
+
key,
|
|
1139
1240
|
} = descriptor;
|
|
1140
1241
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME2);
|
|
1141
1242
|
const normalizedHeaders = normalizeHeaders(headers);
|
|
@@ -1144,22 +1245,22 @@ async function withProcessingSpan(descriptor, fn) {
|
|
|
1144
1245
|
const { parentContext, spanLinks } = resolveContextAndLinks(
|
|
1145
1246
|
contextMode,
|
|
1146
1247
|
extractedSpanContext,
|
|
1147
|
-
links
|
|
1248
|
+
links,
|
|
1148
1249
|
);
|
|
1149
1250
|
const span = tracer.startSpan(
|
|
1150
1251
|
name,
|
|
1151
1252
|
{
|
|
1152
1253
|
kind: SpanKind.CONSUMER,
|
|
1153
|
-
links: spanLinks
|
|
1254
|
+
links: spanLinks,
|
|
1154
1255
|
},
|
|
1155
|
-
parentContext
|
|
1256
|
+
parentContext,
|
|
1156
1257
|
);
|
|
1157
1258
|
setMessagingAttributes(span, {
|
|
1158
1259
|
topic,
|
|
1159
1260
|
consumerGroup,
|
|
1160
1261
|
partition,
|
|
1161
1262
|
offset,
|
|
1162
|
-
key
|
|
1263
|
+
key,
|
|
1163
1264
|
});
|
|
1164
1265
|
const spanContext = otelTrace.setSpan(context.active(), span);
|
|
1165
1266
|
try {
|
|
@@ -1180,14 +1281,18 @@ async function withProcessingSpan(descriptor, fn) {
|
|
|
1180
1281
|
throw error;
|
|
1181
1282
|
}
|
|
1182
1283
|
}
|
|
1183
|
-
function resolveContextAndLinks(
|
|
1284
|
+
function resolveContextAndLinks(
|
|
1285
|
+
contextMode,
|
|
1286
|
+
extractedSpanContext,
|
|
1287
|
+
additionalLinks,
|
|
1288
|
+
) {
|
|
1184
1289
|
const activeSpan = otelTrace.getActiveSpan();
|
|
1185
1290
|
const activeContext = context.active();
|
|
1186
1291
|
const hasActiveSpan = activeSpan !== void 0;
|
|
1187
1292
|
const hasValidExtracted = isValidSpanContext(extractedSpanContext);
|
|
1188
1293
|
const spanLinks = [...additionalLinks];
|
|
1189
1294
|
switch (contextMode) {
|
|
1190
|
-
case
|
|
1295
|
+
case 'inherit': {
|
|
1191
1296
|
if (hasActiveSpan) {
|
|
1192
1297
|
if (hasValidExtracted) {
|
|
1193
1298
|
const activeSpanContext = activeSpan.spanContext();
|
|
@@ -1200,20 +1305,20 @@ function resolveContextAndLinks(contextMode, extractedSpanContext, additionalLin
|
|
|
1200
1305
|
if (hasValidExtracted) {
|
|
1201
1306
|
const extractedParentCtx = otelTrace.setSpanContext(
|
|
1202
1307
|
activeContext,
|
|
1203
|
-
extractedSpanContext
|
|
1308
|
+
extractedSpanContext,
|
|
1204
1309
|
);
|
|
1205
1310
|
return { parentContext: extractedParentCtx, spanLinks };
|
|
1206
1311
|
}
|
|
1207
1312
|
return { parentContext: activeContext, spanLinks };
|
|
1208
1313
|
}
|
|
1209
1314
|
}
|
|
1210
|
-
case
|
|
1315
|
+
case 'link': {
|
|
1211
1316
|
if (hasValidExtracted) {
|
|
1212
1317
|
spanLinks.push({ context: extractedSpanContext });
|
|
1213
1318
|
}
|
|
1214
1319
|
return { parentContext: activeContext, spanLinks };
|
|
1215
1320
|
}
|
|
1216
|
-
case
|
|
1321
|
+
case 'none': {
|
|
1217
1322
|
return { parentContext: activeContext, spanLinks };
|
|
1218
1323
|
}
|
|
1219
1324
|
default: {
|
|
@@ -1225,7 +1330,7 @@ function resolveContextAndLinks(contextMode, extractedSpanContext, additionalLin
|
|
|
1225
1330
|
function setMessagingAttributes(span, attrs) {
|
|
1226
1331
|
const { topic, consumerGroup, partition, offset, key } = attrs;
|
|
1227
1332
|
if (topic) {
|
|
1228
|
-
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM,
|
|
1333
|
+
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'kafka');
|
|
1229
1334
|
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, topic);
|
|
1230
1335
|
}
|
|
1231
1336
|
if (consumerGroup) {
|
|
@@ -1241,16 +1346,16 @@ function setMessagingAttributes(span, attrs) {
|
|
|
1241
1346
|
span.setAttribute(SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, key);
|
|
1242
1347
|
}
|
|
1243
1348
|
}
|
|
1244
|
-
var DEFAULT_TRACER_NAME3 =
|
|
1349
|
+
var DEFAULT_TRACER_NAME3 = 'autotel-plugins/kafka';
|
|
1245
1350
|
async function withProducerSpan(descriptor, fn) {
|
|
1246
|
-
const { name, topic, messageKey, system =
|
|
1351
|
+
const { name, topic, messageKey, system = 'kafka' } = descriptor;
|
|
1247
1352
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME3);
|
|
1248
1353
|
const span = tracer.startSpan(name, {
|
|
1249
|
-
kind: SpanKind.PRODUCER
|
|
1354
|
+
kind: SpanKind.PRODUCER,
|
|
1250
1355
|
});
|
|
1251
1356
|
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, system);
|
|
1252
1357
|
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, topic);
|
|
1253
|
-
span.setAttribute(SEMATTRS_MESSAGING_OPERATION,
|
|
1358
|
+
span.setAttribute(SEMATTRS_MESSAGING_OPERATION, 'publish');
|
|
1254
1359
|
if (messageKey !== void 0) {
|
|
1255
1360
|
span.setAttribute(SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, messageKey);
|
|
1256
1361
|
}
|
|
@@ -1275,31 +1380,39 @@ async function withProducerSpan(descriptor, fn) {
|
|
|
1275
1380
|
}
|
|
1276
1381
|
var DEFAULT_MAX_LINKS = 128;
|
|
1277
1382
|
function isValidSpanContext2(spanContext) {
|
|
1278
|
-
return !!(
|
|
1383
|
+
return !!(
|
|
1384
|
+
spanContext &&
|
|
1385
|
+
spanContext.traceId &&
|
|
1386
|
+
spanContext.spanId &&
|
|
1387
|
+
otelTrace.isSpanContextValid(spanContext)
|
|
1388
|
+
);
|
|
1279
1389
|
}
|
|
1280
1390
|
async function hashTraceIds(traceIds) {
|
|
1281
|
-
const input = traceIds.join(
|
|
1391
|
+
const input = traceIds.join('|');
|
|
1282
1392
|
try {
|
|
1283
1393
|
const encoder = new TextEncoder();
|
|
1284
1394
|
const data = encoder.encode(input);
|
|
1285
|
-
const hashBuffer = await crypto.subtle.digest(
|
|
1395
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
1286
1396
|
const hashArray = new Uint8Array(hashBuffer);
|
|
1287
|
-
return [...hashArray]
|
|
1397
|
+
return [...hashArray]
|
|
1398
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
1399
|
+
.join('')
|
|
1400
|
+
.slice(0, 16);
|
|
1288
1401
|
} catch {
|
|
1289
1402
|
let hash = 5381;
|
|
1290
1403
|
for (let i = 0; i < input.length; i++) {
|
|
1291
|
-
hash = hash * 33 ^ input.charCodeAt(i);
|
|
1404
|
+
hash = (hash * 33) ^ input.charCodeAt(i);
|
|
1292
1405
|
}
|
|
1293
|
-
return (hash >>> 0).toString(16).padStart(16,
|
|
1406
|
+
return (hash >>> 0).toString(16).padStart(16, '0');
|
|
1294
1407
|
}
|
|
1295
1408
|
}
|
|
1296
1409
|
function hashTraceIdsSync(traceIds) {
|
|
1297
|
-
const input = traceIds.join(
|
|
1410
|
+
const input = traceIds.join('|');
|
|
1298
1411
|
let hash = 5381;
|
|
1299
1412
|
for (let i = 0; i < input.length; i++) {
|
|
1300
|
-
hash = hash * 33 ^ input.charCodeAt(i);
|
|
1413
|
+
hash = (hash * 33) ^ input.charCodeAt(i);
|
|
1301
1414
|
}
|
|
1302
|
-
return (hash >>> 0).toString(16).padStart(16,
|
|
1415
|
+
return (hash >>> 0).toString(16).padStart(16, '0');
|
|
1303
1416
|
}
|
|
1304
1417
|
function extractBatchLineage(items, options = {}) {
|
|
1305
1418
|
const { includeTraceIds = false, maxLinks = DEFAULT_MAX_LINKS } = options;
|
|
@@ -1309,23 +1422,29 @@ function extractBatchLineage(items, options = {}) {
|
|
|
1309
1422
|
const normalizedHeaders = normalizeHeaders(item.headers);
|
|
1310
1423
|
const extractedCtx = extractTraceContext(normalizedHeaders);
|
|
1311
1424
|
const spanContext = otelTrace.getSpanContext(extractedCtx);
|
|
1312
|
-
if (
|
|
1425
|
+
if (
|
|
1426
|
+
isValidSpanContext2(spanContext) &&
|
|
1427
|
+
!seenTraceIds.has(spanContext.traceId)
|
|
1428
|
+
) {
|
|
1313
1429
|
seenTraceIds.add(spanContext.traceId);
|
|
1314
1430
|
extractedContexts.push({
|
|
1315
1431
|
traceId: spanContext.traceId,
|
|
1316
|
-
spanContext
|
|
1432
|
+
spanContext,
|
|
1317
1433
|
});
|
|
1318
1434
|
}
|
|
1319
1435
|
}
|
|
1320
1436
|
extractedContexts.sort((a, b) => a.traceId.localeCompare(b.traceId));
|
|
1321
1437
|
const traceIds = extractedContexts.map((ec) => ec.traceId);
|
|
1322
|
-
const links = extractedContexts
|
|
1323
|
-
|
|
1438
|
+
const links = extractedContexts
|
|
1439
|
+
.slice(0, maxLinks)
|
|
1440
|
+
.map((ec) => ({ context: ec.spanContext }));
|
|
1441
|
+
const hash =
|
|
1442
|
+
traceIds.length > 0 ? hashTraceIdsSync(traceIds) : '0000000000000000';
|
|
1324
1443
|
return {
|
|
1325
1444
|
linked_trace_id_count: traceIds.length,
|
|
1326
1445
|
linked_trace_id_hash: hash,
|
|
1327
1446
|
links,
|
|
1328
|
-
...includeTraceIds && { trace_ids: traceIds }
|
|
1447
|
+
...(includeTraceIds && { trace_ids: traceIds }),
|
|
1329
1448
|
};
|
|
1330
1449
|
}
|
|
1331
1450
|
async function extractBatchLineageAsync(items, options = {}) {
|
|
@@ -1336,28 +1455,34 @@ async function extractBatchLineageAsync(items, options = {}) {
|
|
|
1336
1455
|
const normalizedHeaders = normalizeHeaders(item.headers);
|
|
1337
1456
|
const extractedCtx = extractTraceContext(normalizedHeaders);
|
|
1338
1457
|
const spanContext = otelTrace.getSpanContext(extractedCtx);
|
|
1339
|
-
if (
|
|
1458
|
+
if (
|
|
1459
|
+
isValidSpanContext2(spanContext) &&
|
|
1460
|
+
!seenTraceIds.has(spanContext.traceId)
|
|
1461
|
+
) {
|
|
1340
1462
|
seenTraceIds.add(spanContext.traceId);
|
|
1341
1463
|
extractedContexts.push({
|
|
1342
1464
|
traceId: spanContext.traceId,
|
|
1343
|
-
spanContext
|
|
1465
|
+
spanContext,
|
|
1344
1466
|
});
|
|
1345
1467
|
}
|
|
1346
1468
|
}
|
|
1347
1469
|
extractedContexts.sort((a, b) => a.traceId.localeCompare(b.traceId));
|
|
1348
1470
|
const traceIds = extractedContexts.map((ec) => ec.traceId);
|
|
1349
|
-
const links = extractedContexts
|
|
1350
|
-
|
|
1471
|
+
const links = extractedContexts
|
|
1472
|
+
.slice(0, maxLinks)
|
|
1473
|
+
.map((ec) => ({ context: ec.spanContext }));
|
|
1474
|
+
const hash =
|
|
1475
|
+
traceIds.length > 0 ? await hashTraceIds(traceIds) : '0000000000000000';
|
|
1351
1476
|
return {
|
|
1352
1477
|
linked_trace_id_count: traceIds.length,
|
|
1353
1478
|
linked_trace_id_hash: hash,
|
|
1354
1479
|
links,
|
|
1355
|
-
...includeTraceIds && { trace_ids: traceIds }
|
|
1480
|
+
...(includeTraceIds && { trace_ids: traceIds }),
|
|
1356
1481
|
};
|
|
1357
1482
|
}
|
|
1358
|
-
var DEFAULT_TRACER_NAME4 =
|
|
1483
|
+
var DEFAULT_TRACER_NAME4 = 'autotel-plugins/kafka';
|
|
1359
1484
|
function withBatchConsumer(config, handler) {
|
|
1360
|
-
const { name, consumerGroup, perMessageSpans =
|
|
1485
|
+
const { name, consumerGroup, perMessageSpans = 'none', onProgress } = config;
|
|
1361
1486
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME4);
|
|
1362
1487
|
return async (payload) => {
|
|
1363
1488
|
const { batch } = payload;
|
|
@@ -1366,7 +1491,7 @@ function withBatchConsumer(config, handler) {
|
|
|
1366
1491
|
let failed = 0;
|
|
1367
1492
|
let skipped = 0;
|
|
1368
1493
|
const batchSpan = tracer.startSpan(name, {
|
|
1369
|
-
kind: SpanKind.CONSUMER
|
|
1494
|
+
kind: SpanKind.CONSUMER,
|
|
1370
1495
|
});
|
|
1371
1496
|
setBatchAttributes(batchSpan, {
|
|
1372
1497
|
topic: batch.topic,
|
|
@@ -1374,31 +1499,31 @@ function withBatchConsumer(config, handler) {
|
|
|
1374
1499
|
consumerGroup,
|
|
1375
1500
|
messageCount: batch.messages.length,
|
|
1376
1501
|
firstOffset: batch.firstOffset() ?? void 0,
|
|
1377
|
-
lastOffset: batch.lastOffset()
|
|
1502
|
+
lastOffset: batch.lastOffset(),
|
|
1378
1503
|
});
|
|
1379
1504
|
const spanContext = otelTrace.setSpan(context.active(), batchSpan);
|
|
1380
1505
|
const {
|
|
1381
1506
|
wrappedPayload,
|
|
1382
1507
|
endOpenMessageSpans,
|
|
1383
|
-
endRemainingMessageSpansOnSuccess
|
|
1508
|
+
endRemainingMessageSpansOnSuccess,
|
|
1384
1509
|
} = createWrappedPayload(
|
|
1385
1510
|
payload,
|
|
1386
1511
|
perMessageSpans,
|
|
1387
1512
|
tracer,
|
|
1388
1513
|
spanContext,
|
|
1389
1514
|
(type) => {
|
|
1390
|
-
if (type ===
|
|
1391
|
-
else if (type ===
|
|
1515
|
+
if (type === 'processed') processed++;
|
|
1516
|
+
else if (type === 'failed') failed++;
|
|
1392
1517
|
else skipped++;
|
|
1393
1518
|
if (onProgress) {
|
|
1394
1519
|
onProgress({
|
|
1395
1520
|
processed,
|
|
1396
1521
|
failed,
|
|
1397
1522
|
skipped,
|
|
1398
|
-
batchProcessingTimeMs: Date.now() - startTime
|
|
1523
|
+
batchProcessingTimeMs: Date.now() - startTime,
|
|
1399
1524
|
});
|
|
1400
1525
|
}
|
|
1401
|
-
}
|
|
1526
|
+
},
|
|
1402
1527
|
);
|
|
1403
1528
|
try {
|
|
1404
1529
|
await context.with(spanContext, async () => {
|
|
@@ -1408,47 +1533,47 @@ function withBatchConsumer(config, handler) {
|
|
|
1408
1533
|
const processingTime = Date.now() - startTime;
|
|
1409
1534
|
batchSpan.setAttribute(
|
|
1410
1535
|
SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED,
|
|
1411
|
-
processed
|
|
1536
|
+
processed,
|
|
1412
1537
|
);
|
|
1413
1538
|
batchSpan.setAttribute(
|
|
1414
1539
|
SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED,
|
|
1415
|
-
failed
|
|
1540
|
+
failed,
|
|
1416
1541
|
);
|
|
1417
1542
|
batchSpan.setAttribute(
|
|
1418
1543
|
SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS,
|
|
1419
|
-
processingTime
|
|
1544
|
+
processingTime,
|
|
1420
1545
|
);
|
|
1421
1546
|
batchSpan.setStatus({ code: SpanStatusCode.OK });
|
|
1422
1547
|
batchSpan.end();
|
|
1423
1548
|
} catch (error) {
|
|
1424
1549
|
endOpenMessageSpans?.(error);
|
|
1425
1550
|
const firstMessage = batch.messages[0];
|
|
1426
|
-
if (perMessageSpans ===
|
|
1551
|
+
if (perMessageSpans === 'errors' && firstMessage !== void 0) {
|
|
1427
1552
|
createMessageErrorSpan(
|
|
1428
1553
|
name,
|
|
1429
1554
|
{
|
|
1430
1555
|
offset: firstMessage.offset,
|
|
1431
1556
|
key: firstMessage.key ?? void 0,
|
|
1432
|
-
headers: firstMessage.headers
|
|
1557
|
+
headers: firstMessage.headers,
|
|
1433
1558
|
},
|
|
1434
1559
|
error instanceof Error ? error : new Error(String(error)),
|
|
1435
1560
|
batch.topic,
|
|
1436
|
-
batch.partition
|
|
1561
|
+
batch.partition,
|
|
1437
1562
|
);
|
|
1438
1563
|
}
|
|
1439
1564
|
const processingTime = Date.now() - startTime;
|
|
1440
1565
|
batchSpan.setAttribute(
|
|
1441
1566
|
SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED,
|
|
1442
|
-
processed
|
|
1567
|
+
processed,
|
|
1443
1568
|
);
|
|
1444
1569
|
batchSpan.setAttribute(
|
|
1445
1570
|
SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED,
|
|
1446
|
-
failed + 1
|
|
1571
|
+
failed + 1,
|
|
1447
1572
|
// Count the batch error
|
|
1448
1573
|
);
|
|
1449
1574
|
batchSpan.setAttribute(
|
|
1450
1575
|
SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS,
|
|
1451
|
-
processingTime
|
|
1576
|
+
processingTime,
|
|
1452
1577
|
);
|
|
1453
1578
|
batchSpan.setStatus({ code: SpanStatusCode.ERROR });
|
|
1454
1579
|
if (error instanceof Error) {
|
|
@@ -1462,77 +1587,86 @@ function withBatchConsumer(config, handler) {
|
|
|
1462
1587
|
};
|
|
1463
1588
|
}
|
|
1464
1589
|
function setBatchAttributes(span, attrs) {
|
|
1465
|
-
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM,
|
|
1590
|
+
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'kafka');
|
|
1466
1591
|
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, attrs.topic);
|
|
1467
1592
|
span.setAttribute(SEMATTRS_MESSAGING_KAFKA_PARTITION, attrs.partition);
|
|
1468
1593
|
span.setAttribute(SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, attrs.messageCount);
|
|
1469
1594
|
if (attrs.consumerGroup) {
|
|
1470
1595
|
span.setAttribute(
|
|
1471
1596
|
SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP,
|
|
1472
|
-
attrs.consumerGroup
|
|
1597
|
+
attrs.consumerGroup,
|
|
1473
1598
|
);
|
|
1474
1599
|
}
|
|
1475
1600
|
if (attrs.firstOffset) {
|
|
1476
1601
|
span.setAttribute(
|
|
1477
1602
|
SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET,
|
|
1478
|
-
attrs.firstOffset
|
|
1603
|
+
attrs.firstOffset,
|
|
1479
1604
|
);
|
|
1480
1605
|
}
|
|
1481
1606
|
span.setAttribute(
|
|
1482
1607
|
SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET,
|
|
1483
|
-
attrs.lastOffset
|
|
1608
|
+
attrs.lastOffset,
|
|
1484
1609
|
);
|
|
1485
1610
|
}
|
|
1486
|
-
function createWrappedPayload(
|
|
1487
|
-
|
|
1611
|
+
function createWrappedPayload(
|
|
1612
|
+
original,
|
|
1613
|
+
perMessageSpans,
|
|
1614
|
+
tracer,
|
|
1615
|
+
parentContext,
|
|
1616
|
+
onMetric,
|
|
1617
|
+
) {
|
|
1618
|
+
if (perMessageSpans === 'none') {
|
|
1488
1619
|
return {
|
|
1489
1620
|
wrappedPayload: {
|
|
1490
1621
|
...original,
|
|
1491
1622
|
resolveOffset: (offset) => {
|
|
1492
|
-
onMetric(
|
|
1623
|
+
onMetric('processed');
|
|
1493
1624
|
original.resolveOffset(offset);
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1625
|
+
},
|
|
1626
|
+
},
|
|
1496
1627
|
};
|
|
1497
1628
|
}
|
|
1498
1629
|
const messageSpans = /* @__PURE__ */ new Map();
|
|
1499
|
-
if (perMessageSpans ===
|
|
1630
|
+
if (perMessageSpans === 'all') {
|
|
1500
1631
|
for (const message of original.batch.messages) {
|
|
1501
1632
|
const normalizedHeaders = normalizeHeaders(message.headers);
|
|
1502
1633
|
const extractedCtx = extractTraceContext(normalizedHeaders);
|
|
1503
1634
|
const spanContext = otelTrace.getSpanContext(extractedCtx);
|
|
1504
|
-
const parentCtx =
|
|
1635
|
+
const parentCtx =
|
|
1636
|
+
spanContext && otelTrace.isSpanContextValid(spanContext)
|
|
1637
|
+
? extractedCtx
|
|
1638
|
+
: parentContext;
|
|
1505
1639
|
const span = tracer.startSpan(
|
|
1506
1640
|
`${original.batch.topic}.${original.batch.partition}.${message.offset}`,
|
|
1507
1641
|
{
|
|
1508
|
-
kind: SpanKind.CONSUMER
|
|
1642
|
+
kind: SpanKind.CONSUMER,
|
|
1509
1643
|
},
|
|
1510
|
-
parentCtx
|
|
1644
|
+
parentCtx,
|
|
1511
1645
|
);
|
|
1512
1646
|
span.setAttributes({
|
|
1513
|
-
[SEMATTRS_MESSAGING_SYSTEM]:
|
|
1647
|
+
[SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
|
|
1514
1648
|
[SEMATTRS_MESSAGING_DESTINATION_NAME]: original.batch.topic,
|
|
1515
1649
|
[SEMATTRS_MESSAGING_KAFKA_PARTITION]: original.batch.partition,
|
|
1516
1650
|
[SEMATTRS_MESSAGING_KAFKA_OFFSET]: message.offset,
|
|
1517
|
-
...message.key && {
|
|
1518
|
-
[SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY]: message.key.toString()
|
|
1519
|
-
}
|
|
1651
|
+
...(message.key && {
|
|
1652
|
+
[SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY]: message.key.toString(),
|
|
1653
|
+
}),
|
|
1520
1654
|
});
|
|
1521
1655
|
messageSpans.set(message.offset, span);
|
|
1522
1656
|
}
|
|
1523
1657
|
}
|
|
1524
1658
|
const wrappedMessages = original.batch.messages.map((message) => ({
|
|
1525
|
-
...message
|
|
1659
|
+
...message,
|
|
1526
1660
|
}));
|
|
1527
1661
|
const wrappedBatch = {
|
|
1528
1662
|
...original.batch,
|
|
1529
|
-
messages: wrappedMessages
|
|
1663
|
+
messages: wrappedMessages,
|
|
1530
1664
|
};
|
|
1531
1665
|
const wrappedPayload = {
|
|
1532
1666
|
...original,
|
|
1533
1667
|
batch: wrappedBatch,
|
|
1534
1668
|
resolveOffset: (offset) => {
|
|
1535
|
-
onMetric(
|
|
1669
|
+
onMetric('processed');
|
|
1536
1670
|
const span = messageSpans.get(offset);
|
|
1537
1671
|
if (span) {
|
|
1538
1672
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
@@ -1540,31 +1674,37 @@ function createWrappedPayload(original, perMessageSpans, tracer, parentContext,
|
|
|
1540
1674
|
messageSpans.delete(offset);
|
|
1541
1675
|
}
|
|
1542
1676
|
original.resolveOffset(offset);
|
|
1543
|
-
}
|
|
1677
|
+
},
|
|
1544
1678
|
};
|
|
1545
|
-
const endOpenMessageSpans =
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1679
|
+
const endOpenMessageSpans =
|
|
1680
|
+
perMessageSpans === 'all'
|
|
1681
|
+
? (error) => {
|
|
1682
|
+
for (const [, span] of messageSpans) {
|
|
1683
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1684
|
+
if (error instanceof Error) {
|
|
1685
|
+
span.recordException(error);
|
|
1686
|
+
} else {
|
|
1687
|
+
span.recordException(new Error(String(error)));
|
|
1688
|
+
}
|
|
1689
|
+
span.end();
|
|
1690
|
+
}
|
|
1691
|
+
messageSpans.clear();
|
|
1692
|
+
}
|
|
1693
|
+
: void 0;
|
|
1694
|
+
const endRemainingMessageSpansOnSuccess =
|
|
1695
|
+
perMessageSpans === 'all'
|
|
1696
|
+
? () => {
|
|
1697
|
+
for (const [, span] of messageSpans) {
|
|
1698
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
1699
|
+
span.end();
|
|
1700
|
+
}
|
|
1701
|
+
messageSpans.clear();
|
|
1702
|
+
}
|
|
1703
|
+
: void 0;
|
|
1564
1704
|
return {
|
|
1565
1705
|
wrappedPayload,
|
|
1566
1706
|
endOpenMessageSpans,
|
|
1567
|
-
endRemainingMessageSpansOnSuccess
|
|
1707
|
+
endRemainingMessageSpansOnSuccess,
|
|
1568
1708
|
};
|
|
1569
1709
|
}
|
|
1570
1710
|
function createMessageErrorSpan(name, message, error, topic, partition) {
|
|
@@ -1574,24 +1714,24 @@ function createMessageErrorSpan(name, message, error, topic, partition) {
|
|
|
1574
1714
|
const span = tracer.startSpan(
|
|
1575
1715
|
`${name}.error`,
|
|
1576
1716
|
{
|
|
1577
|
-
kind: SpanKind.CONSUMER
|
|
1717
|
+
kind: SpanKind.CONSUMER,
|
|
1578
1718
|
},
|
|
1579
|
-
extractedCtx
|
|
1719
|
+
extractedCtx,
|
|
1580
1720
|
);
|
|
1581
1721
|
span.setAttributes({
|
|
1582
|
-
[SEMATTRS_MESSAGING_SYSTEM]:
|
|
1722
|
+
[SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
|
|
1583
1723
|
[SEMATTRS_MESSAGING_DESTINATION_NAME]: topic,
|
|
1584
1724
|
[SEMATTRS_MESSAGING_KAFKA_PARTITION]: partition,
|
|
1585
1725
|
[SEMATTRS_MESSAGING_KAFKA_OFFSET]: message.offset,
|
|
1586
|
-
...message.key && {
|
|
1587
|
-
[SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY]: message.key.toString()
|
|
1588
|
-
}
|
|
1726
|
+
...(message.key && {
|
|
1727
|
+
[SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY]: message.key.toString(),
|
|
1728
|
+
}),
|
|
1589
1729
|
});
|
|
1590
1730
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1591
1731
|
span.recordException(error);
|
|
1592
1732
|
span.end();
|
|
1593
1733
|
}
|
|
1594
|
-
var DEFAULT_TRACER_NAME5 =
|
|
1734
|
+
var DEFAULT_TRACER_NAME5 = 'autotel-plugins/kafka';
|
|
1595
1735
|
function createStreamProcessor(config) {
|
|
1596
1736
|
const { name } = config;
|
|
1597
1737
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME5);
|
|
@@ -1603,22 +1743,27 @@ function createStreamProcessor(config) {
|
|
|
1603
1743
|
const processorSpan = tracer.startSpan(
|
|
1604
1744
|
name,
|
|
1605
1745
|
{
|
|
1606
|
-
kind: SpanKind.CONSUMER
|
|
1746
|
+
kind: SpanKind.CONSUMER,
|
|
1607
1747
|
},
|
|
1608
|
-
inputSpanContext && otelTrace.isSpanContextValid(inputSpanContext)
|
|
1748
|
+
inputSpanContext && otelTrace.isSpanContextValid(inputSpanContext)
|
|
1749
|
+
? extractedCtx
|
|
1750
|
+
: void 0,
|
|
1751
|
+
);
|
|
1752
|
+
processorSpan.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'kafka');
|
|
1753
|
+
processorSpan.setAttribute(SEMATTRS_MESSAGING_OPERATION, 'process');
|
|
1754
|
+
const processorContext = otelTrace.setSpan(
|
|
1755
|
+
context.active(),
|
|
1756
|
+
processorSpan,
|
|
1609
1757
|
);
|
|
1610
|
-
processorSpan.setAttribute(SEMATTRS_MESSAGING_SYSTEM, "kafka");
|
|
1611
|
-
processorSpan.setAttribute(SEMATTRS_MESSAGING_OPERATION, "process");
|
|
1612
|
-
const processorContext = otelTrace.setSpan(context.active(), processorSpan);
|
|
1613
1758
|
const ctx = {
|
|
1614
1759
|
span: processorSpan,
|
|
1615
1760
|
inputContext: inputSpanContext,
|
|
1616
1761
|
async stage(stageName, fn) {
|
|
1617
1762
|
return context.with(processorContext, async () => {
|
|
1618
1763
|
const stageSpan = tracer.startSpan(`${name}.${stageName}`, {
|
|
1619
|
-
kind: SpanKind.INTERNAL
|
|
1764
|
+
kind: SpanKind.INTERNAL,
|
|
1620
1765
|
});
|
|
1621
|
-
stageSpan.setAttribute(
|
|
1766
|
+
stageSpan.setAttribute('stream.stage', stageName);
|
|
1622
1767
|
const stageContext = otelTrace.setSpan(context.active(), stageSpan);
|
|
1623
1768
|
try {
|
|
1624
1769
|
const result = await context.with(stageContext, async () => {
|
|
@@ -1640,28 +1785,36 @@ function createStreamProcessor(config) {
|
|
|
1640
1785
|
});
|
|
1641
1786
|
},
|
|
1642
1787
|
async produce(topic, _payload, options) {
|
|
1643
|
-
const { linkToInput = false, headers: extraHeaders = {} } =
|
|
1788
|
+
const { linkToInput = false, headers: extraHeaders = {} } =
|
|
1789
|
+
options ?? {};
|
|
1644
1790
|
const links = [];
|
|
1645
|
-
if (
|
|
1791
|
+
if (
|
|
1792
|
+
linkToInput &&
|
|
1793
|
+
inputSpanContext &&
|
|
1794
|
+
otelTrace.isSpanContextValid(inputSpanContext)
|
|
1795
|
+
) {
|
|
1646
1796
|
links.push({ context: inputSpanContext });
|
|
1647
1797
|
}
|
|
1648
1798
|
const produceSpan = tracer.startSpan(`${name}.produce`, {
|
|
1649
1799
|
kind: SpanKind.PRODUCER,
|
|
1650
|
-
links
|
|
1800
|
+
links,
|
|
1651
1801
|
});
|
|
1652
|
-
produceSpan.setAttribute(SEMATTRS_MESSAGING_SYSTEM,
|
|
1802
|
+
produceSpan.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'kafka');
|
|
1653
1803
|
produceSpan.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, topic);
|
|
1654
|
-
produceSpan.setAttribute(SEMATTRS_MESSAGING_OPERATION,
|
|
1655
|
-
const produceContext = otelTrace.setSpan(
|
|
1804
|
+
produceSpan.setAttribute(SEMATTRS_MESSAGING_OPERATION, 'publish');
|
|
1805
|
+
const produceContext = otelTrace.setSpan(
|
|
1806
|
+
context.active(),
|
|
1807
|
+
produceSpan,
|
|
1808
|
+
);
|
|
1656
1809
|
return context.with(produceContext, () => {
|
|
1657
1810
|
const headers = injectTraceHeaders(extraHeaders, {
|
|
1658
|
-
includeCorrelationIdHeader: true
|
|
1811
|
+
includeCorrelationIdHeader: true,
|
|
1659
1812
|
});
|
|
1660
1813
|
produceSpan.setStatus({ code: SpanStatusCode.OK });
|
|
1661
1814
|
produceSpan.end();
|
|
1662
1815
|
return headers;
|
|
1663
1816
|
});
|
|
1664
|
-
}
|
|
1817
|
+
},
|
|
1665
1818
|
};
|
|
1666
1819
|
try {
|
|
1667
1820
|
const result = await context.with(processorContext, async () => {
|
|
@@ -1680,7 +1833,7 @@ function createStreamProcessor(config) {
|
|
|
1680
1833
|
processorSpan.end();
|
|
1681
1834
|
throw error;
|
|
1682
1835
|
}
|
|
1683
|
-
}
|
|
1836
|
+
},
|
|
1684
1837
|
};
|
|
1685
1838
|
}
|
|
1686
1839
|
var ConsumerMetrics = class {
|
|
@@ -1695,61 +1848,69 @@ var ConsumerMetrics = class {
|
|
|
1695
1848
|
lagPollInterval;
|
|
1696
1849
|
isRunning = false;
|
|
1697
1850
|
constructor(config) {
|
|
1698
|
-
if (
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1851
|
+
if (
|
|
1852
|
+
config.enableLag &&
|
|
1853
|
+
config.lagStrategy === 'polling' &&
|
|
1854
|
+
!config.lagPollIntervalMs
|
|
1855
|
+
) {
|
|
1856
|
+
throw new Error('Lag polling requires lagPollIntervalMs');
|
|
1857
|
+
}
|
|
1858
|
+
if (
|
|
1859
|
+
config.enableLag &&
|
|
1860
|
+
(config.lagStrategy === 'polling' || config.lagStrategy === 'hybrid')
|
|
1861
|
+
) {
|
|
1702
1862
|
if (!config.admin) {
|
|
1703
1863
|
throw new Error(
|
|
1704
|
-
`Lag strategy '${config.lagStrategy}' requires admin client
|
|
1864
|
+
`Lag strategy '${config.lagStrategy}' requires admin client`,
|
|
1705
1865
|
);
|
|
1706
1866
|
}
|
|
1707
1867
|
if (!config.groupId) {
|
|
1708
|
-
throw new Error(
|
|
1868
|
+
throw new Error('Lag tracking requires groupId');
|
|
1709
1869
|
}
|
|
1710
1870
|
if (!config.topics || config.topics.length === 0) {
|
|
1711
|
-
throw new Error(
|
|
1871
|
+
throw new Error('Lag tracking requires topics');
|
|
1712
1872
|
}
|
|
1713
1873
|
}
|
|
1714
1874
|
this.config = {
|
|
1715
1875
|
...config,
|
|
1716
|
-
metricsPrefix: config.metricsPrefix ??
|
|
1876
|
+
metricsPrefix: config.metricsPrefix ?? 'kafka.consumer',
|
|
1717
1877
|
enableLag: config.enableLag ?? false,
|
|
1718
|
-
lagStrategy: config.lagStrategy ??
|
|
1719
|
-
lagPollIntervalMs: config.lagPollIntervalMs ?? 3e4
|
|
1878
|
+
lagStrategy: config.lagStrategy ?? 'hybrid',
|
|
1879
|
+
lagPollIntervalMs: config.lagPollIntervalMs ?? 3e4,
|
|
1720
1880
|
};
|
|
1721
|
-
this.meter = metrics.getMeter(
|
|
1881
|
+
this.meter = metrics.getMeter('autotel-plugins/kafka');
|
|
1722
1882
|
const prefix = this.config.metricsPrefix;
|
|
1723
1883
|
this.messagesProcessed = this.meter.createCounter(
|
|
1724
1884
|
`${prefix}.messages_processed`,
|
|
1725
1885
|
{
|
|
1726
|
-
description:
|
|
1727
|
-
}
|
|
1886
|
+
description: 'Total number of messages processed',
|
|
1887
|
+
},
|
|
1728
1888
|
);
|
|
1729
1889
|
this.processingDuration = this.meter.createHistogram(
|
|
1730
1890
|
`${prefix}.processing_duration`,
|
|
1731
1891
|
{
|
|
1732
|
-
description:
|
|
1733
|
-
unit:
|
|
1734
|
-
}
|
|
1892
|
+
description: 'Message processing duration in milliseconds',
|
|
1893
|
+
unit: 'ms',
|
|
1894
|
+
},
|
|
1735
1895
|
);
|
|
1736
1896
|
this.batchSize = this.meter.createHistogram(`${prefix}.batch_size`, {
|
|
1737
|
-
description:
|
|
1897
|
+
description: 'Number of messages in each batch',
|
|
1738
1898
|
});
|
|
1739
1899
|
this.rebalances = this.meter.createCounter(`${prefix}.rebalances`, {
|
|
1740
|
-
description:
|
|
1900
|
+
description: 'Number of consumer group rebalances',
|
|
1741
1901
|
});
|
|
1742
1902
|
this.lag = this.meter.createObservableGauge(`${prefix}.lag`, {
|
|
1743
|
-
description:
|
|
1903
|
+
description: 'Consumer lag per topic-partition',
|
|
1744
1904
|
});
|
|
1745
1905
|
if (this.config.enableLag) {
|
|
1746
1906
|
this.lag.addCallback((observableResult) => {
|
|
1747
1907
|
for (const [, state] of this.partitionStates.entries()) {
|
|
1748
1908
|
if (state.highWatermark) {
|
|
1749
|
-
const lagValue =
|
|
1909
|
+
const lagValue =
|
|
1910
|
+
BigInt(state.highWatermark) - BigInt(state.currentOffset);
|
|
1750
1911
|
observableResult.observe(Number(lagValue), {
|
|
1751
1912
|
topic: state.topic,
|
|
1752
|
-
partition: state.partition
|
|
1913
|
+
partition: state.partition,
|
|
1753
1914
|
});
|
|
1754
1915
|
}
|
|
1755
1916
|
}
|
|
@@ -1763,18 +1924,21 @@ var ConsumerMetrics = class {
|
|
|
1763
1924
|
if (this.isRunning) return;
|
|
1764
1925
|
this.isRunning = true;
|
|
1765
1926
|
const { consumer } = this.config;
|
|
1766
|
-
consumer.on(
|
|
1767
|
-
this.rebalances.add(1, { event:
|
|
1927
|
+
consumer.on('consumer.rebalancing', () => {
|
|
1928
|
+
this.rebalances.add(1, { event: 'rebalancing' });
|
|
1768
1929
|
});
|
|
1769
|
-
consumer.on(
|
|
1770
|
-
this.rebalances.add(1, { event:
|
|
1930
|
+
consumer.on('consumer.group_join', () => {
|
|
1931
|
+
this.rebalances.add(1, { event: 'group_join' });
|
|
1771
1932
|
});
|
|
1772
|
-
if (
|
|
1933
|
+
if (
|
|
1934
|
+
this.config.enableLag &&
|
|
1935
|
+
(this.config.lagStrategy === 'polling' ||
|
|
1936
|
+
this.config.lagStrategy === 'hybrid')
|
|
1937
|
+
) {
|
|
1773
1938
|
await this.pollLag();
|
|
1774
1939
|
this.lagPollInterval = setInterval(
|
|
1775
|
-
() => this.pollLag().catch(() => {
|
|
1776
|
-
|
|
1777
|
-
this.config.lagPollIntervalMs
|
|
1940
|
+
() => this.pollLag().catch(() => {}),
|
|
1941
|
+
this.config.lagPollIntervalMs,
|
|
1778
1942
|
);
|
|
1779
1943
|
}
|
|
1780
1944
|
}
|
|
@@ -1827,7 +1991,7 @@ var ConsumerMetrics = class {
|
|
|
1827
1991
|
topic,
|
|
1828
1992
|
partition,
|
|
1829
1993
|
currentOffset: offset,
|
|
1830
|
-
highWatermark: highWatermark ?? existing?.highWatermark
|
|
1994
|
+
highWatermark: highWatermark ?? existing?.highWatermark,
|
|
1831
1995
|
});
|
|
1832
1996
|
}
|
|
1833
1997
|
/**
|
|
@@ -1839,15 +2003,15 @@ var ConsumerMetrics = class {
|
|
|
1839
2003
|
try {
|
|
1840
2004
|
const committedOffsets = await admin.fetchOffsets({
|
|
1841
2005
|
groupId,
|
|
1842
|
-
topics
|
|
2006
|
+
topics,
|
|
1843
2007
|
});
|
|
1844
2008
|
for (const topicOffsets of committedOffsets) {
|
|
1845
2009
|
const topicHighWatermarks = await admin.fetchTopicOffsets(
|
|
1846
|
-
topicOffsets.topic
|
|
2010
|
+
topicOffsets.topic,
|
|
1847
2011
|
);
|
|
1848
2012
|
for (const partition of topicOffsets.partitions) {
|
|
1849
2013
|
const hwm = topicHighWatermarks.find(
|
|
1850
|
-
(p) => p.partition === partition.partition
|
|
2014
|
+
(p) => p.partition === partition.partition,
|
|
1851
2015
|
);
|
|
1852
2016
|
if (hwm) {
|
|
1853
2017
|
const key = `${topicOffsets.topic}-${partition.partition}`;
|
|
@@ -1855,34 +2019,33 @@ var ConsumerMetrics = class {
|
|
|
1855
2019
|
topic: topicOffsets.topic,
|
|
1856
2020
|
partition: partition.partition,
|
|
1857
2021
|
currentOffset: partition.offset,
|
|
1858
|
-
highWatermark: hwm.high
|
|
2022
|
+
highWatermark: hwm.high,
|
|
1859
2023
|
});
|
|
1860
2024
|
}
|
|
1861
2025
|
}
|
|
1862
2026
|
}
|
|
1863
|
-
} catch {
|
|
1864
|
-
}
|
|
2027
|
+
} catch {}
|
|
1865
2028
|
}
|
|
1866
2029
|
};
|
|
1867
|
-
var DEFAULT_TRACER_NAME6 =
|
|
2030
|
+
var DEFAULT_TRACER_NAME6 = 'autotel-plugins/kafka';
|
|
1868
2031
|
var REBALANCE_EVENTS = [
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
2032
|
+
'consumer.group_join',
|
|
2033
|
+
'consumer.rebalancing',
|
|
2034
|
+
'consumer.stop',
|
|
1872
2035
|
];
|
|
1873
2036
|
var ERROR_EVENTS = [
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2037
|
+
'consumer.crash',
|
|
2038
|
+
'consumer.disconnect',
|
|
2039
|
+
'consumer.network.request_timeout',
|
|
1877
2040
|
];
|
|
1878
|
-
var HEARTBEAT_EVENTS = [
|
|
2041
|
+
var HEARTBEAT_EVENTS = ['consumer.heartbeat'];
|
|
1879
2042
|
function instrumentConsumerEvents(consumer, config = {}) {
|
|
1880
2043
|
const {
|
|
1881
|
-
mode =
|
|
2044
|
+
mode = 'events',
|
|
1882
2045
|
traceRebalances = true,
|
|
1883
2046
|
traceErrors = true,
|
|
1884
2047
|
traceHeartbeats = false,
|
|
1885
|
-
lifecycleSpan
|
|
2048
|
+
lifecycleSpan,
|
|
1886
2049
|
} = config;
|
|
1887
2050
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME6);
|
|
1888
2051
|
const listeners = [];
|
|
@@ -1893,7 +2056,7 @@ function instrumentConsumerEvents(consumer, config = {}) {
|
|
|
1893
2056
|
if (traceRebalances) {
|
|
1894
2057
|
for (const event of REBALANCE_EVENTS) {
|
|
1895
2058
|
addListener(event, (payload) => {
|
|
1896
|
-
if (mode ===
|
|
2059
|
+
if (mode === 'spans') {
|
|
1897
2060
|
createEventSpan(tracer, event, payload);
|
|
1898
2061
|
} else if (lifecycleSpan) {
|
|
1899
2062
|
lifecycleSpan.addEvent(event, extractEventAttributes(payload));
|
|
@@ -1904,14 +2067,14 @@ function instrumentConsumerEvents(consumer, config = {}) {
|
|
|
1904
2067
|
if (traceErrors) {
|
|
1905
2068
|
for (const event of ERROR_EVENTS) {
|
|
1906
2069
|
addListener(event, (payload) => {
|
|
1907
|
-
if (mode ===
|
|
2070
|
+
if (mode === 'spans') {
|
|
1908
2071
|
createErrorSpan(tracer, event, payload);
|
|
1909
2072
|
} else if (lifecycleSpan) {
|
|
1910
2073
|
lifecycleSpan.addEvent(event, {
|
|
1911
2074
|
...extractEventAttributes(payload),
|
|
1912
|
-
|
|
2075
|
+
'event.severity': 'error',
|
|
1913
2076
|
});
|
|
1914
|
-
if (event ===
|
|
2077
|
+
if (event === 'consumer.crash' && isErrorPayload(payload)) {
|
|
1915
2078
|
lifecycleSpan.recordException(payload.error);
|
|
1916
2079
|
}
|
|
1917
2080
|
}
|
|
@@ -1921,7 +2084,7 @@ function instrumentConsumerEvents(consumer, config = {}) {
|
|
|
1921
2084
|
if (traceHeartbeats) {
|
|
1922
2085
|
for (const event of HEARTBEAT_EVENTS) {
|
|
1923
2086
|
addListener(event, (payload) => {
|
|
1924
|
-
if (mode ===
|
|
2087
|
+
if (mode === 'spans') {
|
|
1925
2088
|
createEventSpan(tracer, event, payload);
|
|
1926
2089
|
} else if (lifecycleSpan) {
|
|
1927
2090
|
lifecycleSpan.addEvent(event, extractEventAttributes(payload));
|
|
@@ -1940,7 +2103,7 @@ function instrumentConsumerEvents(consumer, config = {}) {
|
|
|
1940
2103
|
}
|
|
1941
2104
|
function createEventSpan(tracer, eventName, payload) {
|
|
1942
2105
|
const span = tracer.startSpan(`kafka.consumer.${eventName}`, {
|
|
1943
|
-
kind: SpanKind.INTERNAL
|
|
2106
|
+
kind: SpanKind.INTERNAL,
|
|
1944
2107
|
});
|
|
1945
2108
|
const attributes = extractEventAttributes(payload);
|
|
1946
2109
|
for (const [key, value] of Object.entries(attributes)) {
|
|
@@ -1951,7 +2114,7 @@ function createEventSpan(tracer, eventName, payload) {
|
|
|
1951
2114
|
}
|
|
1952
2115
|
function createErrorSpan(tracer, eventName, payload) {
|
|
1953
2116
|
const span = tracer.startSpan(`kafka.consumer.${eventName}`, {
|
|
1954
|
-
kind: SpanKind.INTERNAL
|
|
2117
|
+
kind: SpanKind.INTERNAL,
|
|
1955
2118
|
});
|
|
1956
2119
|
const attributes = extractEventAttributes(payload);
|
|
1957
2120
|
for (const [key, value] of Object.entries(attributes)) {
|
|
@@ -1965,35 +2128,41 @@ function createErrorSpan(tracer, eventName, payload) {
|
|
|
1965
2128
|
}
|
|
1966
2129
|
function extractEventAttributes(payload) {
|
|
1967
2130
|
const attributes = {};
|
|
1968
|
-
if (!payload || typeof payload !==
|
|
2131
|
+
if (!payload || typeof payload !== 'object') {
|
|
1969
2132
|
return attributes;
|
|
1970
2133
|
}
|
|
1971
2134
|
const p = payload;
|
|
1972
|
-
if (typeof p.groupId ===
|
|
1973
|
-
attributes[
|
|
2135
|
+
if (typeof p.groupId === 'string') {
|
|
2136
|
+
attributes['messaging.kafka.consumer.group'] = p.groupId;
|
|
1974
2137
|
}
|
|
1975
|
-
if (typeof p.memberId ===
|
|
1976
|
-
attributes[
|
|
2138
|
+
if (typeof p.memberId === 'string') {
|
|
2139
|
+
attributes['messaging.kafka.consumer.member_id'] = p.memberId;
|
|
1977
2140
|
}
|
|
1978
|
-
if (typeof p.leaderId ===
|
|
1979
|
-
attributes[
|
|
2141
|
+
if (typeof p.leaderId === 'string') {
|
|
2142
|
+
attributes['messaging.kafka.consumer.leader_id'] = p.leaderId;
|
|
1980
2143
|
}
|
|
1981
|
-
if (typeof p.duration ===
|
|
1982
|
-
attributes[
|
|
2144
|
+
if (typeof p.duration === 'number') {
|
|
2145
|
+
attributes['event.duration_ms'] = p.duration;
|
|
1983
2146
|
}
|
|
1984
|
-
if (typeof p.isLeader ===
|
|
1985
|
-
attributes[
|
|
2147
|
+
if (typeof p.isLeader === 'boolean') {
|
|
2148
|
+
attributes['messaging.kafka.consumer.is_leader'] = p.isLeader;
|
|
1986
2149
|
}
|
|
1987
2150
|
if (Array.isArray(p.memberAssignment)) {
|
|
1988
|
-
attributes[
|
|
2151
|
+
attributes['messaging.kafka.consumer.assignment_count'] =
|
|
2152
|
+
p.memberAssignment.length;
|
|
1989
2153
|
}
|
|
1990
|
-
if (typeof p.type ===
|
|
1991
|
-
attributes[
|
|
2154
|
+
if (typeof p.type === 'string') {
|
|
2155
|
+
attributes['event.type'] = p.type;
|
|
1992
2156
|
}
|
|
1993
2157
|
return attributes;
|
|
1994
2158
|
}
|
|
1995
2159
|
function isErrorPayload(payload) {
|
|
1996
|
-
return
|
|
2160
|
+
return (
|
|
2161
|
+
payload !== null &&
|
|
2162
|
+
typeof payload === 'object' &&
|
|
2163
|
+
'error' in payload &&
|
|
2164
|
+
payload.error instanceof Error
|
|
2165
|
+
);
|
|
1997
2166
|
}
|
|
1998
2167
|
function normalizeHeaders2(headers) {
|
|
1999
2168
|
if (!headers) {
|
|
@@ -2007,23 +2176,24 @@ function normalizeHeaders2(headers) {
|
|
|
2007
2176
|
}
|
|
2008
2177
|
if (Buffer.isBuffer(value)) {
|
|
2009
2178
|
try {
|
|
2010
|
-
const decoded = value.toString(
|
|
2011
|
-
normalized[key] = Buffer.from(decoded,
|
|
2179
|
+
const decoded = value.toString('utf8');
|
|
2180
|
+
normalized[key] = Buffer.from(decoded, 'utf8').equals(value)
|
|
2181
|
+
? decoded
|
|
2182
|
+
: `base64:${value.toString('base64')}`;
|
|
2012
2183
|
} catch {
|
|
2013
|
-
normalized[key] = `base64:${value.toString(
|
|
2184
|
+
normalized[key] = `base64:${value.toString('base64')}`;
|
|
2014
2185
|
}
|
|
2015
|
-
} else if (typeof value ===
|
|
2186
|
+
} else if (typeof value === 'string') {
|
|
2016
2187
|
normalized[key] = value;
|
|
2017
|
-
} else if (typeof value ===
|
|
2188
|
+
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
2018
2189
|
normalized[key] = String(value);
|
|
2019
|
-
} else if (typeof value ===
|
|
2190
|
+
} else if (typeof value === 'object') {
|
|
2020
2191
|
try {
|
|
2021
2192
|
const json = JSON.stringify(value);
|
|
2022
2193
|
if (json.length <= MAX_OBJECT_SIZE) {
|
|
2023
2194
|
normalized[key] = json;
|
|
2024
2195
|
}
|
|
2025
|
-
} catch {
|
|
2026
|
-
}
|
|
2196
|
+
} catch {}
|
|
2027
2197
|
}
|
|
2028
2198
|
}
|
|
2029
2199
|
return normalized;
|
|
@@ -2040,7 +2210,7 @@ var caseInsensitiveGetter2 = {
|
|
|
2040
2210
|
},
|
|
2041
2211
|
keys(carrier) {
|
|
2042
2212
|
return Object.keys(carrier);
|
|
2043
|
-
}
|
|
2213
|
+
},
|
|
2044
2214
|
};
|
|
2045
2215
|
function extractTraceContext2(headers) {
|
|
2046
2216
|
return propagation.extract(ROOT_CONTEXT, headers, caseInsensitiveGetter2);
|
|
@@ -2048,11 +2218,11 @@ function extractTraceContext2(headers) {
|
|
|
2048
2218
|
var headerSetter2 = {
|
|
2049
2219
|
set(carrier, key, value) {
|
|
2050
2220
|
carrier[key] = value;
|
|
2051
|
-
}
|
|
2221
|
+
},
|
|
2052
2222
|
};
|
|
2053
2223
|
function deriveCorrelationId2() {
|
|
2054
2224
|
const activeBaggage = propagation.getActiveBaggage();
|
|
2055
|
-
const baggageCorrelationId = activeBaggage?.getEntry(
|
|
2225
|
+
const baggageCorrelationId = activeBaggage?.getEntry('correlation-id');
|
|
2056
2226
|
if (baggageCorrelationId?.value) {
|
|
2057
2227
|
return baggageCorrelationId.value;
|
|
2058
2228
|
}
|
|
@@ -2061,7 +2231,7 @@ function deriveCorrelationId2() {
|
|
|
2061
2231
|
const spanContext = activeSpan.spanContext();
|
|
2062
2232
|
return spanContext.traceId.slice(0, 16);
|
|
2063
2233
|
}
|
|
2064
|
-
return
|
|
2234
|
+
return '';
|
|
2065
2235
|
}
|
|
2066
2236
|
function extractCorrelationId2(headers, amqpCorrelationId) {
|
|
2067
2237
|
if (amqpCorrelationId) {
|
|
@@ -2087,13 +2257,18 @@ function injectTraceHeaders2(base = {}, options = {}) {
|
|
|
2087
2257
|
}
|
|
2088
2258
|
return carrier;
|
|
2089
2259
|
}
|
|
2090
|
-
var DEFAULT_TRACER_NAME7 =
|
|
2260
|
+
var DEFAULT_TRACER_NAME7 = 'autotel-plugins/rabbitmq';
|
|
2091
2261
|
function isValidSpanContext3(spanContext) {
|
|
2092
|
-
return !!(
|
|
2262
|
+
return !!(
|
|
2263
|
+
spanContext &&
|
|
2264
|
+
spanContext.traceId &&
|
|
2265
|
+
spanContext.spanId &&
|
|
2266
|
+
otelTrace.isSpanContextValid(spanContext)
|
|
2267
|
+
);
|
|
2093
2268
|
}
|
|
2094
2269
|
function validateDeferredConfig(descriptor) {
|
|
2095
2270
|
if (descriptor.deferSpanEnd && !descriptor.ackTimeoutMs) {
|
|
2096
|
-
throw new Error(
|
|
2271
|
+
throw new Error('deferSpanEnd requires ackTimeoutMs to be set');
|
|
2097
2272
|
}
|
|
2098
2273
|
}
|
|
2099
2274
|
async function withConsumeSpan(descriptor, fn) {
|
|
@@ -2101,7 +2276,7 @@ async function withConsumeSpan(descriptor, fn) {
|
|
|
2101
2276
|
const {
|
|
2102
2277
|
name,
|
|
2103
2278
|
headers,
|
|
2104
|
-
contextMode =
|
|
2279
|
+
contextMode = 'inherit',
|
|
2105
2280
|
links = [],
|
|
2106
2281
|
queue,
|
|
2107
2282
|
exchange,
|
|
@@ -2110,7 +2285,7 @@ async function withConsumeSpan(descriptor, fn) {
|
|
|
2110
2285
|
correlationId,
|
|
2111
2286
|
consumerTag,
|
|
2112
2287
|
deferSpanEnd = false,
|
|
2113
|
-
ackTimeoutMs
|
|
2288
|
+
ackTimeoutMs,
|
|
2114
2289
|
} = descriptor;
|
|
2115
2290
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME7);
|
|
2116
2291
|
const normalizedHeaders = normalizeHeaders2(headers);
|
|
@@ -2119,15 +2294,15 @@ async function withConsumeSpan(descriptor, fn) {
|
|
|
2119
2294
|
const { parentContext, spanLinks } = resolveContextAndLinks2(
|
|
2120
2295
|
contextMode,
|
|
2121
2296
|
extractedSpanContext,
|
|
2122
|
-
links
|
|
2297
|
+
links,
|
|
2123
2298
|
);
|
|
2124
2299
|
const span = tracer.startSpan(
|
|
2125
2300
|
name,
|
|
2126
2301
|
{
|
|
2127
2302
|
kind: SpanKind.CONSUMER,
|
|
2128
|
-
links: spanLinks
|
|
2303
|
+
links: spanLinks,
|
|
2129
2304
|
},
|
|
2130
|
-
parentContext
|
|
2305
|
+
parentContext,
|
|
2131
2306
|
);
|
|
2132
2307
|
setMessagingAttributes2(span, {
|
|
2133
2308
|
queue,
|
|
@@ -2135,16 +2310,11 @@ async function withConsumeSpan(descriptor, fn) {
|
|
|
2135
2310
|
routingKey,
|
|
2136
2311
|
messageId,
|
|
2137
2312
|
correlationId,
|
|
2138
|
-
consumerTag
|
|
2313
|
+
consumerTag,
|
|
2139
2314
|
});
|
|
2140
2315
|
const spanContext = otelTrace.setSpan(context.active(), span);
|
|
2141
2316
|
if (deferSpanEnd) {
|
|
2142
|
-
return executeDeferredMode(
|
|
2143
|
-
span,
|
|
2144
|
-
spanContext,
|
|
2145
|
-
fn,
|
|
2146
|
-
ackTimeoutMs
|
|
2147
|
-
);
|
|
2317
|
+
return executeDeferredMode(span, spanContext, fn, ackTimeoutMs);
|
|
2148
2318
|
}
|
|
2149
2319
|
return executeImmediateMode(span, spanContext, fn);
|
|
2150
2320
|
}
|
|
@@ -2183,25 +2353,25 @@ async function executeDeferredMode(span, spanContext, fn, ackTimeoutMs) {
|
|
|
2183
2353
|
span.setAttribute(SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, requeue);
|
|
2184
2354
|
}
|
|
2185
2355
|
span.setStatus({
|
|
2186
|
-
code: status ===
|
|
2356
|
+
code: status === 'ok' ? SpanStatusCode.OK : SpanStatusCode.ERROR,
|
|
2187
2357
|
});
|
|
2188
2358
|
span.end();
|
|
2189
2359
|
};
|
|
2190
2360
|
const controls = {
|
|
2191
2361
|
ack() {
|
|
2192
|
-
endSpan(
|
|
2362
|
+
endSpan('ok', 'ack');
|
|
2193
2363
|
},
|
|
2194
2364
|
nack(options) {
|
|
2195
|
-
endSpan(
|
|
2365
|
+
endSpan('ok', 'nack', options?.requeue ?? true);
|
|
2196
2366
|
},
|
|
2197
2367
|
reject(options) {
|
|
2198
|
-
endSpan(
|
|
2199
|
-
}
|
|
2368
|
+
endSpan('ok', 'reject', options?.requeue ?? false);
|
|
2369
|
+
},
|
|
2200
2370
|
};
|
|
2201
2371
|
timeoutRef.id = setTimeout(() => {
|
|
2202
2372
|
if (!spanEnded) {
|
|
2203
|
-
span.setAttribute(
|
|
2204
|
-
endSpan(
|
|
2373
|
+
span.setAttribute('messaging.rabbitmq.ack_timeout', true);
|
|
2374
|
+
endSpan('error');
|
|
2205
2375
|
}
|
|
2206
2376
|
}, ackTimeoutMs);
|
|
2207
2377
|
try {
|
|
@@ -2209,7 +2379,7 @@ async function executeDeferredMode(span, spanContext, fn, ackTimeoutMs) {
|
|
|
2209
2379
|
return await fn(span, controls);
|
|
2210
2380
|
});
|
|
2211
2381
|
if (!spanEnded) {
|
|
2212
|
-
endSpan(
|
|
2382
|
+
endSpan('ok');
|
|
2213
2383
|
}
|
|
2214
2384
|
return result;
|
|
2215
2385
|
} catch (error) {
|
|
@@ -2219,33 +2389,37 @@ async function executeDeferredMode(span, spanContext, fn, ackTimeoutMs) {
|
|
|
2219
2389
|
} else {
|
|
2220
2390
|
span.recordException(new Error(String(error)));
|
|
2221
2391
|
}
|
|
2222
|
-
endSpan(
|
|
2392
|
+
endSpan('error');
|
|
2223
2393
|
}
|
|
2224
2394
|
throw error;
|
|
2225
2395
|
}
|
|
2226
2396
|
}
|
|
2227
|
-
function resolveContextAndLinks2(
|
|
2397
|
+
function resolveContextAndLinks2(
|
|
2398
|
+
contextMode,
|
|
2399
|
+
extractedSpanContext,
|
|
2400
|
+
additionalLinks,
|
|
2401
|
+
) {
|
|
2228
2402
|
const activeContext = context.active();
|
|
2229
2403
|
const hasValidExtracted = isValidSpanContext3(extractedSpanContext);
|
|
2230
2404
|
const spanLinks = [...additionalLinks];
|
|
2231
2405
|
switch (contextMode) {
|
|
2232
|
-
case
|
|
2406
|
+
case 'inherit': {
|
|
2233
2407
|
if (hasValidExtracted) {
|
|
2234
2408
|
const extractedParentCtx = otelTrace.setSpanContext(
|
|
2235
2409
|
activeContext,
|
|
2236
|
-
extractedSpanContext
|
|
2410
|
+
extractedSpanContext,
|
|
2237
2411
|
);
|
|
2238
2412
|
return { parentContext: extractedParentCtx, spanLinks };
|
|
2239
2413
|
}
|
|
2240
2414
|
return { parentContext: activeContext, spanLinks };
|
|
2241
2415
|
}
|
|
2242
|
-
case
|
|
2416
|
+
case 'link': {
|
|
2243
2417
|
if (hasValidExtracted) {
|
|
2244
2418
|
spanLinks.push({ context: extractedSpanContext });
|
|
2245
2419
|
}
|
|
2246
2420
|
return { parentContext: activeContext, spanLinks };
|
|
2247
2421
|
}
|
|
2248
|
-
case
|
|
2422
|
+
case 'none': {
|
|
2249
2423
|
return { parentContext: activeContext, spanLinks };
|
|
2250
2424
|
}
|
|
2251
2425
|
default: {
|
|
@@ -2255,22 +2429,23 @@ function resolveContextAndLinks2(contextMode, extractedSpanContext, additionalLi
|
|
|
2255
2429
|
}
|
|
2256
2430
|
}
|
|
2257
2431
|
function setMessagingAttributes2(span, attrs) {
|
|
2258
|
-
const { queue, exchange, routingKey, messageId, correlationId, consumerTag } =
|
|
2259
|
-
|
|
2260
|
-
span.setAttribute(
|
|
2432
|
+
const { queue, exchange, routingKey, messageId, correlationId, consumerTag } =
|
|
2433
|
+
attrs;
|
|
2434
|
+
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'rabbitmq');
|
|
2435
|
+
span.setAttribute(SEMATTRS_MESSAGING_OPERATION_NAME, 'receive');
|
|
2261
2436
|
if (queue) {
|
|
2262
2437
|
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, queue);
|
|
2263
2438
|
}
|
|
2264
2439
|
if (exchange) {
|
|
2265
2440
|
span.setAttribute(
|
|
2266
2441
|
SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE,
|
|
2267
|
-
exchange
|
|
2442
|
+
exchange,
|
|
2268
2443
|
);
|
|
2269
2444
|
}
|
|
2270
2445
|
if (routingKey) {
|
|
2271
2446
|
span.setAttribute(
|
|
2272
2447
|
SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY,
|
|
2273
|
-
routingKey
|
|
2448
|
+
routingKey,
|
|
2274
2449
|
);
|
|
2275
2450
|
}
|
|
2276
2451
|
if (messageId) {
|
|
@@ -2279,33 +2454,33 @@ function setMessagingAttributes2(span, attrs) {
|
|
|
2279
2454
|
if (correlationId) {
|
|
2280
2455
|
span.setAttribute(
|
|
2281
2456
|
SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID,
|
|
2282
|
-
correlationId
|
|
2457
|
+
correlationId,
|
|
2283
2458
|
);
|
|
2284
2459
|
}
|
|
2285
2460
|
if (consumerTag) {
|
|
2286
2461
|
span.setAttribute(SEMATTRS_MESSAGING_CONSUMER_ID, consumerTag);
|
|
2287
2462
|
}
|
|
2288
2463
|
}
|
|
2289
|
-
var DEFAULT_TRACER_NAME8 =
|
|
2464
|
+
var DEFAULT_TRACER_NAME8 = 'autotel-plugins/rabbitmq';
|
|
2290
2465
|
async function withPublishSpan(descriptor, fn) {
|
|
2291
2466
|
const {
|
|
2292
2467
|
name,
|
|
2293
|
-
exchange =
|
|
2468
|
+
exchange = 'amq.default',
|
|
2294
2469
|
routingKey,
|
|
2295
2470
|
messageId,
|
|
2296
2471
|
correlationId,
|
|
2297
|
-
system =
|
|
2472
|
+
system = 'rabbitmq',
|
|
2298
2473
|
} = descriptor;
|
|
2299
2474
|
const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME8);
|
|
2300
2475
|
const span = tracer.startSpan(name, {
|
|
2301
|
-
kind: SpanKind.PRODUCER
|
|
2476
|
+
kind: SpanKind.PRODUCER,
|
|
2302
2477
|
});
|
|
2303
2478
|
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, system);
|
|
2304
2479
|
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, exchange);
|
|
2305
|
-
span.setAttribute(SEMATTRS_MESSAGING_OPERATION_NAME,
|
|
2480
|
+
span.setAttribute(SEMATTRS_MESSAGING_OPERATION_NAME, 'publish');
|
|
2306
2481
|
span.setAttribute(
|
|
2307
2482
|
SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY,
|
|
2308
|
-
routingKey
|
|
2483
|
+
routingKey,
|
|
2309
2484
|
);
|
|
2310
2485
|
if (messageId) {
|
|
2311
2486
|
span.setAttribute(SEMATTRS_MESSAGING_MESSAGE_ID, messageId);
|
|
@@ -2313,7 +2488,7 @@ async function withPublishSpan(descriptor, fn) {
|
|
|
2313
2488
|
if (correlationId) {
|
|
2314
2489
|
span.setAttribute(
|
|
2315
2490
|
SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID,
|
|
2316
|
-
correlationId
|
|
2491
|
+
correlationId,
|
|
2317
2492
|
);
|
|
2318
2493
|
}
|
|
2319
2494
|
const spanContext = otelTrace.setSpan(context.active(), span);
|
|
@@ -2337,15 +2512,20 @@ async function withPublishSpan(descriptor, fn) {
|
|
|
2337
2512
|
}
|
|
2338
2513
|
var DEFAULT_MAX_LINKS2 = 128;
|
|
2339
2514
|
function isValidSpanContext4(spanContext) {
|
|
2340
|
-
return !!(
|
|
2515
|
+
return !!(
|
|
2516
|
+
spanContext &&
|
|
2517
|
+
spanContext.traceId &&
|
|
2518
|
+
spanContext.spanId &&
|
|
2519
|
+
otelTrace.isSpanContextValid(spanContext)
|
|
2520
|
+
);
|
|
2341
2521
|
}
|
|
2342
2522
|
function hashTraceIdsSync2(traceIds) {
|
|
2343
|
-
const input = traceIds.join(
|
|
2523
|
+
const input = traceIds.join('|');
|
|
2344
2524
|
let hash = 5381;
|
|
2345
2525
|
for (let i = 0; i < input.length; i++) {
|
|
2346
|
-
hash = hash * 33 ^ input.charCodeAt(i);
|
|
2526
|
+
hash = (hash * 33) ^ input.charCodeAt(i);
|
|
2347
2527
|
}
|
|
2348
|
-
return (hash >>> 0).toString(16).padStart(16,
|
|
2528
|
+
return (hash >>> 0).toString(16).padStart(16, '0');
|
|
2349
2529
|
}
|
|
2350
2530
|
function extractBatchLineage2(items, options = {}) {
|
|
2351
2531
|
const { includeTraceIds = false, maxLinks = DEFAULT_MAX_LINKS2 } = options;
|
|
@@ -2355,23 +2535,29 @@ function extractBatchLineage2(items, options = {}) {
|
|
|
2355
2535
|
const normalizedHeaders = normalizeHeaders2(item.headers);
|
|
2356
2536
|
const extractedCtx = extractTraceContext2(normalizedHeaders);
|
|
2357
2537
|
const spanContext = otelTrace.getSpanContext(extractedCtx);
|
|
2358
|
-
if (
|
|
2538
|
+
if (
|
|
2539
|
+
isValidSpanContext4(spanContext) &&
|
|
2540
|
+
!seenTraceIds.has(spanContext.traceId)
|
|
2541
|
+
) {
|
|
2359
2542
|
seenTraceIds.add(spanContext.traceId);
|
|
2360
2543
|
extractedContexts.push({
|
|
2361
2544
|
traceId: spanContext.traceId,
|
|
2362
|
-
spanContext
|
|
2545
|
+
spanContext,
|
|
2363
2546
|
});
|
|
2364
2547
|
}
|
|
2365
2548
|
}
|
|
2366
2549
|
extractedContexts.sort((a, b) => a.traceId.localeCompare(b.traceId));
|
|
2367
2550
|
const traceIds = extractedContexts.map((ec) => ec.traceId);
|
|
2368
|
-
const links = extractedContexts
|
|
2369
|
-
|
|
2551
|
+
const links = extractedContexts
|
|
2552
|
+
.slice(0, maxLinks)
|
|
2553
|
+
.map((ec) => ({ context: ec.spanContext }));
|
|
2554
|
+
const hash =
|
|
2555
|
+
traceIds.length > 0 ? hashTraceIdsSync2(traceIds) : '0000000000000000';
|
|
2370
2556
|
return {
|
|
2371
2557
|
linked_trace_id_count: traceIds.length,
|
|
2372
2558
|
linked_trace_id_hash: hash,
|
|
2373
2559
|
links,
|
|
2374
|
-
...includeTraceIds && { trace_ids: traceIds }
|
|
2560
|
+
...(includeTraceIds && { trace_ids: traceIds }),
|
|
2375
2561
|
};
|
|
2376
2562
|
}
|
|
2377
2563
|
|
|
@@ -2383,6 +2569,78 @@ function recordAckResult(span, result, options) {
|
|
|
2383
2569
|
}
|
|
2384
2570
|
}
|
|
2385
2571
|
|
|
2386
|
-
export {
|
|
2572
|
+
export {
|
|
2573
|
+
BigQueryInstrumentation,
|
|
2574
|
+
CORRELATION_ID_HEADER,
|
|
2575
|
+
ConsumerMetrics,
|
|
2576
|
+
SEMATTRS_DB_COLLECTION_NAME,
|
|
2577
|
+
SEMATTRS_DB_NAME,
|
|
2578
|
+
SEMATTRS_DB_NAMESPACE,
|
|
2579
|
+
SEMATTRS_DB_OPERATION,
|
|
2580
|
+
SEMATTRS_DB_OPERATION_NAME,
|
|
2581
|
+
SEMATTRS_DB_QUERY_SUMMARY,
|
|
2582
|
+
SEMATTRS_DB_QUERY_TEXT,
|
|
2583
|
+
SEMATTRS_DB_STATEMENT,
|
|
2584
|
+
SEMATTRS_DB_SYSTEM,
|
|
2585
|
+
SEMATTRS_DB_SYSTEM_NAME,
|
|
2586
|
+
SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE,
|
|
2587
|
+
SEMATTRS_GCP_BIGQUERY_JOB_ID,
|
|
2588
|
+
SEMATTRS_GCP_BIGQUERY_JOB_LOCATION,
|
|
2589
|
+
SEMATTRS_GCP_BIGQUERY_PROJECT_ID,
|
|
2590
|
+
SEMATTRS_GCP_BIGQUERY_QUERY_HASH,
|
|
2591
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED,
|
|
2592
|
+
SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED,
|
|
2593
|
+
SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS,
|
|
2594
|
+
SEMATTRS_GCP_BIGQUERY_SOURCE_TABLES,
|
|
2595
|
+
SEMATTRS_GCP_BIGQUERY_STATEMENT_TYPE,
|
|
2596
|
+
SEMATTRS_LINKED_TRACE_ID_COUNT,
|
|
2597
|
+
SEMATTRS_LINKED_TRACE_ID_HASH,
|
|
2598
|
+
SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT,
|
|
2599
|
+
SEMATTRS_MESSAGING_CONSUMER_ID,
|
|
2600
|
+
SEMATTRS_MESSAGING_DESTINATION_NAME,
|
|
2601
|
+
SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET,
|
|
2602
|
+
SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET,
|
|
2603
|
+
SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED,
|
|
2604
|
+
SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED,
|
|
2605
|
+
SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS,
|
|
2606
|
+
SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP,
|
|
2607
|
+
SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY,
|
|
2608
|
+
SEMATTRS_MESSAGING_KAFKA_OFFSET,
|
|
2609
|
+
SEMATTRS_MESSAGING_KAFKA_PARTITION,
|
|
2610
|
+
SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID,
|
|
2611
|
+
SEMATTRS_MESSAGING_MESSAGE_ID,
|
|
2612
|
+
SEMATTRS_MESSAGING_OPERATION,
|
|
2613
|
+
SEMATTRS_MESSAGING_OPERATION_NAME,
|
|
2614
|
+
SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT,
|
|
2615
|
+
SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE,
|
|
2616
|
+
SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY,
|
|
2617
|
+
SEMATTRS_MESSAGING_RABBITMQ_REQUEUE,
|
|
2618
|
+
SEMATTRS_MESSAGING_SYSTEM,
|
|
2619
|
+
SEMATTRS_NET_PEER_NAME,
|
|
2620
|
+
SEMATTRS_NET_PEER_PORT,
|
|
2621
|
+
createMessageErrorSpan,
|
|
2622
|
+
createStreamProcessor,
|
|
2623
|
+
deriveCorrelationId,
|
|
2624
|
+
deriveCorrelationId2 as deriveRabbitMQCorrelationId,
|
|
2625
|
+
extractBatchLineage,
|
|
2626
|
+
extractBatchLineageAsync,
|
|
2627
|
+
extractCorrelationId,
|
|
2628
|
+
extractBatchLineage2 as extractRabbitMQBatchLineage,
|
|
2629
|
+
extractCorrelationId2 as extractRabbitMQCorrelationId,
|
|
2630
|
+
extractTraceContext2 as extractRabbitMQTraceContext,
|
|
2631
|
+
extractTraceContext,
|
|
2632
|
+
injectTraceHeaders2 as injectRabbitMQTraceHeaders,
|
|
2633
|
+
injectTraceHeaders,
|
|
2634
|
+
instrumentBigQuery,
|
|
2635
|
+
instrumentConsumerEvents,
|
|
2636
|
+
normalizeHeaders,
|
|
2637
|
+
normalizeHeaders2 as normalizeRabbitMQHeaders,
|
|
2638
|
+
recordAckResult,
|
|
2639
|
+
withBatchConsumer,
|
|
2640
|
+
withConsumeSpan,
|
|
2641
|
+
withProcessingSpan,
|
|
2642
|
+
withProducerSpan,
|
|
2643
|
+
withPublishSpan,
|
|
2644
|
+
};
|
|
2645
|
+
//# sourceMappingURL=index.js.map
|
|
2387
2646
|
//# sourceMappingURL=index.js.map
|
|
2388
|
-
//# sourceMappingURL=index.js.map
|