@monocle.sh/adonisjs-agent 1.1.0 → 1.2.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/dist/configure.mjs +23 -1
- package/dist/init.mjs +3 -3
- package/dist/src/define_config.mjs +13 -8
- package/dist/src/types/config.d.mts +8 -2
- package/package.json +1 -1
package/dist/configure.mjs
CHANGED
|
@@ -10,7 +10,12 @@ async function configure(command) {
|
|
|
10
10
|
* Publish otel.ts at project root
|
|
11
11
|
*/
|
|
12
12
|
await codemods.makeUsingStub(stubsRoot, "otel.stub", {});
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Add otel.ts import as the FIRST import in bin/server.ts
|
|
15
|
+
* This is critical for auto-instrumentation to work
|
|
16
|
+
*/
|
|
17
|
+
const project = await codemods.getTsMorphProject();
|
|
18
|
+
const serverFile = project?.getSourceFile(command.app.makePath("bin/server.ts"));
|
|
14
19
|
if (serverFile) {
|
|
15
20
|
const insertIndex = serverFile.getImportDeclarations()[0]?.getChildIndex() ?? 0;
|
|
16
21
|
serverFile.insertStatements(insertIndex, [
|
|
@@ -24,6 +29,23 @@ async function configure(command) {
|
|
|
24
29
|
await serverFile.save();
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
32
|
+
* Add otel.ts import as the FIRST import in bin/console.ts
|
|
33
|
+
* Required for CLI command tracing to work
|
|
34
|
+
*/
|
|
35
|
+
const consoleFile = project?.getSourceFile(command.app.makePath("bin/console.ts"));
|
|
36
|
+
if (consoleFile) {
|
|
37
|
+
const insertIndex = consoleFile.getImportDeclarations()[0]?.getChildIndex() ?? 0;
|
|
38
|
+
consoleFile.insertStatements(insertIndex, [
|
|
39
|
+
"/**",
|
|
40
|
+
" * OpenTelemetry initialization - MUST be the first import",
|
|
41
|
+
" * @see https://opentelemetry.io/docs/languages/js/getting-started/nodejs/",
|
|
42
|
+
" */",
|
|
43
|
+
`import '../otel.js'`,
|
|
44
|
+
""
|
|
45
|
+
]);
|
|
46
|
+
await consoleFile.save();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
27
49
|
* Register the provider in adonisrc.ts
|
|
28
50
|
*/
|
|
29
51
|
await codemods.updateRcFile((rcFile) => {
|
package/dist/init.mjs
CHANGED
|
@@ -67,14 +67,14 @@ async function init(dirname) {
|
|
|
67
67
|
*
|
|
68
68
|
* Prerequisites for this to work:
|
|
69
69
|
* 1. App's `bin/console.ts` must import `otel.ts` FIRST (before reflect-metadata)
|
|
70
|
-
* 2. Config must have `cli.enabled:
|
|
70
|
+
* 2. Config must not have `cli: false` or `cli.enabled: false`
|
|
71
71
|
*
|
|
72
72
|
* @see ./cli_instrumentation.ts for implementation details
|
|
73
73
|
*/
|
|
74
74
|
const cliConfig = config.cli;
|
|
75
|
-
if (cliConfig !== false && cliConfig?.enabled) {
|
|
75
|
+
if (cliConfig !== false && cliConfig?.enabled !== false) {
|
|
76
76
|
const { instrumentCliCommands } = await import("./src/cli_instrumentation.mjs");
|
|
77
|
-
await instrumentCliCommands(cliConfig, dirname);
|
|
77
|
+
await instrumentCliCommands(cliConfig ?? {}, dirname);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Mail Instrumentation
|
|
@@ -52,12 +52,18 @@ function extractUserResponseHook(httpConfig) {
|
|
|
52
52
|
* Returns undefined if no API key is provided (telemetry will be disabled).
|
|
53
53
|
*/
|
|
54
54
|
function defineConfig(config) {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const isDev = config.dev ?? process.env.NODE_ENV === "development";
|
|
56
|
+
if (!isDev && !config.apiKey) return;
|
|
57
|
+
if (isDev) process.env.OTEL_EXPORTER_OTLP_PROTOCOL = "http/json";
|
|
58
|
+
const endpoint = isDev ? config.endpoint || "http://localhost:4200" : config.endpoint || "https://ingest.monocle.sh";
|
|
57
59
|
const environment = config.environment || process.env.NODE_ENV || "development";
|
|
58
|
-
const compression = config.compression === false ? "none" : "gzip";
|
|
59
|
-
const
|
|
60
|
+
const compression = isDev ? "none" : config.compression === false ? "none" : "gzip";
|
|
61
|
+
const devBatchConfig = {
|
|
60
62
|
...DEFAULT_BATCH_CONFIG,
|
|
63
|
+
scheduledDelayMillis: 100
|
|
64
|
+
};
|
|
65
|
+
const batchConfig = {
|
|
66
|
+
...isDev ? devBatchConfig : DEFAULT_BATCH_CONFIG,
|
|
61
67
|
...config.batch
|
|
62
68
|
};
|
|
63
69
|
const httpConfig = config.instrumentations?.["@opentelemetry/instrumentation-http"];
|
|
@@ -69,14 +75,13 @@ function defineConfig(config) {
|
|
|
69
75
|
responseHook: createConnectionTypeHook(userResponseHook)
|
|
70
76
|
}
|
|
71
77
|
};
|
|
78
|
+
const headers = { "x-monocle-env": environment };
|
|
79
|
+
if (config.apiKey) headers["x-api-key"] = config.apiKey;
|
|
72
80
|
const monocleDestination = destinations.otlp({
|
|
73
81
|
endpoint,
|
|
74
82
|
signals: "all",
|
|
75
83
|
compression,
|
|
76
|
-
headers
|
|
77
|
-
"x-api-key": config.apiKey,
|
|
78
|
-
"x-monocle-env": environment
|
|
79
|
-
},
|
|
84
|
+
headers,
|
|
80
85
|
maxExportBatchSize: batchConfig.maxExportBatchSize,
|
|
81
86
|
scheduledDelayMillis: batchConfig.scheduledDelayMillis,
|
|
82
87
|
exportTimeoutMillis: batchConfig.exportTimeoutMillis,
|
|
@@ -31,7 +31,7 @@ interface MailInstrumentationConfig {
|
|
|
31
31
|
interface CliTracingConfig {
|
|
32
32
|
/**
|
|
33
33
|
* Enable CLI command tracing.
|
|
34
|
-
* @default
|
|
34
|
+
* @default true
|
|
35
35
|
*/
|
|
36
36
|
enabled?: boolean;
|
|
37
37
|
/**
|
|
@@ -104,6 +104,12 @@ interface AiInstrumentationConfig {
|
|
|
104
104
|
}
|
|
105
105
|
type BullMQAgentConfig = BullMQInstrumentationConfig;
|
|
106
106
|
interface MonocleConfig extends Omit<OtelConfig, 'traceExporter' | 'metricExporter'> {
|
|
107
|
+
/**
|
|
108
|
+
* Enable local DevTools mode.
|
|
109
|
+
* Sends telemetry to Monocle DevTools (localhost:4200) with no compression.
|
|
110
|
+
* No API key required.
|
|
111
|
+
*/
|
|
112
|
+
dev?: boolean;
|
|
107
113
|
/**
|
|
108
114
|
* Your Monocle API key. If not provided, telemetry will be disabled.
|
|
109
115
|
* Format: mk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
@@ -151,7 +157,7 @@ interface MonocleConfig extends Omit<OtelConfig, 'traceExporter' | 'metricExport
|
|
|
151
157
|
/**
|
|
152
158
|
* CLI command tracing configuration.
|
|
153
159
|
* Set to `false` to disable, or pass config object.
|
|
154
|
-
* @default
|
|
160
|
+
* @default { enabled: true, exclude: ['make:*', 'generate:*', 'queue:work', 'queue:listen'] }
|
|
155
161
|
*/
|
|
156
162
|
cli?: false | CliTracingConfig;
|
|
157
163
|
/**
|