@monocle.sh/adonisjs-agent 1.0.0-beta.5 → 1.0.0-beta.6

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 CHANGED
@@ -85,7 +85,7 @@ import { defineConfig } from '@monocle.sh/adonisjs-agent'
85
85
  import env from '#start/env'
86
86
 
87
87
  export default defineConfig({
88
- // Required: Your Monocle API key
88
+ // Optional: Your Monocle API key
89
89
  apiKey: env.get('MONOCLE_API_KEY'),
90
90
 
91
91
  // Optional: Custom ingestion endpoint (for development)
@@ -123,7 +123,7 @@ export default defineConfig({
123
123
 
124
124
  | Variable | Description | Required |
125
125
  | ----------------- | ------------------------------------------------------ | -------- |
126
- | `MONOCLE_API_KEY` | Your Monocle API key | Yes |
126
+ | `MONOCLE_API_KEY` | Your Monocle API key | No |
127
127
  | `APP_NAME` | Service name for identification | Yes |
128
128
  | `APP_VERSION` | Service version (e.g., git sha, semver) | Yes |
129
129
  | `APP_ENV` | Environment: `development`, `staging`, or `production` | Yes |
@@ -53,7 +53,7 @@ async function configure(command) {
53
53
  APP_NAME: "Env.schema.string()",
54
54
  APP_VERSION: "Env.schema.string()",
55
55
  APP_ENV: `Env.schema.enum(['development', 'staging', 'production'] as const)`,
56
- MONOCLE_API_KEY: "Env.schema.string()"
56
+ MONOCLE_API_KEY: "Env.schema.string.optional()"
57
57
  } });
58
58
  }
59
59
 
package/dist/init.mjs CHANGED
@@ -69,9 +69,7 @@ async function init(dirname$1) {
69
69
  const manager = OtelManager.create(configWithProcessors);
70
70
  manager?.start();
71
71
  const shutdown = async () => {
72
- await manager?.shutdown().catch(() => {
73
- console.error("Error during OTEL shutdown");
74
- });
72
+ await manager?.shutdown().catch(() => {});
75
73
  };
76
74
  process.on("beforeExit", shutdown);
77
75
  process.on("SIGINT", async () => {
@@ -1,5 +1,6 @@
1
1
  import { recordExceptionWithContext } from "./src/context_lines.mjs";
2
2
  import { getCurrentSpan } from "@adonisjs/otel/helpers";
3
+ import is from "@sindresorhus/is";
3
4
  import OtelMiddleware from "@adonisjs/otel/otel_middleware";
4
5
  import { OtelManager } from "@adonisjs/otel";
5
6
  import { ExceptionHandler } from "@adonisjs/core/http";
@@ -15,6 +16,15 @@ var OtelProvider = class {
15
16
  this.app = app;
16
17
  }
17
18
  /**
19
+ * Convert any error to an HttpError-like object
20
+ */
21
+ #toHttpError(error) {
22
+ const httpError = is.object(error) ? error : new Error(String(error));
23
+ if (!httpError.message) httpError.message = "Internal server error";
24
+ if (!httpError.status) httpError.status = 500;
25
+ return httpError;
26
+ }
27
+ /**
18
28
  * Hook into ExceptionHandler to record exceptions in spans.
19
29
  *
20
30
  * We always record the exception on the span (for trace visibility), but we also
@@ -26,14 +36,16 @@ var OtelProvider = class {
26
36
  */
27
37
  #registerExceptionHandler() {
28
38
  const originalReport = ExceptionHandler.prototype.report;
39
+ const toHttpError = this.#toHttpError;
29
40
  ExceptionHandler.macro("report", async function(error, ctx) {
30
41
  const span = getCurrentSpan();
31
- if (span && error instanceof Error) {
32
- const httpError = this.toHttpError(error);
42
+ if (span) {
43
+ const httpError = toHttpError(error);
44
+ const shouldReport = this.shouldReport(httpError);
33
45
  await recordExceptionWithContext({
34
46
  span,
35
- error,
36
- shouldReport: this.shouldReport(httpError)
47
+ error: is.error(error) ? error : new Error(String(error)),
48
+ shouldReport
37
49
  });
38
50
  }
39
51
  return originalReport.call(this, error, ctx);
@@ -283,7 +283,8 @@ async function recordExceptionWithContext(options) {
283
283
  "exception.message": error.message,
284
284
  "exception.stacktrace": hasCauses ? stackWithCauses(error) : error.stack || ""
285
285
  };
286
- if (causeChain.length > 0) attributes["monocle.exception.cause_chain"] = JSON.stringify(causeChain);
286
+ const actualCauses = causeChain.slice(1);
287
+ if (actualCauses.length > 0) attributes["monocle.exception.cause_chain"] = JSON.stringify(actualCauses);
287
288
  const mainFrames = causeChain[0]?.frames;
288
289
  if (mainFrames && mainFrames.length > 0) attributes["monocle.exception.frames"] = JSON.stringify(mainFrames);
289
290
  span.addEvent("exception", attributes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monocle.sh/adonisjs-agent",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "Monocle agent for AdonisJS - sends telemetry to Monocle cloud",
5
5
  "keywords": [
6
6
  "adonisjs",
@@ -67,6 +67,7 @@
67
67
  "@opentelemetry/sdk-metrics": "^2.2.0",
68
68
  "@opentelemetry/sdk-trace-base": "^2.2.0",
69
69
  "@opentelemetry/semantic-conventions": "^1.38.0",
70
+ "@sindresorhus/is": "^7.2.0",
70
71
  "error-stack-parser-es": "^1.0.5",
71
72
  "import-in-the-middle": "^2.0.1"
72
73
  },