Skip to content

Commit 8143ebf

Browse files
authored
Merge pull request #16 from JudgmentLabs/ahh/0.3.4
Chore: Node instrumentation reliability
2 parents 329df9b + f4927ca commit 8143ebf

File tree

9 files changed

+34
-14
lines changed

9 files changed

+34
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "judgeval",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "JavaScript/TypeScript client for Judgment evaluation platform",
55
"main": "./dist/index.mjs",
66
"module": "./dist/index.mjs",

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function buildLib() {
4444

4545
async function buildUmd() {
4646
const config: BuildConfig = {
47-
entrypoints: ["./src/umd.ts"],
47+
entrypoints: ["./src/index.ts"],
4848
outdir: "./dist",
4949
target: "browser",
5050
format: "iife",

src/data/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Example as ExampleModel } from "../internal/api/models/Example";
33
export type Example<T extends Record<string, any> = Record<string, any>> =
44
ExampleModel & T;
55

6-
export function createExample<T extends Record<string, any>>(
6+
export function Example<T extends Record<string, any>>(
77
properties: T,
88
): Example<T> {
99
const example: Example<T> = {

src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ export const JUDGMENT_ENABLE_EVALUATIONS = getEnvVar(
2727
"true",
2828
);
2929
export const JUDGMENT_NO_COLOR = getEnvVar("JUDGMENT_NO_COLOR");
30+
export const JUDGMENT_LOG_LEVEL = getEnvVar("JUDGMENT_LOG_LEVEL", "warn");

src/tracer/NodeTracer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { resourceFromAttributes } from "@opentelemetry/resources";
22
import { NodeSDK, NodeSDKConfiguration } from "@opentelemetry/sdk-node";
3-
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
3+
import { Logger } from "../utils/logger";
44
import { VERSION } from "../version";
55
import { OpenTelemetryKeys } from "./OpenTelemetryKeys";
66
import { Tracer, TracerInitializeOptions } from "./Tracer";
77
import { TracerConfiguration } from "./TracerConfiguration";
88

99
export type NodeTracerInitializeOptions = TracerInitializeOptions & {
10-
instrumentations?: NodeSDKConfiguration["instrumentations"];
1110
resourceAttributes?: Record<string, unknown>;
12-
};
11+
} & Partial<NodeSDKConfiguration>;
1312

1413
export class NodeTracer extends Tracer {
1514
private nodeSDK?: NodeSDK;
@@ -34,7 +33,7 @@ export class NodeTracer extends Tracer {
3433
this.nodeSDK = new NodeSDK({
3534
resource: resourceFromAttributes(resourceAttributes),
3635
instrumentations: options.instrumentations,
37-
spanProcessor: new BatchSpanProcessor(spanExporter),
36+
traceExporter: spanExporter,
3837
...options,
3938
});
4039

@@ -72,8 +71,10 @@ export class NodeTracer extends Tracer {
7271
}
7372

7473
public async shutdown(): Promise<void> {
75-
if (this.nodeSDK) {
76-
await this.nodeSDK.shutdown();
74+
if (!this.nodeSDK) {
75+
Logger.warn("Node SDK not initialized, skipping shutdown");
76+
return;
7777
}
78+
await this.nodeSDK.shutdown();
7879
}
7980
}

src/tracer/Tracer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,14 @@ export abstract class Tracer {
383383
OpenTelemetryKeys.AttributeKeys.JUDGMENT_OUTPUT,
384384
this.serializer(res),
385385
);
386-
span.end();
387386
return res;
388387
})
389388
.catch((err) => {
390389
span.recordException(err as Error);
391-
span.end();
392390
throw err;
391+
})
392+
.finally(() => {
393+
span.end();
393394
}) as TResult;
394395
} else {
395396
span.setAttribute(

src/umd.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/utils/logger.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { JUDGMENT_LOG_LEVEL } from "../env";
2+
13
export class Logger {
24
private static readonly RESET = "\x1b[0m";
35
private static readonly RED = "\x1b[31m";
@@ -13,13 +15,27 @@ export class Logger {
1315
} as const;
1416

1517
private static initialized = false;
16-
private static currentLevel: number = Logger.Level.INFO;
18+
private static currentLevel: number = Logger.Level.WARNING;
1719
private static useColor = true;
1820

1921
private static initialize(): void {
2022
if (!Logger.initialized) {
2123
const noColor = process.env.JUDGMENT_NO_COLOR;
2224
Logger.useColor = !noColor && process.stdout.isTTY;
25+
26+
const logLevel = JUDGMENT_LOG_LEVEL.toLowerCase();
27+
if (logLevel) {
28+
const levelMap: Record<string, number> = {
29+
debug: Logger.Level.DEBUG,
30+
info: Logger.Level.INFO,
31+
warning: Logger.Level.WARNING,
32+
warn: Logger.Level.WARNING,
33+
error: Logger.Level.ERROR,
34+
critical: Logger.Level.CRITICAL,
35+
};
36+
Logger.currentLevel = levelMap[logLevel] ?? Logger.Level.WARNING;
37+
}
38+
2339
Logger.initialized = true;
2440
}
2541
}

src/version.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const VERSION = "0.3.3";
1+
import { version } from "../package.json" with { type: "json" };
2+
3+
export const VERSION = version;

0 commit comments

Comments
 (0)