@monocle.sh/effect-agent 0.0.1 → 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,53 @@
1
+ ## Elastic License 2.0 (ELv2)
2
+
3
+ ### Acceptance
4
+
5
+ By using the software, you agree to all of the terms and conditions below.
6
+
7
+ ### Copyright License
8
+
9
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
10
+
11
+ ### Limitations
12
+
13
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
14
+
15
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
16
+
17
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor's trademarks is subject to applicable law.
18
+
19
+ ### Patents
20
+
21
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
22
+
23
+ ### Notices
24
+
25
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
26
+
27
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
28
+
29
+ ### No Other Rights
30
+
31
+ These terms do not imply any licenses other than those expressly granted in these terms.
32
+
33
+ ### Termination
34
+
35
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
36
+
37
+ ### No Liability
38
+
39
+ _As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim._
40
+
41
+ ### Definitions
42
+
43
+ The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it.
44
+
45
+ **You** refers to the individual or entity agreeing to these terms.
46
+
47
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
48
+
49
+ **Your licenses** are all the licenses granted to you for the software under these terms.
50
+
51
+ **Use** means anything you do with the software requiring one of your licenses.
52
+
53
+ **Trademark** means trademarks, service marks, and similar rights.
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { MonocleEffectConfig } from "./src/types.mjs";
1
+ import { MonocleEffectConfig, MonocleUser } from "./src/types.mjs";
2
2
  import { MonocleLayer } from "./src/layer.mjs";
3
+ import { monocle_d_exports } from "./src/monocle.mjs";
3
4
  import { MonocleSpanProcessor } from "./src/index.mjs";
4
- export { MonocleEffectConfig, MonocleLayer, MonocleSpanProcessor };
5
+ export { monocle_d_exports as Monocle, MonocleEffectConfig, MonocleLayer, MonocleSpanProcessor, MonocleUser };
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
1
  import { MonocleLayer } from "./src/layer.mjs";
2
+ import { monocle_exports } from "./src/monocle.mjs";
2
3
  import { MonocleSpanProcessor } from "./src/index.mjs";
3
- export { MonocleLayer, MonocleSpanProcessor };
4
+ export { monocle_exports as Monocle, MonocleLayer, MonocleSpanProcessor };
@@ -1,4 +1,5 @@
1
- import { MonocleEffectConfig } from "./types.mjs";
1
+ import { MonocleEffectConfig, MonocleUser } from "./types.mjs";
2
2
  import { MonocleLayer } from "./layer.mjs";
3
+ import { monocle_d_exports } from "./monocle.mjs";
3
4
  import { MonocleSpanProcessor as MonocleSpanProcessor$1 } from "@monocle.sh/otel-utils";
4
5
  export { MonocleSpanProcessor$1 as MonocleSpanProcessor };
@@ -1,3 +1,4 @@
1
1
  import "./layer.mjs";
2
+ import "./monocle.mjs";
2
3
  import { MonocleSpanProcessor as MonocleSpanProcessor$1 } from "@monocle.sh/otel-utils";
3
4
  export { MonocleSpanProcessor$1 as MonocleSpanProcessor };
@@ -20,6 +20,18 @@ const DEV_BATCH_CONFIG = {
20
20
  ...DEFAULT_BATCH_CONFIG,
21
21
  scheduledDelayMillis: 100
22
22
  };
23
+ function resolveSdkVersion() {
24
+ return "0.1.0";
25
+ }
26
+ function buildNodejsResourceAttributes() {
27
+ const attributes = {
28
+ "monocle.language.name": "javascript",
29
+ "monocle.framework.name": "effect"
30
+ };
31
+ const sdkVersion = resolveSdkVersion();
32
+ if (sdkVersion) attributes["telemetry.sdk.version"] = sdkVersion;
33
+ return attributes;
34
+ }
23
35
  /**
24
36
  * Resolve the Monocle API key from config or MONOCLE_API_KEY env var.
25
37
  * Returns a Redacted value to prevent accidental logging.
@@ -53,6 +65,10 @@ function MonocleLayer(config) {
53
65
  const endpoint = isDev ? config.endpoint || DEV_ENDPOINT : config.endpoint || DEFAULT_ENDPOINT;
54
66
  const environment = resolveEnvironment(config.environment);
55
67
  const batchConfig = isDev ? DEV_BATCH_CONFIG : DEFAULT_BATCH_CONFIG;
68
+ const resourceAttributes = {
69
+ "deployment.environment": environment,
70
+ ...buildNodejsResourceAttributes()
71
+ };
56
72
  const headers = { "x-monocle-env": environment };
57
73
  if (Option.isSome(apiKey)) headers["x-api-key"] = Redacted.value(apiKey.value);
58
74
  const monocleProcessor = new MonocleSpanProcessor();
@@ -60,7 +76,7 @@ function MonocleLayer(config) {
60
76
  resource: {
61
77
  serviceName: config.serviceName,
62
78
  serviceVersion: config.serviceVersion ?? "0.0.0",
63
- attributes: { "deployment.environment": environment }
79
+ attributes: resourceAttributes
64
80
  },
65
81
  spanProcessor: [monocleProcessor, new BatchSpanProcessor(new OTLPTraceExporter({
66
82
  url: `${endpoint}/v1/traces`,
@@ -0,0 +1,17 @@
1
+ import { MonocleUser } from "./types.mjs";
2
+ import * as Effect from "effect/Effect";
3
+
4
+ //#region src/monocle.d.ts
5
+ declare namespace monocle_d_exports {
6
+ export { setUser };
7
+ }
8
+ /**
9
+ * Set user information on the current active span.
10
+ * `name` is displayed with priority over `email` in the Monocle UI.
11
+ * Falls back to `email`, then `id`.
12
+ *
13
+ * No-ops when there is no active span.
14
+ */
15
+ declare const setUser: (user: MonocleUser) => Effect.Effect<void>;
16
+ //#endregion
17
+ export { monocle_d_exports };
@@ -0,0 +1,23 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import * as Effect from "effect/Effect";
3
+ //#region src/monocle.ts
4
+ var monocle_exports = /* @__PURE__ */ __exportAll({ setUser: () => setUser });
5
+ /**
6
+ * Set user information on the current active span.
7
+ * `name` is displayed with priority over `email` in the Monocle UI.
8
+ * Falls back to `email`, then `id`.
9
+ *
10
+ * No-ops when there is no active span.
11
+ */
12
+ const setUser = (user) => Effect.currentSpan.pipe(Effect.andThen((span) => {
13
+ span.attribute("user.id", String(user.id));
14
+ if (user.email) span.attribute("user.email", user.email);
15
+ if (user.name) span.attribute("user.name", user.name);
16
+ for (const [key, value] of Object.entries(user)) {
17
+ if (key === "id" || key === "email" || key === "name") continue;
18
+ if (value === void 0) continue;
19
+ span.attribute(`user.${key}`, value);
20
+ }
21
+ }), Effect.ignore);
22
+ //#endregion
23
+ export { monocle_exports };
@@ -1,4 +1,10 @@
1
1
  //#region src/types.d.ts
2
+ interface MonocleUser {
3
+ id: string | number;
4
+ email?: string;
5
+ name?: string;
6
+ [key: string]: string | number | boolean | string[] | undefined;
7
+ }
2
8
  interface MonocleEffectConfig {
3
9
  /**
4
10
  * Enable local DevTools mode.
@@ -32,4 +38,4 @@ interface MonocleEffectConfig {
32
38
  endpoint?: string;
33
39
  }
34
40
  //#endregion
35
- export { MonocleEffectConfig };
41
+ export { MonocleEffectConfig, MonocleUser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monocle.sh/effect-agent",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Monocle observability agent for Effect applications",
5
5
  "keywords": [
6
6
  "effect",
@@ -9,13 +9,13 @@
9
9
  "opentelemetry",
10
10
  "tracing"
11
11
  ],
12
- "homepage": "https://github.com/monocle-sh/monocle/tree/main/packages/effect-agent",
12
+ "homepage": "https://github.com/monocle-sh/js/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/monocle.git",
18
- "directory": "packages/effect-agent"
17
+ "url": "git+https://github.com/monocle-sh/js.git",
18
+ "directory": "packages/agents/effect"
19
19
  },
20
20
  "files": [
21
21
  "dist"
@@ -38,7 +38,7 @@
38
38
  "@opentelemetry/sdk-logs": "^0.214.0",
39
39
  "@opentelemetry/sdk-metrics": "^2.6.1",
40
40
  "@opentelemetry/sdk-trace-node": "^2.6.1",
41
- "@monocle.sh/otel-utils": "1.0.1"
41
+ "@monocle.sh/otel-utils": "1.1.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@adonisjs/tsconfig": "^2.0.0",
package/LICENSE DELETED
@@ -1,15 +0,0 @@
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.