@redthreadlabs/tracelog 1.4.0
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/LICENSE +26 -0
- package/README.md +126 -0
- package/index.d.ts +464 -0
- package/index.js +11 -0
- package/lib/InflightEventSet.js +53 -0
- package/lib/activation-method.js +97 -0
- package/lib/agent.js +1226 -0
- package/lib/apm-client/apm-client.js +107 -0
- package/lib/apm-client/channel-writer.js +334 -0
- package/lib/apm-client/jsonl-file-client.js +241 -0
- package/lib/apm-client/ndjson.js +20 -0
- package/lib/apm-client/noop-apm-client.js +79 -0
- package/lib/apm-client/s3-uploader.js +308 -0
- package/lib/apm-client/truncate.js +507 -0
- package/lib/async-hooks-polyfill.js +58 -0
- package/lib/cloud-metadata/aws.js +175 -0
- package/lib/cloud-metadata/azure.js +123 -0
- package/lib/cloud-metadata/callback-coordination.js +159 -0
- package/lib/cloud-metadata/gcp.js +133 -0
- package/lib/cloud-metadata/index.js +175 -0
- package/lib/config/config.js +431 -0
- package/lib/config/normalizers.js +649 -0
- package/lib/config/schema.js +946 -0
- package/lib/constants.js +35 -0
- package/lib/errors.js +303 -0
- package/lib/filters/sanitize-field-names.js +69 -0
- package/lib/http-request.js +249 -0
- package/lib/instrumentation/context.js +56 -0
- package/lib/instrumentation/dropped-spans-stats.js +112 -0
- package/lib/instrumentation/elasticsearch-shared.js +63 -0
- package/lib/instrumentation/express-utils.js +91 -0
- package/lib/instrumentation/generic-span.js +322 -0
- package/lib/instrumentation/http-shared.js +424 -0
- package/lib/instrumentation/ids.js +39 -0
- package/lib/instrumentation/index.js +1078 -0
- package/lib/instrumentation/modules/@apollo/server.js +39 -0
- package/lib/instrumentation/modules/@aws-sdk/client-dynamodb.js +143 -0
- package/lib/instrumentation/modules/@aws-sdk/client-s3.js +230 -0
- package/lib/instrumentation/modules/@aws-sdk/client-sns.js +197 -0
- package/lib/instrumentation/modules/@aws-sdk/client-sqs.js +336 -0
- package/lib/instrumentation/modules/@elastic/elasticsearch.js +343 -0
- package/lib/instrumentation/modules/@hapi/hapi.js +221 -0
- package/lib/instrumentation/modules/@redis/client/dist/lib/client/commands-queue.js +178 -0
- package/lib/instrumentation/modules/@redis/client/dist/lib/client/index.js +49 -0
- package/lib/instrumentation/modules/@smithy/smithy-client.js +198 -0
- package/lib/instrumentation/modules/apollo-server-core.js +49 -0
- package/lib/instrumentation/modules/aws-sdk/dynamodb.js +155 -0
- package/lib/instrumentation/modules/aws-sdk/s3.js +184 -0
- package/lib/instrumentation/modules/aws-sdk/sns.js +232 -0
- package/lib/instrumentation/modules/aws-sdk/sqs.js +361 -0
- package/lib/instrumentation/modules/aws-sdk.js +76 -0
- package/lib/instrumentation/modules/bluebird.js +93 -0
- package/lib/instrumentation/modules/cassandra-driver.js +280 -0
- package/lib/instrumentation/modules/elasticsearch.js +200 -0
- package/lib/instrumentation/modules/express-graphql.js +66 -0
- package/lib/instrumentation/modules/express-queue.js +28 -0
- package/lib/instrumentation/modules/express.js +162 -0
- package/lib/instrumentation/modules/fastify.js +179 -0
- package/lib/instrumentation/modules/finalhandler.js +41 -0
- package/lib/instrumentation/modules/generic-pool.js +85 -0
- package/lib/instrumentation/modules/graphql.js +256 -0
- package/lib/instrumentation/modules/handlebars.js +33 -0
- package/lib/instrumentation/modules/http.js +112 -0
- package/lib/instrumentation/modules/http2.js +320 -0
- package/lib/instrumentation/modules/https.js +68 -0
- package/lib/instrumentation/modules/ioredis.js +94 -0
- package/lib/instrumentation/modules/jade.js +29 -0
- package/lib/instrumentation/modules/kafkajs.js +476 -0
- package/lib/instrumentation/modules/knex.js +91 -0
- package/lib/instrumentation/modules/koa-router.js +74 -0
- package/lib/instrumentation/modules/koa.js +15 -0
- package/lib/instrumentation/modules/memcached.js +100 -0
- package/lib/instrumentation/modules/mimic-response.js +45 -0
- package/lib/instrumentation/modules/mongodb/lib/cmap/connection_pool.js +40 -0
- package/lib/instrumentation/modules/mongodb-core.js +206 -0
- package/lib/instrumentation/modules/mongodb.js +259 -0
- package/lib/instrumentation/modules/mysql.js +200 -0
- package/lib/instrumentation/modules/mysql2.js +140 -0
- package/lib/instrumentation/modules/pg.js +148 -0
- package/lib/instrumentation/modules/pug.js +29 -0
- package/lib/instrumentation/modules/redis.js +176 -0
- package/lib/instrumentation/modules/restify.js +52 -0
- package/lib/instrumentation/modules/tedious.js +159 -0
- package/lib/instrumentation/modules/undici.js +270 -0
- package/lib/instrumentation/modules/ws.js +59 -0
- package/lib/instrumentation/noop-transaction.js +81 -0
- package/lib/instrumentation/run-context/AbstractRunContextManager.js +215 -0
- package/lib/instrumentation/run-context/AsyncHooksRunContextManager.js +106 -0
- package/lib/instrumentation/run-context/AsyncLocalStorageRunContextManager.js +73 -0
- package/lib/instrumentation/run-context/BasicRunContextManager.js +82 -0
- package/lib/instrumentation/run-context/RunContext.js +151 -0
- package/lib/instrumentation/run-context/index.js +23 -0
- package/lib/instrumentation/shimmer.js +123 -0
- package/lib/instrumentation/span-compression.js +239 -0
- package/lib/instrumentation/span.js +621 -0
- package/lib/instrumentation/template-shared.js +43 -0
- package/lib/instrumentation/timer.js +84 -0
- package/lib/instrumentation/transaction.js +571 -0
- package/lib/load-source-map.js +100 -0
- package/lib/logging.js +212 -0
- package/lib/metrics/index.js +92 -0
- package/lib/metrics/platforms/generic/index.js +40 -0
- package/lib/metrics/platforms/generic/process-cpu.js +22 -0
- package/lib/metrics/platforms/generic/process-top.js +157 -0
- package/lib/metrics/platforms/generic/stats.js +34 -0
- package/lib/metrics/platforms/generic/system-cpu.js +51 -0
- package/lib/metrics/platforms/linux/index.js +19 -0
- package/lib/metrics/platforms/linux/stats.js +213 -0
- package/lib/metrics/queue.js +90 -0
- package/lib/metrics/registry.js +52 -0
- package/lib/metrics/reporter.js +119 -0
- package/lib/metrics/runtime.js +77 -0
- package/lib/middleware/connect.js +16 -0
- package/lib/parsers.js +225 -0
- package/lib/propwrap.js +147 -0
- package/lib/stacktraces.js +537 -0
- package/lib/symbols.js +15 -0
- package/lib/tracecontext/index.js +115 -0
- package/lib/tracecontext/traceparent.js +185 -0
- package/lib/tracecontext/tracestate.js +388 -0
- package/lib/wildcard-matcher.js +52 -0
- package/loader.mjs +7 -0
- package/package.json +98 -0
- package/start.d.ts +8 -0
- package/start.js +29 -0
- package/types/aws-lambda.d.ts +98 -0
- package/types/connect.d.ts +23 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and other contributors where applicable.
|
|
3
|
+
* Licensed under the BSD 2-Clause License; you may not use this file except in
|
|
4
|
+
* compliance with the BSD 2-Clause License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const errorStackParser = require('error-stack-parser');
|
|
12
|
+
const semver = require('semver');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const CONTAINS_R_TRACELOG_START =
|
|
16
|
+
/(-r\s+|--require\s*=?\s*).*tracelog\/start/;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Determine the 'service.agent.activation_method' metadata value from an Error
|
|
20
|
+
* stack collected at `Agent.start()` time. Spec:
|
|
21
|
+
* https://github.com/elastic/apm/blob/main/specs/agents/metadata.md#activation-method
|
|
22
|
+
*
|
|
23
|
+
* @param {Error} startStack - An Error object with a captured stack trace.
|
|
24
|
+
* The `stackTraceLimit` for the stack should be at least 15 -- higher
|
|
25
|
+
* that the default of 10.
|
|
26
|
+
* @returns {string} one of the following values:
|
|
27
|
+
* - "unknown"
|
|
28
|
+
* - "require":
|
|
29
|
+
* require('tracelog').start(...)
|
|
30
|
+
* require('tracelog/start')
|
|
31
|
+
* - "import":
|
|
32
|
+
* import 'tracelog/start.js'
|
|
33
|
+
* import apm from 'tracelog'; apm.start()
|
|
34
|
+
* - "aws-lambda-layer": `NODE_OPTIONS` using Agent installed at /opt/nodejs/node_modules/tracelog
|
|
35
|
+
* - "k8s-attach": `NODE_OPTIONS` using Agent, and `TRACELOG_ACTIVATION_METHOD=K8S_ATTACH` in env
|
|
36
|
+
* - "env-attach": Fallback for any other usage of NODE_OPTIONS='-r tracelog/start'
|
|
37
|
+
* - "preload": For usage of `node -r tracelog/start` without `NODE_OPTIONS`.
|
|
38
|
+
*/
|
|
39
|
+
function agentActivationMethodFromStartStack(startStack, log) {
|
|
40
|
+
/* @param {require('stackframe').StackFrame[]} frames */
|
|
41
|
+
let frames;
|
|
42
|
+
try {
|
|
43
|
+
frames = errorStackParser.parse(startStack);
|
|
44
|
+
} catch (parseErr) {
|
|
45
|
+
log.trace(
|
|
46
|
+
parseErr,
|
|
47
|
+
'could not determine metadata.service.agent.activation_method',
|
|
48
|
+
);
|
|
49
|
+
return 'unknown';
|
|
50
|
+
}
|
|
51
|
+
if (frames.length < 2) {
|
|
52
|
+
return 'unknown';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// frames[0].fileName = "$topDir/lib/agent.js"
|
|
56
|
+
// at Agent.start (/Users/trentm/tmp/asdf/node_modules/tracelog/lib/agent.js:241:11)
|
|
57
|
+
const topDir = path.dirname(path.dirname(frames[0].fileName));
|
|
58
|
+
|
|
59
|
+
// If this was a preload (i.e. using `-r tracelog/start`), then
|
|
60
|
+
// there will be a frame with `functionName` equal to:
|
|
61
|
+
// - node >=12: 'loadPreloadModules'
|
|
62
|
+
// - node <12: 'preloadModules'
|
|
63
|
+
const functionName = semver.gte(process.version, '12.0.0', {
|
|
64
|
+
includePrerelease: true,
|
|
65
|
+
})
|
|
66
|
+
? 'loadPreloadModules'
|
|
67
|
+
: 'preloadModules';
|
|
68
|
+
let isPreload = false;
|
|
69
|
+
for (let i = frames.length - 1; i >= 2; i--) {
|
|
70
|
+
if (frames[i].functionName === functionName) {
|
|
71
|
+
isPreload = true;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (isPreload) {
|
|
76
|
+
return 'preload';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// To tell if tracelog was `import`d or `require`d we look for a
|
|
80
|
+
// frame with `functionName` equal to 'ModuleJob.run'. This has consistently
|
|
81
|
+
// been the name of this method back to at least Node v8.
|
|
82
|
+
const esmImportFunctionName = 'ModuleJob.run';
|
|
83
|
+
if (esmImportFunctionName) {
|
|
84
|
+
for (let i = frames.length - 1; i >= 2; i--) {
|
|
85
|
+
if (frames[i].functionName === esmImportFunctionName) {
|
|
86
|
+
return 'import';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Otherwise this was a manual `require(...)` of the agent in user code.
|
|
92
|
+
return 'require';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = {
|
|
96
|
+
agentActivationMethodFromStartStack,
|
|
97
|
+
};
|