@monocle.sh/effect-agent 0.1.4 → 0.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.
@@ -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 no API key is available and dev mode
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>;
@@ -6,6 +6,7 @@ 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 { parseMonocleDsn } from "@monocle.sh/otel-utils/connection";
9
10
  import { MonocleSpanProcessor } from "@monocle.sh/otel-utils";
10
11
  //#region src/layer.ts
11
12
  const DEFAULT_ENDPOINT = "https://ingest.monocle.sh";
@@ -21,7 +22,7 @@ const DEV_BATCH_CONFIG = {
21
22
  scheduledDelayMillis: 100
22
23
  };
23
24
  function resolveSdkVersion() {
24
- return "0.1.4";
25
+ return "0.2.0";
25
26
  }
26
27
  function buildNodejsResourceAttributes() {
27
28
  const attributes = {
@@ -55,14 +56,16 @@ function resolveEnvironment(configEnv) {
55
56
  * Monocle authentication headers. Includes the MonocleSpanProcessor
56
57
  * for automatic exception enrichment.
57
58
  *
58
- * Returns an empty layer when no API key is available and dev mode
59
+ * Returns an empty layer when neither a DSN nor an API key is available and dev mode
59
60
  * is disabled, making it safe for local development.
60
61
  */
61
62
  function MonocleLayer(config) {
62
63
  const isDev = config.dev;
63
- const apiKey = resolveApiKey(config.apiKey);
64
+ const dsn = config.dsn ?? process.env.MONOCLE_DSN;
65
+ const connection = !isDev && dsn ? parseMonocleDsn(dsn) : void 0;
66
+ const apiKey = resolveApiKey(connection?.apiKey || config.apiKey);
64
67
  if (!isDev && Option.isNone(apiKey)) return Layer.empty;
65
- const endpoint = isDev ? config.endpoint || DEV_ENDPOINT : config.endpoint || DEFAULT_ENDPOINT;
68
+ const endpoint = isDev ? config.endpoint || DEV_ENDPOINT : connection?.endpoint || config.endpoint || DEFAULT_ENDPOINT;
66
69
  const environment = resolveEnvironment(config.environment);
67
70
  const batchConfig = isDev ? DEV_BATCH_CONFIG : DEFAULT_BATCH_CONFIG;
68
71
  const resourceAttributes = {
@@ -70,11 +73,12 @@ function MonocleLayer(config) {
70
73
  ...buildNodejsResourceAttributes()
71
74
  };
72
75
  const headers = { "x-monocle-env": environment };
76
+ if (connection) headers["x-monocle-service-id"] = connection.serviceId;
73
77
  if (Option.isSome(apiKey)) headers["x-api-key"] = Redacted.value(apiKey.value);
74
78
  const monocleProcessor = new MonocleSpanProcessor();
75
79
  return NodeSdk.layer(() => ({
76
80
  resource: {
77
- serviceName: config.serviceName,
81
+ serviceName: config.serviceName ?? "unknown_service",
78
82
  serviceVersion: config.serviceVersion ?? "0.0.0",
79
83
  attributes: resourceAttributes
80
84
  },
@@ -13,15 +13,28 @@ interface MonocleEffectConfig {
13
13
  */
14
14
  dev?: boolean;
15
15
  /**
16
- * Monocle API key (format: mk_live_xxx or mk_test_xxx).
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 this application.
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: string;
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.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Monocle observability agent for Effect applications",
5
5
  "keywords": [
6
6
  "effect",
@@ -9,12 +9,12 @@
9
9
  "opentelemetry",
10
10
  "tracing"
11
11
  ],
12
- "homepage": "https://github.com/monocle-sh/js/tree/main/packages/agents/effect",
12
+ "homepage": "https://github.com/monocle-sh/js-sdk/tree/main/packages/agents/effect",
13
13
  "license": "ISC",
14
14
  "author": "Julien Ripouteau <julien@ripouteau.com>",
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/monocle-sh/js.git",
17
+ "url": "git+https://github.com/monocle-sh/js-sdk.git",
18
18
  "directory": "packages/agents/effect"
19
19
  },
20
20
  "files": [
@@ -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.3.0"
41
+ "@monocle.sh/otel-utils": "1.5.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
  }