@monocle.sh/effect-agent 0.0.1
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 +15 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +3 -0
- package/dist/src/index.d.mts +4 -0
- package/dist/src/index.mjs +3 -0
- package/dist/src/layer.d.mts +18 -0
- package/dist/src/layer.mjs +93 -0
- package/dist/src/types.d.mts +35 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present, Julien Ripouteau
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MonocleEffectConfig } from "./types.mjs";
|
|
2
|
+
import { Resource } from "@effect/opentelemetry";
|
|
3
|
+
import { Layer } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/layer.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates an Effect Layer that configures OpenTelemetry with Monocle.
|
|
8
|
+
*
|
|
9
|
+
* Sets up OTLP exporters for traces, metrics, and logs with the proper
|
|
10
|
+
* Monocle authentication headers. Includes the MonocleSpanProcessor
|
|
11
|
+
* for automatic exception enrichment.
|
|
12
|
+
*
|
|
13
|
+
* Returns an empty layer when no API key is available and dev mode
|
|
14
|
+
* is disabled, making it safe for local development.
|
|
15
|
+
*/
|
|
16
|
+
declare function MonocleLayer(config: MonocleEffectConfig): Layer.Layer<Resource.Resource>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { MonocleLayer };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
2
|
+
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
3
|
+
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
4
|
+
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
|
|
5
|
+
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
6
|
+
import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
7
|
+
import { NodeSdk } from "@effect/opentelemetry";
|
|
8
|
+
import { Layer, Option, Redacted } from "effect";
|
|
9
|
+
import { MonocleSpanProcessor } from "@monocle.sh/otel-utils";
|
|
10
|
+
//#region src/layer.ts
|
|
11
|
+
const DEFAULT_ENDPOINT = "https://ingest.monocle.sh";
|
|
12
|
+
const DEV_ENDPOINT = "http://localhost:4200";
|
|
13
|
+
const DEFAULT_BATCH_CONFIG = {
|
|
14
|
+
maxExportBatchSize: 512,
|
|
15
|
+
scheduledDelayMillis: 5e3,
|
|
16
|
+
exportTimeoutMillis: 3e4,
|
|
17
|
+
maxQueueSize: 2048
|
|
18
|
+
};
|
|
19
|
+
const DEV_BATCH_CONFIG = {
|
|
20
|
+
...DEFAULT_BATCH_CONFIG,
|
|
21
|
+
scheduledDelayMillis: 100
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the Monocle API key from config or MONOCLE_API_KEY env var.
|
|
25
|
+
* Returns a Redacted value to prevent accidental logging.
|
|
26
|
+
*/
|
|
27
|
+
function resolveApiKey(configKey) {
|
|
28
|
+
const raw = configKey || process.env.MONOCLE_API_KEY;
|
|
29
|
+
if (!raw) return Option.none();
|
|
30
|
+
return Option.some(Redacted.make(raw));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the deployment environment.
|
|
34
|
+
* Priority: config > MONOCLE_ENVIRONMENT > NODE_ENV > 'development'
|
|
35
|
+
*/
|
|
36
|
+
function resolveEnvironment(configEnv) {
|
|
37
|
+
return configEnv || process.env.MONOCLE_ENVIRONMENT || process.env.NODE_ENV || "development";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates an Effect Layer that configures OpenTelemetry with Monocle.
|
|
41
|
+
*
|
|
42
|
+
* Sets up OTLP exporters for traces, metrics, and logs with the proper
|
|
43
|
+
* Monocle authentication headers. Includes the MonocleSpanProcessor
|
|
44
|
+
* for automatic exception enrichment.
|
|
45
|
+
*
|
|
46
|
+
* Returns an empty layer when no API key is available and dev mode
|
|
47
|
+
* is disabled, making it safe for local development.
|
|
48
|
+
*/
|
|
49
|
+
function MonocleLayer(config) {
|
|
50
|
+
const isDev = config.dev;
|
|
51
|
+
const apiKey = resolveApiKey(config.apiKey);
|
|
52
|
+
if (!isDev && Option.isNone(apiKey)) return Layer.empty;
|
|
53
|
+
const endpoint = isDev ? config.endpoint || DEV_ENDPOINT : config.endpoint || DEFAULT_ENDPOINT;
|
|
54
|
+
const environment = resolveEnvironment(config.environment);
|
|
55
|
+
const batchConfig = isDev ? DEV_BATCH_CONFIG : DEFAULT_BATCH_CONFIG;
|
|
56
|
+
const headers = { "x-monocle-env": environment };
|
|
57
|
+
if (Option.isSome(apiKey)) headers["x-api-key"] = Redacted.value(apiKey.value);
|
|
58
|
+
const monocleProcessor = new MonocleSpanProcessor();
|
|
59
|
+
return NodeSdk.layer(() => ({
|
|
60
|
+
resource: {
|
|
61
|
+
serviceName: config.serviceName,
|
|
62
|
+
serviceVersion: config.serviceVersion ?? "0.0.0",
|
|
63
|
+
attributes: { "deployment.environment": environment }
|
|
64
|
+
},
|
|
65
|
+
spanProcessor: [monocleProcessor, new BatchSpanProcessor(new OTLPTraceExporter({
|
|
66
|
+
url: `${endpoint}/v1/traces`,
|
|
67
|
+
headers
|
|
68
|
+
}), {
|
|
69
|
+
maxExportBatchSize: batchConfig.maxExportBatchSize,
|
|
70
|
+
scheduledDelayMillis: batchConfig.scheduledDelayMillis,
|
|
71
|
+
exportTimeoutMillis: batchConfig.exportTimeoutMillis,
|
|
72
|
+
maxQueueSize: batchConfig.maxQueueSize
|
|
73
|
+
})],
|
|
74
|
+
metricReader: new PeriodicExportingMetricReader({
|
|
75
|
+
exporter: new OTLPMetricExporter({
|
|
76
|
+
url: `${endpoint}/v1/metrics`,
|
|
77
|
+
headers
|
|
78
|
+
}),
|
|
79
|
+
exportIntervalMillis: 1e4
|
|
80
|
+
}),
|
|
81
|
+
logRecordProcessor: new BatchLogRecordProcessor(new OTLPLogExporter({
|
|
82
|
+
url: `${endpoint}/v1/logs`,
|
|
83
|
+
headers
|
|
84
|
+
}), {
|
|
85
|
+
maxExportBatchSize: batchConfig.maxExportBatchSize,
|
|
86
|
+
scheduledDelayMillis: batchConfig.scheduledDelayMillis,
|
|
87
|
+
exportTimeoutMillis: batchConfig.exportTimeoutMillis,
|
|
88
|
+
maxQueueSize: batchConfig.maxQueueSize
|
|
89
|
+
})
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { MonocleLayer };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface MonocleEffectConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Enable local DevTools mode.
|
|
5
|
+
* Sends telemetry to Monocle DevTools (localhost:4200) with no compression
|
|
6
|
+
* and faster batch delays (100ms). No API key required.
|
|
7
|
+
*/
|
|
8
|
+
dev?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Monocle API key (format: mk_live_xxx or mk_test_xxx).
|
|
11
|
+
* Falls back to the MONOCLE_API_KEY environment variable.
|
|
12
|
+
* When neither is set and dev mode is off, returns an empty layer.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Service name for this application.
|
|
17
|
+
*/
|
|
18
|
+
serviceName: string;
|
|
19
|
+
/**
|
|
20
|
+
* Service version.
|
|
21
|
+
*/
|
|
22
|
+
serviceVersion?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Environment name sent via the x-monocle-env header.
|
|
25
|
+
* Falls back to MONOCLE_ENVIRONMENT, then NODE_ENV, then 'development'.
|
|
26
|
+
*/
|
|
27
|
+
environment?: string;
|
|
28
|
+
/**
|
|
29
|
+
* OTLP endpoint URL.
|
|
30
|
+
* Defaults to 'https://ingest.monocle.sh' (or 'http://localhost:4200' in dev mode).
|
|
31
|
+
*/
|
|
32
|
+
endpoint?: string;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { MonocleEffectConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@monocle.sh/effect-agent",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Monocle observability agent for Effect applications",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"effect",
|
|
7
|
+
"monocle",
|
|
8
|
+
"observability",
|
|
9
|
+
"opentelemetry",
|
|
10
|
+
"tracing"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/monocle-sh/monocle/tree/main/packages/effect-agent",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/monocle-sh/monocle.git",
|
|
18
|
+
"directory": "packages/effect-agent"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.mjs",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"tag": "latest"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@opentelemetry/api": "^1.9.1",
|
|
35
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.214.0",
|
|
36
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.214.0",
|
|
37
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.214.0",
|
|
38
|
+
"@opentelemetry/sdk-logs": "^0.214.0",
|
|
39
|
+
"@opentelemetry/sdk-metrics": "^2.6.1",
|
|
40
|
+
"@opentelemetry/sdk-trace-node": "^2.6.1",
|
|
41
|
+
"@monocle.sh/otel-utils": "1.0.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@adonisjs/tsconfig": "^2.0.0",
|
|
45
|
+
"tsdown": "^0.21.7"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@effect/opentelemetry": ">=0.63.0",
|
|
49
|
+
"effect": ">=3.21.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsdown",
|
|
53
|
+
"dev": "tsdown",
|
|
54
|
+
"typecheck": "tsgo --noEmit"
|
|
55
|
+
}
|
|
56
|
+
}
|