@elysiumjs/argus 0.2.0 → 0.2.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @elysiumjs/argus
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`04773f2`](https://github.com/na2axl/elysiumjs/commit/04773f2acd4ab1c762a80ee903715d90f1c08e21) Thanks [@na2axl](https://github.com/na2axl)! - Ship the type declarations. The packages pointed `types` at `dist/index.d.ts` but their build never wrote it, so TypeScript projects got no types for them.
8
+ - Updated dependencies [[`04773f2`](https://github.com/na2axl/elysiumjs/commit/04773f2acd4ab1c762a80ee903715d90f1c08e21)]:
9
+ - @elysiumjs/hermes@0.4.3
10
+
11
+ ## 0.2.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`68a0cdd`](https://github.com/na2axl/elysiumjs/commit/68a0cdd8b2e4a003d6e0af2d78985623cae40428), [`2c49acd`](https://github.com/na2axl/elysiumjs/commit/2c49acd3b552aa43765d70339fa216961499e1b5), [`76ba0ff`](https://github.com/na2axl/elysiumjs/commit/76ba0ff18f3c196cebc2189426328f67cb699f46), [`4ebf029`](https://github.com/na2axl/elysiumjs/commit/4ebf029611e6d753a4f1bfdbe247a75d954d9ded), [`bacce71`](https://github.com/na2axl/elysiumjs/commit/bacce7146f667a1a46bf474dc0344fb0111ae12a)]:
16
+ - @elysiumjs/core@0.10.0
17
+ - @elysiumjs/hermes@0.4.2
18
+
19
+ ## 0.2.1
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [[`5fef4a7`](https://github.com/na2axl/elysiumjs/commit/5fef4a7199f502fc4fe035299e7670739459a108)]:
24
+ - @elysiumjs/core@0.9.0
25
+ - @elysiumjs/hermes@0.4.1
26
+
3
27
  ## 0.2.0
4
28
 
5
29
  ### Minor Changes
@@ -0,0 +1,34 @@
1
+ import type { TracingConfig } from './types';
2
+ import { Module } from '@elysiumjs/core';
3
+ declare const ArgusModule_base: (abstract new () => {
4
+ readonly config: TracingConfig;
5
+ onInit(): Promise<void> | void;
6
+ onDestroy(): Promise<void> | void;
7
+ onServe(_app: import("elysia").default<any>): Promise<void> | void;
8
+ }) & {
9
+ readonly config: string;
10
+ with(config: Partial<TracingConfig> | (() => Partial<TracingConfig> | Promise<Partial<TracingConfig>>)): import("@elysiumjs/core").ConfiguredModule<TracingConfig>;
11
+ resolveConfig(input?: Partial<TracingConfig> | undefined): TracingConfig;
12
+ register<TConfig_1 = any>(props?: import("@elysiumjs/core").ModuleProps<TConfig_1>): (target: import("@elysiumjs/core").ModuleClass) => void;
13
+ configurable<TConfig extends object>(options?: {
14
+ defaults?: Partial<TConfig>;
15
+ required?: (keyof TConfig)[];
16
+ }): any;
17
+ };
18
+ /**
19
+ * Configurable module that starts the {@link ArgusSDK} on init, installs the request-span
20
+ * plugin on the root app when serving, and shuts the SDK down on destroy.
21
+ *
22
+ * If the SDK was already initialised (e.g. by a preload), the module leaves it running and
23
+ * does not shut it down.
24
+ *
25
+ * `serviceName` has no sensible default and is required.
26
+ * @author Axel Nana <axel.nana@workbud.com>
27
+ */
28
+ export declare class ArgusModule extends ArgusModule_base {
29
+ #private;
30
+ onInit(): void;
31
+ onServe(app: Parameters<Module['onServe']>[0]): void;
32
+ onDestroy(): Promise<void>;
33
+ }
34
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Enriches a log context object with `traceId` and `spanId` from the
3
+ * active OpenTelemetry span.
4
+ *
5
+ * Use this in Hermes log calls to correlate logs with traces:
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { withTraceContext } from '@elysiumjs/argus';
10
+ *
11
+ * logger.info('Processing request', withTraceContext({ userId: '123' }));
12
+ * // Output: { msg: "Processing request", userId: "123", traceId: "abc...", spanId: "def..." }
13
+ * ```
14
+ *
15
+ * @author Axel Nana <axel.nana@workbud.com>
16
+ * @param ctx The base context to enrich.
17
+ * @returns The context with `traceId` and `spanId` injected if an active span exists.
18
+ */
19
+ export declare function withTraceContext(ctx?: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,23 @@
1
+ import type { SpanOptions } from '@opentelemetry/api';
2
+ /**
3
+ * Decorator that wraps a method in an OpenTelemetry span.
4
+ *
5
+ * Creates a child span for each method invocation, recording success
6
+ * or error status. Exceptions are recorded on the span before re-throwing.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * class UserService {
11
+ * @Traced('user.findById')
12
+ * async findById(id: string) {
13
+ * return db.query('SELECT * FROM users WHERE id = $1', [id]);
14
+ * }
15
+ * }
16
+ * ```
17
+ *
18
+ * @author Axel Nana <axel.nana@workbud.com>
19
+ * @param name Optional span name. Defaults to `ClassName.methodName`.
20
+ * @param options Optional OpenTelemetry span options.
21
+ * @returns A method decorator.
22
+ */
23
+ export declare function Traced(name?: string, options?: SpanOptions): MethodDecorator;
@@ -0,0 +1,6 @@
1
+ export type { TracingConfig } from './types';
2
+ export { ArgusSDK } from './sdk';
3
+ export { Traced } from './decorators/traced';
4
+ export { withTraceContext } from './correlation';
5
+ export { argusPlugin } from './plugin';
6
+ export { ArgusModule } from './argus.module';
@@ -0,0 +1,40 @@
1
+ import { Elysia } from 'elysia';
2
+ /**
3
+ * Elysia plugin that creates OpenTelemetry request spans.
4
+ *
5
+ * Each HTTP request gets a span with method, path, and status information.
6
+ * Errors (5xx) are recorded as error spans.
7
+ *
8
+ * @author Axel Nana <axel.nana@workbud.com>
9
+ * @returns An Elysia plugin instance.
10
+ */
11
+ export declare const argusPlugin: () => Elysia<"", {
12
+ decorator: {};
13
+ store: {};
14
+ derive: {};
15
+ resolve: {};
16
+ }, {
17
+ typebox: {};
18
+ error: {};
19
+ }, {
20
+ schema: {};
21
+ standaloneSchema: {};
22
+ macro: {};
23
+ macroFn: {};
24
+ parser: {};
25
+ response: {};
26
+ }, {}, {
27
+ derive: {};
28
+ resolve: {};
29
+ schema: {};
30
+ standaloneSchema: {};
31
+ response: {};
32
+ }, {
33
+ derive: {
34
+ readonly __argusSpan: import("@opentelemetry/api").Span;
35
+ };
36
+ resolve: {};
37
+ schema: {};
38
+ standaloneSchema: {};
39
+ response: {};
40
+ }>;
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { TracingConfig } from './types';
2
+ /**
3
+ * ArgusSDK initializes OpenTelemetry for the Elysium framework.
4
+ *
5
+ * CRITICAL: For full auto-instrumentation this MUST be called before any
6
+ * application code runs (e.g. from a `--preload` file). Auto-instrumentation
7
+ * patches modules at import time; modules imported before OTel is initialized
8
+ * won't be instrumented. `ArgusModule` initialises the SDK in `onInit`, which
9
+ * only covers modules loaded afterwards; when the SDK was already initialised
10
+ * (e.g. by a preload), the module detects it with {@link ArgusSDK.isInitialized}
11
+ * and leaves it alone.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // src/instrument.ts (loaded FIRST via --preload or entrypoint)
16
+ * import { ArgusSDK } from '@elysiumjs/argus';
17
+ *
18
+ * ArgusSDK.initialize({
19
+ * enabled: true,
20
+ * serviceName: 'my-api',
21
+ * exporter: 'otlp-http',
22
+ * endpoint: 'http://localhost:4318/v1/traces'
23
+ * });
24
+ * ```
25
+ *
26
+ * @author Axel Nana <axel.nana@workbud.com>
27
+ */
28
+ export declare class ArgusSDK {
29
+ private static instance;
30
+ private sdk;
31
+ private constructor();
32
+ /**
33
+ * Whether {@link ArgusSDK.initialize} has already been called.
34
+ * @author Axel Nana <axel.nana@workbud.com>
35
+ */
36
+ static isInitialized(): boolean;
37
+ /**
38
+ * Initializes the OpenTelemetry SDK.
39
+ * Can only be called once — subsequent calls are ignored with a warning.
40
+ * @author Axel Nana <axel.nana@workbud.com>
41
+ * @param config The tracing configuration.
42
+ */
43
+ static initialize(config: TracingConfig): void;
44
+ /**
45
+ * Creates the appropriate trace exporter based on the config.
46
+ * @author Axel Nana <axel.nana@workbud.com>
47
+ * @param config The tracing configuration.
48
+ * @returns A span exporter instance.
49
+ */
50
+ private static createExporter;
51
+ /**
52
+ * Shuts down the OpenTelemetry SDK gracefully.
53
+ * @author Axel Nana <axel.nana@workbud.com>
54
+ */
55
+ static shutdown(): Promise<void>;
56
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Configuration for the Argus telemetry SDK.
3
+ * @author Axel Nana <axel.nana@workbud.com>
4
+ */
5
+ export interface TracingConfig {
6
+ /**
7
+ * Whether tracing is enabled.
8
+ */
9
+ enabled: boolean;
10
+ /**
11
+ * The service name reported in spans.
12
+ */
13
+ serviceName: string;
14
+ /**
15
+ * The exporter to use. Only `otlp-http` and `console` are supported.
16
+ * gRPC is not supported on Bun.
17
+ */
18
+ exporter: 'otlp-http' | 'console';
19
+ /**
20
+ * The OTLP endpoint URL.
21
+ * @default 'http://localhost:4318/v1/traces'
22
+ */
23
+ endpoint?: string;
24
+ /**
25
+ * Sampling rate between 0.0 and 1.0.
26
+ * @default 1.0
27
+ */
28
+ samplingRate?: number;
29
+ }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@elysiumjs/argus",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "license": "Apache-2.0",
5
5
  "description": "OpenTelemetry telemetry package for the Elysium.js framework.",
6
6
  "private": false,
7
7
  "author": "Workbud Technologies Inc.",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/workbud/elysium"
10
+ "url": "git+https://github.com/na2axl/elysiumjs.git",
11
+ "directory": "@elysiumjs/argus"
11
12
  },
12
13
  "keywords": [
13
14
  "elysium",
@@ -19,11 +20,18 @@
19
20
  "typescript",
20
21
  "bun"
21
22
  ],
22
- "homepage": "https://github.com/workbud/elysium",
23
- "module": "index.ts",
23
+ "homepage": "https://github.com/na2axl/elysiumjs/tree/main/@elysiumjs/argus#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/na2axl/elysiumjs/issues"
26
+ },
27
+ "module": "dist/index.js",
24
28
  "type": "module",
25
29
  "main": "dist/index.js",
26
30
  "types": "dist/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "CHANGELOG.md"
34
+ ],
27
35
  "sideEffects": false,
28
36
  "scripts": {
29
37
  "format": "prettier --write \"./src/**/*.ts\"",
@@ -45,12 +53,12 @@
45
53
  "@opentelemetry/semantic-conventions": "^1.43.0"
46
54
  },
47
55
  "devDependencies": {
48
- "@elysiumjs/core": "0.8.0",
49
- "@elysiumjs/hermes": "0.4.0"
56
+ "@elysiumjs/core": "0.10.0",
57
+ "@elysiumjs/hermes": "0.4.3"
50
58
  },
51
59
  "peerDependencies": {
52
- "@elysiumjs/core": "^0.8.0",
53
- "@elysiumjs/hermes": "^0.4.0"
60
+ "@elysiumjs/core": "^0.10.0",
61
+ "@elysiumjs/hermes": "^0.4.3"
54
62
  },
55
63
  "peerDependenciesMeta": {
56
64
  "@elysiumjs/hermes": {
@@ -1,8 +0,0 @@
1
- $ bun run clean && bun run build:js && bun run build:ts
2
- $ rimraf dist
3
- $ bun build ./src/index.ts --outdir ./dist --target bun -e @elysiumjs/* -e @opentelemetry/* --root ./src --minify-syntax --minify-whitespace
4
- Bundled 327 modules in 60ms
5
-
6
- index.js 0.56 MB (entry point)
7
-
8
- $ tsc
package/index.ts DELETED
@@ -1,15 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export * from './src/index';
@@ -1,55 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import type { TracingConfig } from './types';
16
-
17
- import { Module } from '@elysiumjs/core';
18
-
19
- import { argusPlugin } from './plugin';
20
- import { ArgusSDK } from './sdk';
21
-
22
- /**
23
- * Configurable module that starts the {@link ArgusSDK} on init, installs the request-span
24
- * plugin on the root app when serving, and shuts the SDK down on destroy.
25
- *
26
- * If the SDK was already initialised (e.g. by a preload), the module leaves it running and
27
- * does not shut it down.
28
- *
29
- * `serviceName` has no sensible default and is required.
30
- * @author Axel Nana <axel.nana@workbud.com>
31
- */
32
- @Module.register({})
33
- export class ArgusModule extends Module.configurable<TracingConfig>({
34
- defaults: { enabled: true, exporter: 'console' },
35
- required: ['serviceName']
36
- }) {
37
- #started = false;
38
-
39
- public override onInit(): void {
40
- // A preload (or anything else) already owns the SDK: leave it alone.
41
- if (ArgusSDK.isInitialized()) return;
42
- ArgusSDK.initialize(this.config);
43
- this.#started = true;
44
- }
45
-
46
- public override onServe(app: Parameters<Module['onServe']>[0]): void {
47
- app.use(argusPlugin());
48
- }
49
-
50
- public override async onDestroy(): Promise<void> {
51
- if (!this.#started) return;
52
- this.#started = false;
53
- await ArgusSDK.shutdown();
54
- }
55
- }
@@ -1,45 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { trace } from '@opentelemetry/api';
16
-
17
- /**
18
- * Enriches a log context object with `traceId` and `spanId` from the
19
- * active OpenTelemetry span.
20
- *
21
- * Use this in Hermes log calls to correlate logs with traces:
22
- *
23
- * @example
24
- * ```typescript
25
- * import { withTraceContext } from '@elysiumjs/argus';
26
- *
27
- * logger.info('Processing request', withTraceContext({ userId: '123' }));
28
- * // Output: { msg: "Processing request", userId: "123", traceId: "abc...", spanId: "def..." }
29
- * ```
30
- *
31
- * @author Axel Nana <axel.nana@workbud.com>
32
- * @param ctx The base context to enrich.
33
- * @returns The context with `traceId` and `spanId` injected if an active span exists.
34
- */
35
- export function withTraceContext(ctx: Record<string, unknown> = {}): Record<string, unknown> {
36
- const span = trace.getActiveSpan();
37
- if (!span) return ctx;
38
-
39
- const spanCtx = span.spanContext();
40
- return {
41
- ...ctx,
42
- traceId: spanCtx.traceId,
43
- spanId: spanCtx.spanId
44
- };
45
- }
@@ -1,72 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import type { SpanOptions } from '@opentelemetry/api';
16
-
17
- import { SpanStatusCode, trace } from '@opentelemetry/api';
18
-
19
- /**
20
- * Decorator that wraps a method in an OpenTelemetry span.
21
- *
22
- * Creates a child span for each method invocation, recording success
23
- * or error status. Exceptions are recorded on the span before re-throwing.
24
- *
25
- * @example
26
- * ```typescript
27
- * class UserService {
28
- * @Traced('user.findById')
29
- * async findById(id: string) {
30
- * return db.query('SELECT * FROM users WHERE id = $1', [id]);
31
- * }
32
- * }
33
- * ```
34
- *
35
- * @author Axel Nana <axel.nana@workbud.com>
36
- * @param name Optional span name. Defaults to `ClassName.methodName`.
37
- * @param options Optional OpenTelemetry span options.
38
- * @returns A method decorator.
39
- */
40
- export function Traced(name?: string, options?: SpanOptions): MethodDecorator {
41
- return function (
42
- target: object,
43
- propertyKey: string | symbol,
44
- descriptor: TypedPropertyDescriptor<any>
45
- ) {
46
- const original = descriptor.value;
47
- const spanName = name ?? `${target.constructor.name}.${String(propertyKey)}`;
48
-
49
- descriptor.value = async function (...args: any[]) {
50
- const tracer = trace.getTracer('@elysiumjs/argus');
51
-
52
- return tracer.startActiveSpan(spanName, options ?? {}, async (span) => {
53
- try {
54
- const result = await original.apply(this, args);
55
- span.setStatus({ code: SpanStatusCode.OK });
56
- return result;
57
- } catch (error) {
58
- span.setStatus({
59
- code: SpanStatusCode.ERROR,
60
- message: error instanceof Error ? error.message : 'Unknown error'
61
- });
62
- span.recordException(error as Error);
63
- throw error;
64
- } finally {
65
- span.end();
66
- }
67
- });
68
- };
69
-
70
- return descriptor;
71
- };
72
- }
package/src/index.ts DELETED
@@ -1,21 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export type { TracingConfig } from './types';
16
-
17
- export { ArgusSDK } from './sdk';
18
- export { Traced } from './decorators/traced';
19
- export { withTraceContext } from './correlation';
20
- export { argusPlugin } from './plugin';
21
- export { ArgusModule } from './argus.module';
package/src/plugin.ts DELETED
@@ -1,62 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { SpanStatusCode, trace } from '@opentelemetry/api';
16
- import { Elysia } from 'elysia';
17
-
18
- /**
19
- * Elysia plugin that creates OpenTelemetry request spans.
20
- *
21
- * Each HTTP request gets a span with method, path, and status information.
22
- * Errors (5xx) are recorded as error spans.
23
- *
24
- * @author Axel Nana <axel.nana@workbud.com>
25
- * @returns An Elysia plugin instance.
26
- */
27
- export const argusPlugin = () => {
28
- const tracer = trace.getTracer('@elysiumjs/argus');
29
-
30
- return new Elysia({ name: '@elysiumjs/argus' })
31
- .derive(({ request }) => {
32
- const url = new URL(request.url);
33
- const span = tracer.startSpan(`${request.method} ${url.pathname}`, {
34
- attributes: {
35
- 'http.method': request.method,
36
- 'http.url': request.url,
37
- 'http.target': url.pathname
38
- }
39
- });
40
-
41
- return { __argusSpan: span };
42
- })
43
- .onAfterResponse(({ __argusSpan, request }) => {
44
- if (__argusSpan) {
45
- __argusSpan.setStatus({ code: SpanStatusCode.OK });
46
- __argusSpan.setAttribute('http.method', request.method);
47
- __argusSpan.end();
48
- }
49
- })
50
- .onError(({ __argusSpan, error }) => {
51
- if (__argusSpan) {
52
- __argusSpan.setStatus({
53
- code: SpanStatusCode.ERROR,
54
- message: error instanceof Error ? error.message : 'Unknown error'
55
- });
56
- if (error instanceof Error) {
57
- __argusSpan.recordException(error);
58
- }
59
- __argusSpan.end();
60
- }
61
- });
62
- };