@monocle.sh/effect-agent 0.1.5 → 0.3.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/src/layer.d.mts +1 -1
- package/dist/src/layer.mjs +17 -10
- package/dist/src/types.d.mts +17 -4
- package/package.json +4 -3
package/dist/src/layer.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ import { Layer } from "effect";
|
|
|
10
10
|
* Monocle authentication headers. Includes the MonocleSpanProcessor
|
|
11
11
|
* for automatic exception enrichment.
|
|
12
12
|
*
|
|
13
|
-
* Returns an empty layer when
|
|
13
|
+
* Returns an empty layer when neither a DSN nor an API key is available and dev mode
|
|
14
14
|
* is disabled, making it safe for local development.
|
|
15
15
|
*/
|
|
16
16
|
declare function MonocleLayer(config: MonocleEffectConfig): Layer.Layer<Resource.Resource>;
|
package/dist/src/layer.mjs
CHANGED
|
@@ -6,7 +6,8 @@ import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
|
6
6
|
import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
7
7
|
import { NodeSdk } from "@effect/opentelemetry";
|
|
8
8
|
import { Layer, Option, Redacted } from "effect";
|
|
9
|
-
import {
|
|
9
|
+
import { parseMonocleDsn } from "@monocle.sh/otel-utils/connection";
|
|
10
|
+
import { MonocleSpanProcessor, buildNodejsMonocleResourceAttributes } from "@monocle.sh/otel-utils";
|
|
10
11
|
//#region src/layer.ts
|
|
11
12
|
const DEFAULT_ENDPOINT = "https://ingest.monocle.sh";
|
|
12
13
|
const DEV_ENDPOINT = "http://localhost:4200";
|
|
@@ -21,14 +22,17 @@ const DEV_BATCH_CONFIG = {
|
|
|
21
22
|
scheduledDelayMillis: 100
|
|
22
23
|
};
|
|
23
24
|
function resolveSdkVersion() {
|
|
24
|
-
return "0.
|
|
25
|
+
return "0.3.0";
|
|
25
26
|
}
|
|
26
27
|
function buildNodejsResourceAttributes() {
|
|
27
|
-
const attributes = {
|
|
28
|
-
"monocle.language.name": "javascript",
|
|
29
|
-
"monocle.framework.name": "effect"
|
|
30
|
-
};
|
|
31
28
|
const sdkVersion = resolveSdkVersion();
|
|
29
|
+
const attributes = buildNodejsMonocleResourceAttributes({
|
|
30
|
+
framework: { name: "effect" },
|
|
31
|
+
sdk: {
|
|
32
|
+
name: "@monocle.sh/effect-agent",
|
|
33
|
+
version: sdkVersion
|
|
34
|
+
}
|
|
35
|
+
});
|
|
32
36
|
if (sdkVersion) attributes["telemetry.sdk.version"] = sdkVersion;
|
|
33
37
|
return attributes;
|
|
34
38
|
}
|
|
@@ -55,14 +59,16 @@ function resolveEnvironment(configEnv) {
|
|
|
55
59
|
* Monocle authentication headers. Includes the MonocleSpanProcessor
|
|
56
60
|
* for automatic exception enrichment.
|
|
57
61
|
*
|
|
58
|
-
* Returns an empty layer when
|
|
62
|
+
* Returns an empty layer when neither a DSN nor an API key is available and dev mode
|
|
59
63
|
* is disabled, making it safe for local development.
|
|
60
64
|
*/
|
|
61
65
|
function MonocleLayer(config) {
|
|
62
66
|
const isDev = config.dev;
|
|
63
|
-
const
|
|
67
|
+
const dsn = config.dsn ?? process.env.MONOCLE_DSN;
|
|
68
|
+
const connection = !isDev && dsn ? parseMonocleDsn(dsn) : void 0;
|
|
69
|
+
const apiKey = resolveApiKey(connection?.apiKey || config.apiKey);
|
|
64
70
|
if (!isDev && Option.isNone(apiKey)) return Layer.empty;
|
|
65
|
-
const endpoint = isDev ? config.endpoint || DEV_ENDPOINT : config.endpoint || DEFAULT_ENDPOINT;
|
|
71
|
+
const endpoint = isDev ? config.endpoint || DEV_ENDPOINT : connection?.endpoint || config.endpoint || DEFAULT_ENDPOINT;
|
|
66
72
|
const environment = resolveEnvironment(config.environment);
|
|
67
73
|
const batchConfig = isDev ? DEV_BATCH_CONFIG : DEFAULT_BATCH_CONFIG;
|
|
68
74
|
const resourceAttributes = {
|
|
@@ -70,11 +76,12 @@ function MonocleLayer(config) {
|
|
|
70
76
|
...buildNodejsResourceAttributes()
|
|
71
77
|
};
|
|
72
78
|
const headers = { "x-monocle-env": environment };
|
|
79
|
+
if (connection) headers["x-monocle-service-id"] = connection.serviceId;
|
|
73
80
|
if (Option.isSome(apiKey)) headers["x-api-key"] = Redacted.value(apiKey.value);
|
|
74
81
|
const monocleProcessor = new MonocleSpanProcessor();
|
|
75
82
|
return NodeSdk.layer(() => ({
|
|
76
83
|
resource: {
|
|
77
|
-
serviceName: config.serviceName,
|
|
84
|
+
serviceName: config.serviceName ?? "unknown_service",
|
|
78
85
|
serviceVersion: config.serviceVersion ?? "0.0.0",
|
|
79
86
|
attributes: resourceAttributes
|
|
80
87
|
},
|
package/dist/src/types.d.mts
CHANGED
|
@@ -13,15 +13,28 @@ interface MonocleEffectConfig {
|
|
|
13
13
|
*/
|
|
14
14
|
dev?: boolean;
|
|
15
15
|
/**
|
|
16
|
-
* Monocle API key
|
|
16
|
+
* Monocle API key for legacy connections. Prefer dsn or MONOCLE_DSN.
|
|
17
|
+
* Format: mk_live_xxx or mk_test_xxx.
|
|
17
18
|
* Falls back to the MONOCLE_API_KEY environment variable.
|
|
18
|
-
* When neither is set and dev mode is off, returns an empty layer.
|
|
19
|
+
* When neither a DSN nor an API key is set and dev mode is off, returns an empty layer.
|
|
20
|
+
* @deprecated Use dsn or MONOCLE_DSN copied from your service's connection settings.
|
|
21
|
+
* Existing API key configurations remain supported; no key rotation is required.
|
|
19
22
|
*/
|
|
20
23
|
apiKey?: string;
|
|
21
24
|
/**
|
|
22
|
-
* Service name for
|
|
25
|
+
* Service name for legacy connections and local Studio.
|
|
26
|
+
* Existing API key and serviceName configurations remain supported.
|
|
27
|
+
* @deprecated For Monocle Cloud, use dsn or MONOCLE_DSN copied from your service's
|
|
28
|
+
* connection settings. The collector resolves the service name from the DSN.
|
|
29
|
+
* Keep this option when naming services in Studio.
|
|
23
30
|
*/
|
|
24
|
-
serviceName
|
|
31
|
+
serviceName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Service connection copied from Monocle. No serviceName is needed.
|
|
34
|
+
* Takes precedence over apiKey and endpoint.
|
|
35
|
+
* Falls back to MONOCLE_DSN. Ignored in Studio mode.
|
|
36
|
+
*/
|
|
37
|
+
dsn?: string;
|
|
25
38
|
/**
|
|
26
39
|
* Service version.
|
|
27
40
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monocle.sh/effect-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Monocle observability agent for Effect applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@opentelemetry/sdk-logs": "^0.216.0",
|
|
39
39
|
"@opentelemetry/sdk-metrics": "^2.7.1",
|
|
40
40
|
"@opentelemetry/sdk-trace-node": "^2.7.1",
|
|
41
|
-
"@monocle.sh/otel-utils": "1.
|
|
41
|
+
"@monocle.sh/otel-utils": "1.6.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@adonisjs/tsconfig": "^2.0.0",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsdown",
|
|
53
53
|
"dev": "tsdown",
|
|
54
|
-
"typecheck": "tsgo --noEmit"
|
|
54
|
+
"typecheck": "tsgo --noEmit",
|
|
55
|
+
"test": "node --conditions=dev --experimental-transform-types --test tests/*.test.mjs"
|
|
55
56
|
}
|
|
56
57
|
}
|