@monocle.sh/adonisjs-agent 1.0.0-beta.10 → 1.0.0-beta.12
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/README.md +11 -3
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/init.mjs +1 -43
- package/dist/monocle_provider.mjs +1 -1
- package/dist/src/cli_instrumentation.mjs +2 -1
- package/dist/src/define_config.d.mts +0 -1
- package/dist/src/define_config.mjs +31 -4
- package/dist/src/instrumentations/mail/instrumentation.mjs +3 -2
- package/dist/src/types.d.mts +7 -1
- package/dist/stubs/config.stub +9 -1
- package/dist/types.d.mts +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ try {
|
|
|
81
81
|
The `config/monocle.ts` file supports the following options:
|
|
82
82
|
|
|
83
83
|
```typescript
|
|
84
|
-
import { defineConfig } from '@monocle.sh/adonisjs-agent'
|
|
84
|
+
import { defineConfig, destinations } from '@monocle.sh/adonisjs-agent'
|
|
85
85
|
import env from '#start/env'
|
|
86
86
|
|
|
87
87
|
export default defineConfig({
|
|
@@ -96,6 +96,14 @@ export default defineConfig({
|
|
|
96
96
|
serviceVersion: env.get('APP_VERSION'),
|
|
97
97
|
environment: env.get('APP_ENV'),
|
|
98
98
|
|
|
99
|
+
// Additional OTLP destinations (Monocle is always injected automatically)
|
|
100
|
+
destinations: {
|
|
101
|
+
grafana: destinations.otlp({
|
|
102
|
+
endpoint: env.get('GRAFANA_OTLP_ENDPOINT'),
|
|
103
|
+
signals: 'all',
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
106
|
+
|
|
99
107
|
// Host metrics (CPU, Memory, Network, etc.)
|
|
100
108
|
// Set to false to disable
|
|
101
109
|
hostMetrics: {
|
|
@@ -108,13 +116,13 @@ export default defineConfig({
|
|
|
108
116
|
exclude: ['make:*', 'generate:*', 'queue:work', 'queue:listen'],
|
|
109
117
|
},
|
|
110
118
|
|
|
111
|
-
// Trace batching configuration
|
|
119
|
+
// Trace/log batching configuration for Monocle destination
|
|
112
120
|
batch: {
|
|
113
121
|
maxExportBatchSize: 512,
|
|
114
122
|
scheduledDelayMillis: 5000,
|
|
115
123
|
},
|
|
116
124
|
|
|
117
|
-
// Enable gzip compression (default: true)
|
|
125
|
+
// Enable gzip compression for Monocle destination (default: true)
|
|
118
126
|
compression: true,
|
|
119
127
|
})
|
|
120
128
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -4,4 +4,5 @@ import { Monocle } from "./src/monocle.mjs";
|
|
|
4
4
|
import { configure } from "./configure.mjs";
|
|
5
5
|
import { extractTraceContext, getCurrentSpan, handleError, injectTraceContext, otelLoggingPreset, record, recordEvent, setAttributes } from "./helpers.mjs";
|
|
6
6
|
import { SpanAllOptions, SpanOptions, span, spanAll } from "./decorators.mjs";
|
|
7
|
-
|
|
7
|
+
import { destinations } from "@adonisjs/otel";
|
|
8
|
+
export { type BatchConfig, type CliTracingConfig, type HostMetricsConfig, Monocle, type MonocleConfig, type SpanAllOptions, type SpanOptions, configure, defineConfig, destinations, extractTraceContext, getCurrentSpan, handleError, injectTraceContext, otelLoggingPreset, record, recordEvent, setAttributes, span, spanAll };
|
package/dist/index.mjs
CHANGED
|
@@ -3,5 +3,6 @@ import { Monocle } from "./src/monocle.mjs";
|
|
|
3
3
|
import { configure } from "./configure.mjs";
|
|
4
4
|
import { extractTraceContext, getCurrentSpan, handleError, injectTraceContext, otelLoggingPreset, record, recordEvent, setAttributes } from "./helpers.mjs";
|
|
5
5
|
import { span, spanAll } from "./decorators.mjs";
|
|
6
|
+
import { destinations } from "@adonisjs/otel";
|
|
6
7
|
|
|
7
|
-
export { Monocle, configure, defineConfig, extractTraceContext, getCurrentSpan, handleError, injectTraceContext, otelLoggingPreset, record, recordEvent, setAttributes, span, spanAll };
|
|
8
|
+
export { Monocle, configure, defineConfig, destinations, extractTraceContext, getCurrentSpan, handleError, injectTraceContext, otelLoggingPreset, record, recordEvent, setAttributes, span, spanAll };
|
package/dist/init.mjs
CHANGED
|
@@ -8,12 +8,6 @@ import { createAddHookMessageChannel } from "import-in-the-middle";
|
|
|
8
8
|
* Also stolen and tweaked from @adonisjs/otel in order to use our own config file.
|
|
9
9
|
* Need to be able to remove this file in the future.
|
|
10
10
|
*/
|
|
11
|
-
const DEFAULT_BATCH_CONFIG = {
|
|
12
|
-
maxExportBatchSize: 512,
|
|
13
|
-
scheduledDelayMillis: 5e3,
|
|
14
|
-
exportTimeoutMillis: 3e4,
|
|
15
|
-
maxQueueSize: 2048
|
|
16
|
-
};
|
|
17
11
|
async function loadConfig(path) {
|
|
18
12
|
return await import(pathToFileURL(path).href).then((mod) => mod.default || mod).catch((error) => {
|
|
19
13
|
throw new Error(`Failed to load Monocle config file at "${path}"`, { cause: error });
|
|
@@ -24,49 +18,13 @@ function setupHooks() {
|
|
|
24
18
|
register("import-in-the-middle/hook.mjs", import.meta.url, registerOptions);
|
|
25
19
|
return waitForAllMessagesAcknowledged;
|
|
26
20
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Create a metric reader for exporting metrics via OTLP
|
|
29
|
-
*/
|
|
30
|
-
async function createMetricReader(config) {
|
|
31
|
-
const { PeriodicExportingMetricReader } = await import("@opentelemetry/sdk-metrics");
|
|
32
|
-
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-http");
|
|
33
|
-
return new PeriodicExportingMetricReader({
|
|
34
|
-
exporter: new OTLPMetricExporter({ compression: config.compression !== false ? "gzip" : void 0 }),
|
|
35
|
-
exportIntervalMillis: 6e4
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create a BatchSpanProcessor for efficient trace export with compression
|
|
40
|
-
*/
|
|
41
|
-
async function createSpanProcessor(config) {
|
|
42
|
-
const { BatchSpanProcessor } = await import("@opentelemetry/sdk-trace-base");
|
|
43
|
-
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-http");
|
|
44
|
-
const compression = config.compression !== false ? "gzip" : void 0;
|
|
45
|
-
const batchConfig = {
|
|
46
|
-
...DEFAULT_BATCH_CONFIG,
|
|
47
|
-
...config.batch
|
|
48
|
-
};
|
|
49
|
-
return new BatchSpanProcessor(new OTLPTraceExporter({ compression }), {
|
|
50
|
-
maxExportBatchSize: batchConfig.maxExportBatchSize,
|
|
51
|
-
scheduledDelayMillis: batchConfig.scheduledDelayMillis,
|
|
52
|
-
exportTimeoutMillis: batchConfig.exportTimeoutMillis,
|
|
53
|
-
maxQueueSize: batchConfig.maxQueueSize
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
21
|
async function init(dirname) {
|
|
57
22
|
const waitForAllMessagesAcknowledged = setupHooks();
|
|
58
23
|
const { OtelManager } = await import("@adonisjs/otel/manager");
|
|
59
24
|
const config = await loadConfig(join(dirname, "config/monocle.js"));
|
|
60
25
|
if (!config) return;
|
|
61
26
|
if (!OtelManager.isEnabled(config)) return;
|
|
62
|
-
const
|
|
63
|
-
const spanProcessor = await createSpanProcessor(config);
|
|
64
|
-
const configWithProcessors = {
|
|
65
|
-
...config,
|
|
66
|
-
metricReader,
|
|
67
|
-
spanProcessors: [spanProcessor, ...config.spanProcessors || []]
|
|
68
|
-
};
|
|
69
|
-
const manager = OtelManager.create(configWithProcessors);
|
|
27
|
+
const manager = OtelManager.create(config);
|
|
70
28
|
manager?.start();
|
|
71
29
|
const shutdown = async () => {
|
|
72
30
|
await manager?.shutdown().catch(() => {});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExceptionReporter, toHttpError } from "./src/exception_reporter.mjs";
|
|
2
|
+
import { OtelManager } from "@adonisjs/otel";
|
|
2
3
|
import { getCurrentSpan } from "@adonisjs/otel/helpers";
|
|
3
4
|
import OtelMiddleware from "@adonisjs/otel/otel_middleware";
|
|
4
|
-
import { OtelManager } from "@adonisjs/otel";
|
|
5
5
|
import { ExceptionHandler } from "@adonisjs/core/http";
|
|
6
6
|
import { configProvider } from "@adonisjs/core";
|
|
7
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ExceptionReporter } from "./exception_reporter.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { SpanKind, context, trace } from "@opentelemetry/api";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
4
5
|
|
|
5
6
|
//#region src/cli_instrumentation.ts
|
|
6
7
|
/**
|
|
@@ -69,7 +70,7 @@ function shouldTraceCommand(commandName, config) {
|
|
|
69
70
|
*/
|
|
70
71
|
async function instrumentCliCommands(config, appRoot) {
|
|
71
72
|
const tracer = trace.getTracer("@monocle.sh/adonisjs-agent", "1.0.0");
|
|
72
|
-
const BaseCommand = (await import(createRequire(appRoot ?
|
|
73
|
+
const BaseCommand = (await import(pathToFileURL(createRequire(appRoot ? pathToFileURL(`${appRoot}/package.json`).href : import.meta.url).resolve("@adonisjs/core/ace")).href)).BaseCommand;
|
|
73
74
|
const originalExec = BaseCommand.prototype.exec;
|
|
74
75
|
BaseCommand.prototype.exec = async function() {
|
|
75
76
|
const commandName = this.constructor.commandName;
|
|
@@ -3,7 +3,6 @@ import { MonocleConfig } from "./types.mjs";
|
|
|
3
3
|
//#region src/define_config.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Define and validate Monocle agent configuration.
|
|
6
|
-
* Sets up environment variables for OTEL exporters to point to Monocle.
|
|
7
6
|
* Returns undefined if no API key is provided (telemetry will be disabled).
|
|
8
7
|
*/
|
|
9
8
|
declare function defineConfig(config: MonocleConfig): MonocleConfig | undefined;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { destinations } from "@adonisjs/otel";
|
|
2
|
+
|
|
1
3
|
//#region src/define_config.ts
|
|
4
|
+
const DEFAULT_BATCH_CONFIG = {
|
|
5
|
+
maxExportBatchSize: 512,
|
|
6
|
+
scheduledDelayMillis: 5e3,
|
|
7
|
+
exportTimeoutMillis: 3e4,
|
|
8
|
+
maxQueueSize: 2048
|
|
9
|
+
};
|
|
2
10
|
/**
|
|
3
11
|
* Extracts a header value from either ServerResponse (getHeader) or IncomingMessage (headers object).
|
|
4
12
|
*/
|
|
@@ -42,15 +50,17 @@ function extractUserResponseHook(httpConfig) {
|
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* Define and validate Monocle agent configuration.
|
|
45
|
-
* Sets up environment variables for OTEL exporters to point to Monocle.
|
|
46
53
|
* Returns undefined if no API key is provided (telemetry will be disabled).
|
|
47
54
|
*/
|
|
48
55
|
function defineConfig(config) {
|
|
49
56
|
if (!config.apiKey) return;
|
|
50
57
|
const endpoint = config.endpoint || "https://ingest.monocle.sh";
|
|
51
58
|
const environment = config.environment || process.env.NODE_ENV || "development";
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
const compression = config.compression === false ? "none" : "gzip";
|
|
60
|
+
const batchConfig = {
|
|
61
|
+
...DEFAULT_BATCH_CONFIG,
|
|
62
|
+
...config.batch
|
|
63
|
+
};
|
|
54
64
|
const httpConfig = config.instrumentations?.["@opentelemetry/instrumentation-http"];
|
|
55
65
|
const userResponseHook = extractUserResponseHook(httpConfig);
|
|
56
66
|
const instrumentations = {
|
|
@@ -60,11 +70,28 @@ function defineConfig(config) {
|
|
|
60
70
|
responseHook: createConnectionTypeHook(userResponseHook)
|
|
61
71
|
}
|
|
62
72
|
};
|
|
73
|
+
const monocleDestination = destinations.otlp({
|
|
74
|
+
endpoint,
|
|
75
|
+
signals: "all",
|
|
76
|
+
compression,
|
|
77
|
+
headers: {
|
|
78
|
+
"x-api-key": config.apiKey,
|
|
79
|
+
"x-monocle-env": environment
|
|
80
|
+
},
|
|
81
|
+
maxExportBatchSize: batchConfig.maxExportBatchSize,
|
|
82
|
+
scheduledDelayMillis: batchConfig.scheduledDelayMillis,
|
|
83
|
+
exportTimeoutMillis: batchConfig.exportTimeoutMillis,
|
|
84
|
+
maxQueueSize: batchConfig.maxQueueSize
|
|
85
|
+
});
|
|
63
86
|
return {
|
|
64
87
|
...config,
|
|
65
88
|
endpoint,
|
|
66
89
|
environment,
|
|
67
|
-
instrumentations
|
|
90
|
+
instrumentations,
|
|
91
|
+
destinations: {
|
|
92
|
+
...config.destinations,
|
|
93
|
+
monocle: monocleDestination
|
|
94
|
+
}
|
|
68
95
|
};
|
|
69
96
|
}
|
|
70
97
|
|
|
@@ -2,6 +2,7 @@ import { ExceptionReporter } from "../../exception_reporter.mjs";
|
|
|
2
2
|
import { EmailAttributes } from "./types.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { SpanKind, SpanStatusCode, context, trace } from "@opentelemetry/api";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
5
6
|
import { InstrumentationBase } from "@opentelemetry/instrumentation";
|
|
6
7
|
|
|
7
8
|
//#region src/instrumentations/mail/instrumentation.ts
|
|
@@ -116,14 +117,14 @@ var MailInstrumentation = class extends InstrumentationBase {
|
|
|
116
117
|
async enable() {
|
|
117
118
|
if (this.patched) return;
|
|
118
119
|
const appRoot = this.getConfig().appRoot;
|
|
119
|
-
const require = createRequire(appRoot ?
|
|
120
|
+
const require = createRequire(appRoot ? pathToFileURL(`${appRoot}/package.json`).href : import.meta.url);
|
|
120
121
|
let mailerPath;
|
|
121
122
|
try {
|
|
122
123
|
mailerPath = require.resolve("@adonisjs/mail");
|
|
123
124
|
} catch {
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
126
|
-
this.mailerClass = (await import(mailerPath)).Mailer;
|
|
127
|
+
this.mailerClass = (await import(pathToFileURL(mailerPath).href)).Mailer;
|
|
127
128
|
this.originalSendCompiled = this.mailerClass.prototype.sendCompiled;
|
|
128
129
|
this.originalSendLaterCompiled = this.mailerClass.prototype.sendLaterCompiled;
|
|
129
130
|
this.mailerClass.prototype.sendCompiled = this.#createSendCompiledWrapper(this.originalSendCompiled);
|
package/dist/src/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OtelConfig } from "@adonisjs/otel/types";
|
|
1
|
+
import { DestinationMap, OtelConfig } from "@adonisjs/otel/types";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/**
|
|
@@ -95,6 +95,12 @@ interface MonocleConfig extends Omit<OtelConfig, 'traceExporter' | 'metricExport
|
|
|
95
95
|
* @default process.env.NODE_ENV || 'development'
|
|
96
96
|
*/
|
|
97
97
|
environment?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Additional OTLP destinations (Grafana, Honeycomb, etc.).
|
|
100
|
+
*
|
|
101
|
+
* Monocle destination is always injected automatically and cannot be removed.
|
|
102
|
+
*/
|
|
103
|
+
destinations?: DestinationMap;
|
|
98
104
|
/**
|
|
99
105
|
* Host metrics configuration (CPU, Memory, Network, etc.).
|
|
100
106
|
* Set to `false` to disable, or pass config object.
|
package/dist/stubs/config.stub
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{{{
|
|
2
2
|
exports({ to: app.configPath('monocle.ts') })
|
|
3
3
|
}}}
|
|
4
|
-
import { defineConfig } from '@monocle.sh/adonisjs-agent'
|
|
4
|
+
import { defineConfig, destinations } from '@monocle.sh/adonisjs-agent'
|
|
5
5
|
import env from '#start/env'
|
|
6
6
|
|
|
7
7
|
export default defineConfig({
|
|
@@ -10,4 +10,12 @@ export default defineConfig({
|
|
|
10
10
|
serviceName: env.get('APP_NAME'),
|
|
11
11
|
serviceVersion: env.get('APP_VERSION'),
|
|
12
12
|
environment: env.get('APP_ENV'),
|
|
13
|
+
|
|
14
|
+
// Optional: Additional OTLP destinations (Monocle is injected automatically)
|
|
15
|
+
// destinations: {
|
|
16
|
+
// grafana: destinations.otlp({
|
|
17
|
+
// endpoint: env.get('GRAFANA_OTLP_ENDPOINT'),
|
|
18
|
+
// signals: 'all',
|
|
19
|
+
// }),
|
|
20
|
+
// },
|
|
13
21
|
})
|
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BatchConfig, CliTracingConfig, HostMetricsConfig, MonocleConfig } from "./src/types.mjs";
|
|
2
2
|
import { SpanAllOptions, SpanOptions } from "./decorators.mjs";
|
|
3
|
-
import { HeadersCarrier, OtelLoggingPresetOptions, UserContextResult } from "@adonisjs/otel/types";
|
|
4
|
-
export { type BatchConfig, type CliTracingConfig, type HeadersCarrier, type HostMetricsConfig, type MonocleConfig, type OtelLoggingPresetOptions, type SpanAllOptions, type SpanOptions, type UserContextResult };
|
|
3
|
+
import { DestinationConfig, DestinationMap, DestinationSignal, DestinationSignals, HeadersCarrier, OtelLoggingPresetOptions, OtlpDestinationConfig, OtlpDestinationOptions, UserContextResult } from "@adonisjs/otel/types";
|
|
4
|
+
export { type BatchConfig, type CliTracingConfig, type DestinationConfig, type DestinationMap, type DestinationSignal, type DestinationSignals, type HeadersCarrier, type HostMetricsConfig, type MonocleConfig, type OtelLoggingPresetOptions, type OtlpDestinationConfig, type OtlpDestinationOptions, type SpanAllOptions, type SpanOptions, type UserContextResult };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monocle.sh/adonisjs-agent",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.12",
|
|
4
4
|
"description": "Monocle agent for AdonisJS - sends telemetry to Monocle cloud",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adonisjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"tag": "beta"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@adonisjs/otel": "^1.
|
|
34
|
+
"@adonisjs/otel": "^1.2.0",
|
|
35
35
|
"@opentelemetry/api": "^1.9.0",
|
|
36
36
|
"@opentelemetry/core": "^2.5.0",
|
|
37
37
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.211.0",
|