@opencode-ai/util 0.0.0-next-17081 → 0.0.0-next-17084
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Layer } from "effect";
|
|
1
|
+
import { Effect, Layer, Scope } from "effect";
|
|
2
2
|
export interface Options {
|
|
3
3
|
readonly endpoint?: string;
|
|
4
4
|
readonly headers?: string;
|
|
@@ -13,6 +13,6 @@ export declare function resource(app?: App): {
|
|
|
13
13
|
serviceVersion: string;
|
|
14
14
|
attributes: Record<string, string>;
|
|
15
15
|
};
|
|
16
|
-
export declare function loggers(options: Options | undefined, app: App):
|
|
17
|
-
export declare
|
|
16
|
+
export declare function loggers(options: Options | undefined, app: App): Effect.Effect<import("effect/Logger").Logger<unknown, void>, never, import("effect/unstable/http/HttpClient").HttpClient | Scope.Scope | import("effect/unstable/observability/OtlpSerialization").OtlpSerialization>[];
|
|
17
|
+
export declare const tracingLayer: (options: Options | undefined, app: App) => Effect.Effect<Layer.Layer<never, never, never>, never, never>;
|
|
18
18
|
export * as Otlp from "./otlp.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Layer } from "effect";
|
|
1
|
+
import { Effect, Layer, Scope } from "effect";
|
|
2
2
|
import { OtlpLogger } from "effect/unstable/observability";
|
|
3
3
|
import { runID } from "./shared.js";
|
|
4
4
|
function parseHeaders(value) {
|
|
@@ -50,24 +50,27 @@ export function loggers(options, app) {
|
|
|
50
50
|
}),
|
|
51
51
|
];
|
|
52
52
|
}
|
|
53
|
-
export
|
|
53
|
+
export const tracingLayer = Effect.fnUntraced(function* (options, app) {
|
|
54
54
|
if (!options?.endpoint)
|
|
55
55
|
return Layer.empty;
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const [{ layer }, { OTLPTraceExporter }, { BatchSpanProcessor }, { AsyncLocalStorageContextManager }, { context }] = yield* Effect.all([
|
|
57
|
+
Effect.promise(() => import("@effect/opentelemetry/NodeSdk")),
|
|
58
|
+
Effect.promise(() => import("@opentelemetry/exporter-trace-otlp-http")),
|
|
59
|
+
Effect.promise(() => import("@opentelemetry/sdk-trace-base")),
|
|
60
|
+
Effect.promise(() => import("@opentelemetry/context-async-hooks")),
|
|
61
|
+
Effect.promise(() => import("@opentelemetry/api")),
|
|
62
|
+
], { concurrency: "unbounded" });
|
|
61
63
|
// The Effect Node SDK does not register a global context manager, but the AI SDK uses it to parent spans.
|
|
62
64
|
const manager = new AsyncLocalStorageContextManager();
|
|
63
65
|
manager.enable();
|
|
64
66
|
context.setGlobalContextManager(manager);
|
|
65
|
-
|
|
67
|
+
const tracing = layer(() => ({
|
|
66
68
|
resource: resource(app),
|
|
67
|
-
spanProcessor: new
|
|
69
|
+
spanProcessor: new BatchSpanProcessor(new OTLPTraceExporter({
|
|
68
70
|
url: `${options.endpoint}/v1/traces`,
|
|
69
71
|
headers: parseHeaders(options.headers),
|
|
70
72
|
})),
|
|
71
73
|
}));
|
|
72
|
-
|
|
74
|
+
return Layer.effectContext(Effect.acquireRelease(Scope.make(), (scope, exit) => Scope.close(scope, exit).pipe(Effect.ignoreCause)).pipe(Effect.flatMap((scope) => Layer.buildWithScope(tracing, scope))));
|
|
75
|
+
});
|
|
73
76
|
export * as Otlp from "./otlp.js";
|
package/dist/observability.js
CHANGED
|
@@ -25,7 +25,7 @@ export function layer(options = {
|
|
|
25
25
|
const local = Logger.layer(Logging.loggers(app.channel === "local", app.channel), { mergeWithExisting: false }).pipe(Layer.provide(NodeFileSystem.layer), Layer.orDie, Layer.merge(Layer.succeed(References.MinimumLogLevel, Logging.minimumLogLevel())));
|
|
26
26
|
return Layer.unwrap(Effect.gen(function* () {
|
|
27
27
|
const logs = Logger.layer([...Logging.loggers(app.channel === "local", app.channel), ...Otlp.loggers(options, app)], { mergeWithExisting: false }).pipe(Layer.provide(NodeFileSystem.layer), Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer), Layer.orDie, Layer.merge(Layer.succeed(References.MinimumLogLevel, Logging.minimumLogLevel())));
|
|
28
|
-
return Layer.merge(logs, yield*
|
|
28
|
+
return Layer.merge(logs, yield* Otlp.tracingLayer(options, app));
|
|
29
29
|
})).pipe(Layer.catchCause(() => local));
|
|
30
30
|
}
|
|
31
31
|
export const node = LayerNode.make({ name: "observability", layer: layer(), deps: [] });
|