neatlogs 1.1.21 → 1.1.22
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 +12 -9
- package/dist/ai-sdk.cjs +162 -24
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.d.ts +13 -4
- package/dist/ai-sdk.mjs +152 -24
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/cli.cjs +12 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +12 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +167 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +167 -35
- package/dist/index.mjs.map +1 -1
- package/dist/opencode-plugin.cjs +1 -1
- package/dist/opencode-plugin.cjs.map +1 -1
- package/dist/opencode-plugin.mjs +1 -1
- package/dist/opencode-plugin.mjs.map +1 -1
- package/package.json +13 -3
package/dist/index.d.ts
CHANGED
|
@@ -2282,6 +2282,6 @@ declare function doctorCapturedLocalV2(options?: Readonly<{
|
|
|
2282
2282
|
* SDK version. Kept in sync with package.json by the `version:sync` script
|
|
2283
2283
|
* (runs automatically on `prebuild`). Do not edit by hand — bump package.json.
|
|
2284
2284
|
*/
|
|
2285
|
-
declare const __version__ = "1.1.
|
|
2285
|
+
declare const __version__ = "1.1.22";
|
|
2286
2286
|
|
|
2287
2287
|
export { type CachedPrompt, Client, type ClientOptions, type CreatePromptInput, DOCTOR_V2_FORMAT_VERSION, type DeliveryDiagnosticsSnapshot, type DiagnosticEnvelope, type DiagnosticSpan, DisabledUploadAuthority, type DoctorV2Check, type DoctorV2Result, type FlushAllResult, type FlushOutcome, type GetPromptOptions, HttpUploadAuthority, type HttpUploadAuthorityOptions, type IdentifyOptions, type InitOptions, type LegacySavePromptVersionOptions, type MaskContext, type MaskFunction, NeatlogsConfigurationError, type NeatlogsConfigurationErrorCode, PromptApiError, PromptClient, PromptClientClosedError, PromptClientError, type PromptClientOptions, PromptHandle, type PromptMessage, type PromptMutationSelector, PromptNotFoundError, PromptRequestTimeoutError, PromptTemplate, type PromptWriteInput, type SavePromptVersionOptions, Span, type SpanKind, type SpanOptions, TELEMETRY_CONFLICT_PRECEDENCE, TELEMETRY_CONTRACT_VERSION, TELEMETRY_SCHEMA_SHA256, TELEMETRY_SCHEMA_V2, TELEMETRY_SCHEMA_VERSION, TelemetryUploadError, type TraceContextCarrier, type TraceOptions, type TraceSpanKind, type UploadAuthority, type UploadAuthorityOption, type UploadContentEncoding, type UploadPayload, type UploadPayloadSchema, type UploadPurpose, type UploadReceipt, type UploadReference, type UploadRequestOptions, UserPromptTemplate, __version__, addTag, bindTemplates, createPrompt, deletePrompt, doctorCapturedLocalV2, doctorLocalV2, doctorSemanticDigest, extractTraceContext, fetchPrompt, flush, flushAll, flushAllDetailed, getDeliveryDiagnostics, getMastraObservability, getPrompt, getSessionConfig, identify, init, injectTraceContext, isDebugEnabled, listPrompts, log, registerCrewaiTask, removeTag, saveAsVersion, setLabel, setTraceOutput, shutdown, span, trace, updatePrompt };
|
package/dist/index.mjs
CHANGED
|
@@ -8401,16 +8401,20 @@ var ObservableBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
8401
8401
|
// src/core/log.ts
|
|
8402
8402
|
import { AsyncLocalStorage as AsyncLocalStorage5 } from "async_hooks";
|
|
8403
8403
|
var logger12 = getLogger();
|
|
8404
|
-
var
|
|
8405
|
-
var
|
|
8404
|
+
var LOG_RUNTIME_STATE_KEY = /* @__PURE__ */ Symbol.for("neatlogs.log_runtime_state");
|
|
8405
|
+
var neatlogsGlobal3 = globalThis;
|
|
8406
|
+
var logRuntimeState = neatlogsGlobal3[LOG_RUNTIME_STATE_KEY] ?? (neatlogsGlobal3[LOG_RUNTIME_STATE_KEY] = {
|
|
8407
|
+
otelLogger: null,
|
|
8408
|
+
debugMode: false
|
|
8409
|
+
});
|
|
8406
8410
|
var stdoutCaptureContext = new AsyncLocalStorage5();
|
|
8407
8411
|
function resolveOtelLogger() {
|
|
8408
8412
|
const client = getActiveClient();
|
|
8409
|
-
return client ? client.getLogger() :
|
|
8413
|
+
return client ? client.getLogger() : logRuntimeState.otelLogger;
|
|
8410
8414
|
}
|
|
8411
8415
|
function _setOtelLogger(otelLogger, debug) {
|
|
8412
|
-
|
|
8413
|
-
|
|
8416
|
+
logRuntimeState.otelLogger = otelLogger;
|
|
8417
|
+
logRuntimeState.debugMode = debug;
|
|
8414
8418
|
}
|
|
8415
8419
|
function log(msgTemplate, options) {
|
|
8416
8420
|
const { level = "info", ...variables } = options ?? {};
|
|
@@ -8418,7 +8422,7 @@ function log(msgTemplate, options) {
|
|
|
8418
8422
|
for (const [key, value] of Object.entries(variables)) {
|
|
8419
8423
|
rendered = rendered.replace(new RegExp(`\\{${key}\\}`, "g"), String(value));
|
|
8420
8424
|
}
|
|
8421
|
-
if (
|
|
8425
|
+
if (logRuntimeState.debugMode) {
|
|
8422
8426
|
console.log(`[neatlogs:log] ${rendered}`);
|
|
8423
8427
|
}
|
|
8424
8428
|
const otelLogger = resolveOtelLogger();
|
|
@@ -9283,7 +9287,7 @@ function _resetMastraCache() {
|
|
|
9283
9287
|
}
|
|
9284
9288
|
|
|
9285
9289
|
// src/version.ts
|
|
9286
|
-
var __version__ = "1.1.
|
|
9290
|
+
var __version__ = "1.1.22";
|
|
9287
9291
|
|
|
9288
9292
|
// src/core/deadline.ts
|
|
9289
9293
|
async function runByDeadline(operation, deadlineMs) {
|
|
@@ -9319,7 +9323,7 @@ var _logProvider = null;
|
|
|
9319
9323
|
var _spanProcessor = null;
|
|
9320
9324
|
var _transportSpanProcessors = [];
|
|
9321
9325
|
var _completionProcessor = null;
|
|
9322
|
-
var
|
|
9326
|
+
var _debugMode = false;
|
|
9323
9327
|
var _deliveryDiagnostics = new DeliveryDiagnostics();
|
|
9324
9328
|
var _initIdentity = null;
|
|
9325
9329
|
var _effectiveSampleRate = 1;
|
|
@@ -9611,7 +9615,7 @@ async function _performInit(options) {
|
|
|
9611
9615
|
if (options.debug) {
|
|
9612
9616
|
enableDebugLogging();
|
|
9613
9617
|
}
|
|
9614
|
-
|
|
9618
|
+
_debugMode = options.debug ?? false;
|
|
9615
9619
|
const resolvedWorkflowName = _resolveWorkflowName(options.workflowName);
|
|
9616
9620
|
const endpoint = resolveInitEndpoint(options.endpoint);
|
|
9617
9621
|
const baseUrl = resolveIngestBaseUrl(endpoint);
|
|
@@ -9997,7 +10001,7 @@ async function _performShutdown(terminationReason, timeoutMs) {
|
|
|
9997
10001
|
_spanProcessor = null;
|
|
9998
10002
|
_transportSpanProcessors = [];
|
|
9999
10003
|
_completionProcessor = null;
|
|
10000
|
-
|
|
10004
|
+
_debugMode = false;
|
|
10001
10005
|
_effectiveSampleRate = 1;
|
|
10002
10006
|
_exportEnabled = false;
|
|
10003
10007
|
_queueMaxSize = 2048;
|
|
@@ -10009,7 +10013,7 @@ async function _performShutdown(terminationReason, timeoutMs) {
|
|
|
10009
10013
|
return success;
|
|
10010
10014
|
}
|
|
10011
10015
|
function isDebugEnabled() {
|
|
10012
|
-
return
|
|
10016
|
+
return _debugMode;
|
|
10013
10017
|
}
|
|
10014
10018
|
function _doctorRuntimeSnapshot() {
|
|
10015
10019
|
return {
|
|
@@ -10601,10 +10605,104 @@ import {
|
|
|
10601
10605
|
SpanStatusCode as SpanStatusCode6
|
|
10602
10606
|
} from "@opentelemetry/api";
|
|
10603
10607
|
var TRACER_NAME2 = "neatlogs.ai-sdk";
|
|
10608
|
+
var NEATLOGS_V7_INTEGRATION = /* @__PURE__ */ Symbol("neatlogs.ai-sdk.v7-integration");
|
|
10609
|
+
var LazyV7OpenTelemetryIntegration = class {
|
|
10610
|
+
constructor(tracer, metadata) {
|
|
10611
|
+
this.tracer = tracer;
|
|
10612
|
+
this.metadata = metadata;
|
|
10613
|
+
}
|
|
10614
|
+
tracer;
|
|
10615
|
+
metadata;
|
|
10616
|
+
[NEATLOGS_V7_INTEGRATION] = true;
|
|
10617
|
+
delegatePromise;
|
|
10618
|
+
getDelegate() {
|
|
10619
|
+
return this.delegatePromise ??= import("@ai-sdk/otel").then(
|
|
10620
|
+
({ OpenTelemetry }) => new OpenTelemetry({
|
|
10621
|
+
tracer: this.tracer,
|
|
10622
|
+
enrichSpan: () => this.metadata
|
|
10623
|
+
})
|
|
10624
|
+
).catch((error) => {
|
|
10625
|
+
const detail = error instanceof Error ? `: ${error.message}` : "";
|
|
10626
|
+
throw new Error(
|
|
10627
|
+
"Vercel AI SDK v7 telemetry requires the optional @ai-sdk/otel peer dependency" + detail
|
|
10628
|
+
);
|
|
10629
|
+
});
|
|
10630
|
+
}
|
|
10631
|
+
async notify(method, event) {
|
|
10632
|
+
const delegate = await this.getDelegate();
|
|
10633
|
+
const fn = delegate[method];
|
|
10634
|
+
if (typeof fn === "function") {
|
|
10635
|
+
await Reflect.apply(fn, delegate, [event]);
|
|
10636
|
+
}
|
|
10637
|
+
}
|
|
10638
|
+
onStart(event) {
|
|
10639
|
+
return this.notify("onStart", event);
|
|
10640
|
+
}
|
|
10641
|
+
onStepStart(event) {
|
|
10642
|
+
return this.notify("onStepStart", event);
|
|
10643
|
+
}
|
|
10644
|
+
onLanguageModelCallStart(event) {
|
|
10645
|
+
return this.notify("onLanguageModelCallStart", event);
|
|
10646
|
+
}
|
|
10647
|
+
onLanguageModelCallEnd(event) {
|
|
10648
|
+
return this.notify("onLanguageModelCallEnd", event);
|
|
10649
|
+
}
|
|
10650
|
+
onToolExecutionStart(event) {
|
|
10651
|
+
return this.notify("onToolExecutionStart", event);
|
|
10652
|
+
}
|
|
10653
|
+
onToolExecutionEnd(event) {
|
|
10654
|
+
return this.notify("onToolExecutionEnd", event);
|
|
10655
|
+
}
|
|
10656
|
+
onStepEnd(event) {
|
|
10657
|
+
return this.notify("onStepEnd", event);
|
|
10658
|
+
}
|
|
10659
|
+
onStepFinish(event) {
|
|
10660
|
+
return this.notify("onStepFinish", event);
|
|
10661
|
+
}
|
|
10662
|
+
onObjectStepStart(event) {
|
|
10663
|
+
return this.notify("onObjectStepStart", event);
|
|
10664
|
+
}
|
|
10665
|
+
onObjectStepEnd(event) {
|
|
10666
|
+
return this.notify("onObjectStepEnd", event);
|
|
10667
|
+
}
|
|
10668
|
+
onEmbedStart(event) {
|
|
10669
|
+
return this.notify("onEmbedStart", event);
|
|
10670
|
+
}
|
|
10671
|
+
onEmbedEnd(event) {
|
|
10672
|
+
return this.notify("onEmbedEnd", event);
|
|
10673
|
+
}
|
|
10674
|
+
onRerankStart(event) {
|
|
10675
|
+
return this.notify("onRerankStart", event);
|
|
10676
|
+
}
|
|
10677
|
+
onRerankEnd(event) {
|
|
10678
|
+
return this.notify("onRerankEnd", event);
|
|
10679
|
+
}
|
|
10680
|
+
onEnd(event) {
|
|
10681
|
+
return this.notify("onEnd", event);
|
|
10682
|
+
}
|
|
10683
|
+
onAbort(event) {
|
|
10684
|
+
return this.notify("onAbort", event);
|
|
10685
|
+
}
|
|
10686
|
+
onError(event) {
|
|
10687
|
+
return this.notify("onError", event);
|
|
10688
|
+
}
|
|
10689
|
+
async executeLanguageModelCall(options) {
|
|
10690
|
+
const delegate = await this.getDelegate();
|
|
10691
|
+
const fn = delegate.executeLanguageModelCall;
|
|
10692
|
+
return typeof fn === "function" ? Reflect.apply(fn, delegate, [options]) : options.execute();
|
|
10693
|
+
}
|
|
10694
|
+
async executeTool(options) {
|
|
10695
|
+
const delegate = await this.getDelegate();
|
|
10696
|
+
const fn = delegate.executeTool;
|
|
10697
|
+
return typeof fn === "function" ? Reflect.apply(fn, delegate, [options]) : options.execute();
|
|
10698
|
+
}
|
|
10699
|
+
};
|
|
10604
10700
|
function createAITelemetry(opts = {}) {
|
|
10605
10701
|
const userMeta = opts.metadata ?? {};
|
|
10606
10702
|
const neatlogsTracer = getRoutingNeatlogsTracer(TRACER_NAME2);
|
|
10607
10703
|
const callerTracer = opts.tracer;
|
|
10704
|
+
const tracer = callerTracer ? createMirroredTracer(callerTracer, neatlogsTracer) : neatlogsTracer;
|
|
10705
|
+
const metadata = callerTracer ? { ...userMeta } : { ...userMeta, neatlogsWrapped: true };
|
|
10608
10706
|
return {
|
|
10609
10707
|
isEnabled: true,
|
|
10610
10708
|
recordInputs: true,
|
|
@@ -10613,11 +10711,12 @@ function createAITelemetry(opts = {}) {
|
|
|
10613
10711
|
// internally, which would otherwise parent its native spans from the foreign
|
|
10614
10712
|
// global context AND push them onto it (so a co-tenant's next span inherits
|
|
10615
10713
|
// ours). The facade routes both through the private Neatlogs context.
|
|
10616
|
-
tracer
|
|
10714
|
+
tracer,
|
|
10617
10715
|
...opts.functionId !== void 0 ? { functionId: opts.functionId } : {},
|
|
10618
10716
|
// The marker is an implementation detail used only when Neatlogs owns the
|
|
10619
10717
|
// telemetry stream. Do not leak it into caller-owned providers.
|
|
10620
|
-
metadata
|
|
10718
|
+
metadata,
|
|
10719
|
+
integrations: [new LazyV7OpenTelemetryIntegration(tracer, metadata)]
|
|
10621
10720
|
};
|
|
10622
10721
|
}
|
|
10623
10722
|
function safeStringify2(value) {
|
|
@@ -10650,7 +10749,7 @@ function setOutputValue(span2, result) {
|
|
|
10650
10749
|
span2.setAttribute("output.value", text);
|
|
10651
10750
|
}
|
|
10652
10751
|
if (r.finishReason) {
|
|
10653
|
-
span2.setAttribute("
|
|
10752
|
+
span2.setAttribute("neatlogs.llm.finish_reason", String(r.finishReason));
|
|
10654
10753
|
}
|
|
10655
10754
|
return;
|
|
10656
10755
|
}
|
|
@@ -10659,7 +10758,7 @@ function setOutputValue(span2, result) {
|
|
|
10659
10758
|
span2.setAttribute("output.value", safeStringify2(r.object));
|
|
10660
10759
|
}
|
|
10661
10760
|
if (r.finishReason) {
|
|
10662
|
-
span2.setAttribute("
|
|
10761
|
+
span2.setAttribute("neatlogs.llm.finish_reason", String(r.finishReason));
|
|
10663
10762
|
}
|
|
10664
10763
|
return;
|
|
10665
10764
|
}
|
|
@@ -10679,7 +10778,7 @@ function setStreamOutputValue(span2, event) {
|
|
|
10679
10778
|
if (stringified) span2.setAttribute("output.value", stringified);
|
|
10680
10779
|
}
|
|
10681
10780
|
if (e.finishReason) {
|
|
10682
|
-
span2.setAttribute("
|
|
10781
|
+
span2.setAttribute("neatlogs.llm.finish_reason", String(e.finishReason));
|
|
10683
10782
|
}
|
|
10684
10783
|
}
|
|
10685
10784
|
var WRAPPED_FUNCTIONS = [
|
|
@@ -10699,6 +10798,8 @@ var wrappedExports = /* @__PURE__ */ new WeakSet();
|
|
|
10699
10798
|
var wrapperByOriginal = /* @__PURE__ */ new WeakMap();
|
|
10700
10799
|
function wrapAISDK(aiModule) {
|
|
10701
10800
|
const wrapped = { ...aiModule };
|
|
10801
|
+
const hasRegisterTelemetry = "registerTelemetry" in aiModule && typeof Reflect.get(aiModule, "registerTelemetry") === "function";
|
|
10802
|
+
const telemetryKey = hasRegisterTelemetry ? "telemetry" : "experimental_telemetry";
|
|
10702
10803
|
for (const name of WRAPPED_FUNCTIONS) {
|
|
10703
10804
|
const original = aiModule[name];
|
|
10704
10805
|
if (typeof original !== "function") continue;
|
|
@@ -10710,12 +10811,16 @@ function wrapAISDK(aiModule) {
|
|
|
10710
10811
|
if (name === "streamText" || name === "streamObject") {
|
|
10711
10812
|
wrapped[name] = cacheWrapper(
|
|
10712
10813
|
original,
|
|
10713
|
-
createStreamWrapper(name, original)
|
|
10814
|
+
createStreamWrapper(name, original, telemetryKey)
|
|
10714
10815
|
);
|
|
10715
10816
|
} else {
|
|
10716
10817
|
wrapped[name] = cacheWrapper(
|
|
10717
10818
|
original,
|
|
10718
|
-
createAsyncWrapper(
|
|
10819
|
+
createAsyncWrapper(
|
|
10820
|
+
name,
|
|
10821
|
+
original,
|
|
10822
|
+
telemetryKey
|
|
10823
|
+
)
|
|
10719
10824
|
);
|
|
10720
10825
|
}
|
|
10721
10826
|
}
|
|
@@ -10725,7 +10830,7 @@ function wrapAISDK(aiModule) {
|
|
|
10725
10830
|
const existing = getExistingWrapper(original);
|
|
10726
10831
|
wrapped[name] = existing ?? cacheWrapper(
|
|
10727
10832
|
original,
|
|
10728
|
-
createAgentConstructorWrapper(original)
|
|
10833
|
+
createAgentConstructorWrapper(original, telemetryKey)
|
|
10729
10834
|
);
|
|
10730
10835
|
}
|
|
10731
10836
|
return wrapped;
|
|
@@ -10739,26 +10844,30 @@ function cacheWrapper(original, wrapped) {
|
|
|
10739
10844
|
wrappedExports.add(wrapped);
|
|
10740
10845
|
return wrapped;
|
|
10741
10846
|
}
|
|
10742
|
-
function createAgentConstructorWrapper(original) {
|
|
10847
|
+
function createAgentConstructorWrapper(original, telemetryKey) {
|
|
10743
10848
|
return new Proxy(original, {
|
|
10744
10849
|
construct(target, args, newTarget) {
|
|
10745
10850
|
if (args.length === 0 || typeof args[0] !== "object" || args[0] === null) {
|
|
10746
10851
|
return Reflect.construct(target, args, newTarget);
|
|
10747
10852
|
}
|
|
10748
|
-
const settings = mergeAgentSettings(args[0]);
|
|
10853
|
+
const settings = mergeAgentSettings(args[0], telemetryKey);
|
|
10749
10854
|
return Reflect.construct(target, [settings, ...args.slice(1)], newTarget);
|
|
10750
10855
|
}
|
|
10751
10856
|
});
|
|
10752
10857
|
}
|
|
10753
|
-
function mergeAgentSettings(settings) {
|
|
10754
|
-
const merged = mergeTelemetry(settings);
|
|
10858
|
+
function mergeAgentSettings(settings, telemetryKey) {
|
|
10859
|
+
const merged = mergeTelemetry(settings, telemetryKey);
|
|
10755
10860
|
const userPrepareCall = settings.prepareCall;
|
|
10756
10861
|
if (typeof userPrepareCall !== "function") return merged;
|
|
10757
10862
|
return {
|
|
10758
10863
|
...merged,
|
|
10759
10864
|
prepareCall: async function wrappedPrepareCall(...args) {
|
|
10760
10865
|
const prepared = await Reflect.apply(userPrepareCall, this, args);
|
|
10761
|
-
return prepared == null ? prepared : mergeTelemetry(
|
|
10866
|
+
return prepared == null ? prepared : mergeTelemetry(
|
|
10867
|
+
prepared,
|
|
10868
|
+
telemetryKey,
|
|
10869
|
+
settings.telemetry ?? settings.experimental_telemetry
|
|
10870
|
+
);
|
|
10762
10871
|
}
|
|
10763
10872
|
};
|
|
10764
10873
|
}
|
|
@@ -10770,7 +10879,7 @@ function rootSpanKind(name) {
|
|
|
10770
10879
|
function getParentContext() {
|
|
10771
10880
|
return getNeatlogsParentContext();
|
|
10772
10881
|
}
|
|
10773
|
-
function createAsyncWrapper(name, original) {
|
|
10882
|
+
function createAsyncWrapper(name, original, telemetryKey) {
|
|
10774
10883
|
return async function wrappedAsyncFn(opts) {
|
|
10775
10884
|
const tracer = getNeatlogsTracer(TRACER_NAME2);
|
|
10776
10885
|
const parentContext = getParentContext();
|
|
@@ -10790,7 +10899,7 @@ function createAsyncWrapper(name, original) {
|
|
|
10790
10899
|
if (name === "rerank" && opts?.query) {
|
|
10791
10900
|
span2.setAttribute("ai.rerank.query", String(opts.query));
|
|
10792
10901
|
}
|
|
10793
|
-
const merged = mergeTelemetry(opts);
|
|
10902
|
+
const merged = mergeTelemetry(opts, telemetryKey);
|
|
10794
10903
|
const result = await original(merged);
|
|
10795
10904
|
if (!isEmbedOrRerank) {
|
|
10796
10905
|
setOutputValue(span2, result);
|
|
@@ -10807,7 +10916,7 @@ function createAsyncWrapper(name, original) {
|
|
|
10807
10916
|
);
|
|
10808
10917
|
};
|
|
10809
10918
|
}
|
|
10810
|
-
function createStreamWrapper(name, original) {
|
|
10919
|
+
function createStreamWrapper(name, original, telemetryKey) {
|
|
10811
10920
|
return function wrappedStreamFn(opts) {
|
|
10812
10921
|
const tracer = getNeatlogsTracer(TRACER_NAME2);
|
|
10813
10922
|
const parentContext = getParentContext();
|
|
@@ -10827,7 +10936,7 @@ function createStreamWrapper(name, original) {
|
|
|
10827
10936
|
};
|
|
10828
10937
|
try {
|
|
10829
10938
|
setInputValue(span2, opts);
|
|
10830
|
-
const merged = mergeTelemetry(opts);
|
|
10939
|
+
const merged = mergeTelemetry(opts, telemetryKey);
|
|
10831
10940
|
const userOnFinish = opts?.onFinish;
|
|
10832
10941
|
const userOnError = opts?.onError;
|
|
10833
10942
|
const wrappedOpts = {
|
|
@@ -10952,25 +11061,47 @@ function createMirroredTracer(primary, secondary) {
|
|
|
10952
11061
|
})
|
|
10953
11062
|
};
|
|
10954
11063
|
}
|
|
10955
|
-
function
|
|
11064
|
+
function isNeatlogsV7Integration(integration) {
|
|
11065
|
+
return typeof integration === "object" && integration !== null && NEATLOGS_V7_INTEGRATION in integration;
|
|
11066
|
+
}
|
|
11067
|
+
function mergeTelemetry(opts, telemetryKey, fallbackTelemetry) {
|
|
11068
|
+
const legacyTelemetry = opts?.experimental_telemetry ?? {};
|
|
11069
|
+
const v7Telemetry = opts?.telemetry ?? {};
|
|
11070
|
+
const preferredTelemetry = telemetryKey === "telemetry" ? { ...legacyTelemetry, ...v7Telemetry } : { ...v7Telemetry, ...legacyTelemetry };
|
|
10956
11071
|
const requestedTelemetry = {
|
|
10957
11072
|
...fallbackTelemetry,
|
|
10958
|
-
...
|
|
11073
|
+
...preferredTelemetry,
|
|
10959
11074
|
metadata: {
|
|
10960
11075
|
...fallbackTelemetry?.metadata,
|
|
10961
|
-
...
|
|
11076
|
+
...legacyTelemetry.metadata,
|
|
11077
|
+
...v7Telemetry.metadata
|
|
10962
11078
|
}
|
|
10963
11079
|
};
|
|
10964
|
-
const
|
|
11080
|
+
const existingNeatlogsIntegration = Array.isArray(
|
|
11081
|
+
requestedTelemetry.integrations
|
|
11082
|
+
) ? requestedTelemetry.integrations.find(isNeatlogsV7Integration) : void 0;
|
|
11083
|
+
const baseTelemetry = existingNeatlogsIntegration ? {
|
|
11084
|
+
isEnabled: true,
|
|
11085
|
+
recordInputs: true,
|
|
11086
|
+
recordOutputs: true,
|
|
11087
|
+
tracer: requestedTelemetry.tracer,
|
|
11088
|
+
...requestedTelemetry.functionId !== void 0 ? { functionId: requestedTelemetry.functionId } : {},
|
|
11089
|
+
metadata: requestedTelemetry.metadata,
|
|
11090
|
+
integrations: [existingNeatlogsIntegration]
|
|
11091
|
+
} : createAITelemetry({
|
|
10965
11092
|
functionId: requestedTelemetry.functionId,
|
|
10966
11093
|
metadata: requestedTelemetry.metadata,
|
|
10967
11094
|
tracer: requestedTelemetry.tracer
|
|
10968
11095
|
});
|
|
10969
11096
|
const callerTracer = requestedTelemetry.tracer;
|
|
10970
11097
|
const hasCallerTracer = callerTracer !== void 0;
|
|
11098
|
+
const requestedIntegrations = Array.isArray(requestedTelemetry.integrations) ? requestedTelemetry.integrations.filter(
|
|
11099
|
+
(integration) => !isNeatlogsV7Integration(integration)
|
|
11100
|
+
) : [];
|
|
11101
|
+
const { telemetry: _telemetry, experimental_telemetry: _legacy, ...rest } = opts ?? {};
|
|
10971
11102
|
return {
|
|
10972
|
-
...
|
|
10973
|
-
|
|
11103
|
+
...rest,
|
|
11104
|
+
[telemetryKey]: {
|
|
10974
11105
|
...baseTelemetry,
|
|
10975
11106
|
...requestedTelemetry,
|
|
10976
11107
|
isEnabled: true,
|
|
@@ -10980,7 +11111,8 @@ function mergeTelemetry(opts, fallbackTelemetry) {
|
|
|
10980
11111
|
// Do not add Neatlogs-only marker metadata to a caller-owned telemetry
|
|
10981
11112
|
// pipeline such as Laminar. Both providers receive the same AI SDK span
|
|
10982
11113
|
// data, while their providers, parent contexts, and exporters stay separate.
|
|
10983
|
-
metadata: hasCallerTracer ? requestedTelemetry.metadata : baseTelemetry.metadata
|
|
11114
|
+
metadata: hasCallerTracer ? requestedTelemetry.metadata : baseTelemetry.metadata,
|
|
11115
|
+
integrations: [...baseTelemetry.integrations, ...requestedIntegrations]
|
|
10984
11116
|
}
|
|
10985
11117
|
};
|
|
10986
11118
|
}
|