neatlogs 1.1.21 → 1.1.23
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 +153 -24
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.d.ts +30 -6
- package/dist/ai-sdk.mjs +153 -24
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/cli.cjs +25 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +25 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +181 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +181 -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 +15 -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.23";
|
|
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
|
@@ -1630,6 +1630,19 @@ var UnifiedAttributeProcessor = class {
|
|
|
1630
1630
|
attrs["llm.output_messages.0.message.role"] = "assistant";
|
|
1631
1631
|
attrs["llm.output_messages.0.message.content"] = typeof obj === "string" ? obj : JSON.stringify(obj);
|
|
1632
1632
|
}
|
|
1633
|
+
const responseReasoning = attrs["ai.response.reasoning"];
|
|
1634
|
+
if (typeof responseReasoning === "string" && responseReasoning.length > 0 && !("neatlogs.llm.output_messages.0.thinking" in attrs)) {
|
|
1635
|
+
attrs["neatlogs.llm.output_messages.0.thinking"] = responseReasoning;
|
|
1636
|
+
}
|
|
1637
|
+
const thinking = attrs["neatlogs.llm.output_messages.0.thinking"];
|
|
1638
|
+
if (typeof thinking === "string" && thinking.length > 0) {
|
|
1639
|
+
if (!("neatlogs.llm.thinking" in attrs)) {
|
|
1640
|
+
attrs["neatlogs.llm.thinking"] = thinking;
|
|
1641
|
+
}
|
|
1642
|
+
if (!("neatlogs.llm.has_thinking" in attrs)) {
|
|
1643
|
+
attrs["neatlogs.llm.has_thinking"] = "true";
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1633
1646
|
if ("ai.response.finishReason" in attrs && !("llm.response.finish_reason" in attrs)) {
|
|
1634
1647
|
attrs["llm.response.finish_reason"] = attrs["ai.response.finishReason"];
|
|
1635
1648
|
}
|
|
@@ -8401,16 +8414,20 @@ var ObservableBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
8401
8414
|
// src/core/log.ts
|
|
8402
8415
|
import { AsyncLocalStorage as AsyncLocalStorage5 } from "async_hooks";
|
|
8403
8416
|
var logger12 = getLogger();
|
|
8404
|
-
var
|
|
8405
|
-
var
|
|
8417
|
+
var LOG_RUNTIME_STATE_KEY = /* @__PURE__ */ Symbol.for("neatlogs.log_runtime_state");
|
|
8418
|
+
var neatlogsGlobal3 = globalThis;
|
|
8419
|
+
var logRuntimeState = neatlogsGlobal3[LOG_RUNTIME_STATE_KEY] ?? (neatlogsGlobal3[LOG_RUNTIME_STATE_KEY] = {
|
|
8420
|
+
otelLogger: null,
|
|
8421
|
+
debugMode: false
|
|
8422
|
+
});
|
|
8406
8423
|
var stdoutCaptureContext = new AsyncLocalStorage5();
|
|
8407
8424
|
function resolveOtelLogger() {
|
|
8408
8425
|
const client = getActiveClient();
|
|
8409
|
-
return client ? client.getLogger() :
|
|
8426
|
+
return client ? client.getLogger() : logRuntimeState.otelLogger;
|
|
8410
8427
|
}
|
|
8411
8428
|
function _setOtelLogger(otelLogger, debug) {
|
|
8412
|
-
|
|
8413
|
-
|
|
8429
|
+
logRuntimeState.otelLogger = otelLogger;
|
|
8430
|
+
logRuntimeState.debugMode = debug;
|
|
8414
8431
|
}
|
|
8415
8432
|
function log(msgTemplate, options) {
|
|
8416
8433
|
const { level = "info", ...variables } = options ?? {};
|
|
@@ -8418,7 +8435,7 @@ function log(msgTemplate, options) {
|
|
|
8418
8435
|
for (const [key, value] of Object.entries(variables)) {
|
|
8419
8436
|
rendered = rendered.replace(new RegExp(`\\{${key}\\}`, "g"), String(value));
|
|
8420
8437
|
}
|
|
8421
|
-
if (
|
|
8438
|
+
if (logRuntimeState.debugMode) {
|
|
8422
8439
|
console.log(`[neatlogs:log] ${rendered}`);
|
|
8423
8440
|
}
|
|
8424
8441
|
const otelLogger = resolveOtelLogger();
|
|
@@ -9283,7 +9300,7 @@ function _resetMastraCache() {
|
|
|
9283
9300
|
}
|
|
9284
9301
|
|
|
9285
9302
|
// src/version.ts
|
|
9286
|
-
var __version__ = "1.1.
|
|
9303
|
+
var __version__ = "1.1.23";
|
|
9287
9304
|
|
|
9288
9305
|
// src/core/deadline.ts
|
|
9289
9306
|
async function runByDeadline(operation, deadlineMs) {
|
|
@@ -9319,7 +9336,7 @@ var _logProvider = null;
|
|
|
9319
9336
|
var _spanProcessor = null;
|
|
9320
9337
|
var _transportSpanProcessors = [];
|
|
9321
9338
|
var _completionProcessor = null;
|
|
9322
|
-
var
|
|
9339
|
+
var _debugMode = false;
|
|
9323
9340
|
var _deliveryDiagnostics = new DeliveryDiagnostics();
|
|
9324
9341
|
var _initIdentity = null;
|
|
9325
9342
|
var _effectiveSampleRate = 1;
|
|
@@ -9611,7 +9628,7 @@ async function _performInit(options) {
|
|
|
9611
9628
|
if (options.debug) {
|
|
9612
9629
|
enableDebugLogging();
|
|
9613
9630
|
}
|
|
9614
|
-
|
|
9631
|
+
_debugMode = options.debug ?? false;
|
|
9615
9632
|
const resolvedWorkflowName = _resolveWorkflowName(options.workflowName);
|
|
9616
9633
|
const endpoint = resolveInitEndpoint(options.endpoint);
|
|
9617
9634
|
const baseUrl = resolveIngestBaseUrl(endpoint);
|
|
@@ -9997,7 +10014,7 @@ async function _performShutdown(terminationReason, timeoutMs) {
|
|
|
9997
10014
|
_spanProcessor = null;
|
|
9998
10015
|
_transportSpanProcessors = [];
|
|
9999
10016
|
_completionProcessor = null;
|
|
10000
|
-
|
|
10017
|
+
_debugMode = false;
|
|
10001
10018
|
_effectiveSampleRate = 1;
|
|
10002
10019
|
_exportEnabled = false;
|
|
10003
10020
|
_queueMaxSize = 2048;
|
|
@@ -10009,7 +10026,7 @@ async function _performShutdown(terminationReason, timeoutMs) {
|
|
|
10009
10026
|
return success;
|
|
10010
10027
|
}
|
|
10011
10028
|
function isDebugEnabled() {
|
|
10012
|
-
return
|
|
10029
|
+
return _debugMode;
|
|
10013
10030
|
}
|
|
10014
10031
|
function _doctorRuntimeSnapshot() {
|
|
10015
10032
|
return {
|
|
@@ -10601,10 +10618,105 @@ import {
|
|
|
10601
10618
|
SpanStatusCode as SpanStatusCode6
|
|
10602
10619
|
} from "@opentelemetry/api";
|
|
10603
10620
|
var TRACER_NAME2 = "neatlogs.ai-sdk";
|
|
10621
|
+
var NEATLOGS_V7_INTEGRATION = /* @__PURE__ */ Symbol("neatlogs.ai-sdk.v7-integration");
|
|
10622
|
+
var AI_SDK_OTEL_MODULE = "@ai-sdk/otel";
|
|
10623
|
+
var LazyV7OpenTelemetryIntegration = class {
|
|
10624
|
+
constructor(tracer, metadata) {
|
|
10625
|
+
this.tracer = tracer;
|
|
10626
|
+
this.metadata = metadata;
|
|
10627
|
+
}
|
|
10628
|
+
tracer;
|
|
10629
|
+
metadata;
|
|
10630
|
+
[NEATLOGS_V7_INTEGRATION] = true;
|
|
10631
|
+
delegatePromise;
|
|
10632
|
+
getDelegate() {
|
|
10633
|
+
return this.delegatePromise ??= import(AI_SDK_OTEL_MODULE).then(
|
|
10634
|
+
({ OpenTelemetry }) => new OpenTelemetry({
|
|
10635
|
+
tracer: this.tracer,
|
|
10636
|
+
enrichSpan: () => this.metadata
|
|
10637
|
+
})
|
|
10638
|
+
).catch((error) => {
|
|
10639
|
+
const detail = error instanceof Error ? `: ${error.message}` : "";
|
|
10640
|
+
throw new Error(
|
|
10641
|
+
"Vercel AI SDK v7 telemetry requires the optional @ai-sdk/otel peer dependency" + detail
|
|
10642
|
+
);
|
|
10643
|
+
});
|
|
10644
|
+
}
|
|
10645
|
+
async notify(method, event) {
|
|
10646
|
+
const delegate = await this.getDelegate();
|
|
10647
|
+
const fn = delegate[method];
|
|
10648
|
+
if (typeof fn === "function") {
|
|
10649
|
+
await Reflect.apply(fn, delegate, [event]);
|
|
10650
|
+
}
|
|
10651
|
+
}
|
|
10652
|
+
onStart(event) {
|
|
10653
|
+
return this.notify("onStart", event);
|
|
10654
|
+
}
|
|
10655
|
+
onStepStart(event) {
|
|
10656
|
+
return this.notify("onStepStart", event);
|
|
10657
|
+
}
|
|
10658
|
+
onLanguageModelCallStart(event) {
|
|
10659
|
+
return this.notify("onLanguageModelCallStart", event);
|
|
10660
|
+
}
|
|
10661
|
+
onLanguageModelCallEnd(event) {
|
|
10662
|
+
return this.notify("onLanguageModelCallEnd", event);
|
|
10663
|
+
}
|
|
10664
|
+
onToolExecutionStart(event) {
|
|
10665
|
+
return this.notify("onToolExecutionStart", event);
|
|
10666
|
+
}
|
|
10667
|
+
onToolExecutionEnd(event) {
|
|
10668
|
+
return this.notify("onToolExecutionEnd", event);
|
|
10669
|
+
}
|
|
10670
|
+
onStepEnd(event) {
|
|
10671
|
+
return this.notify("onStepEnd", event);
|
|
10672
|
+
}
|
|
10673
|
+
onStepFinish(event) {
|
|
10674
|
+
return this.notify("onStepFinish", event);
|
|
10675
|
+
}
|
|
10676
|
+
onObjectStepStart(event) {
|
|
10677
|
+
return this.notify("onObjectStepStart", event);
|
|
10678
|
+
}
|
|
10679
|
+
onObjectStepEnd(event) {
|
|
10680
|
+
return this.notify("onObjectStepEnd", event);
|
|
10681
|
+
}
|
|
10682
|
+
onEmbedStart(event) {
|
|
10683
|
+
return this.notify("onEmbedStart", event);
|
|
10684
|
+
}
|
|
10685
|
+
onEmbedEnd(event) {
|
|
10686
|
+
return this.notify("onEmbedEnd", event);
|
|
10687
|
+
}
|
|
10688
|
+
onRerankStart(event) {
|
|
10689
|
+
return this.notify("onRerankStart", event);
|
|
10690
|
+
}
|
|
10691
|
+
onRerankEnd(event) {
|
|
10692
|
+
return this.notify("onRerankEnd", event);
|
|
10693
|
+
}
|
|
10694
|
+
onEnd(event) {
|
|
10695
|
+
return this.notify("onEnd", event);
|
|
10696
|
+
}
|
|
10697
|
+
onAbort(event) {
|
|
10698
|
+
return this.notify("onAbort", event);
|
|
10699
|
+
}
|
|
10700
|
+
onError(event) {
|
|
10701
|
+
return this.notify("onError", event);
|
|
10702
|
+
}
|
|
10703
|
+
async executeLanguageModelCall(options) {
|
|
10704
|
+
const delegate = await this.getDelegate();
|
|
10705
|
+
const fn = delegate.executeLanguageModelCall;
|
|
10706
|
+
return typeof fn === "function" ? Reflect.apply(fn, delegate, [options]) : options.execute();
|
|
10707
|
+
}
|
|
10708
|
+
async executeTool(options) {
|
|
10709
|
+
const delegate = await this.getDelegate();
|
|
10710
|
+
const fn = delegate.executeTool;
|
|
10711
|
+
return typeof fn === "function" ? Reflect.apply(fn, delegate, [options]) : options.execute();
|
|
10712
|
+
}
|
|
10713
|
+
};
|
|
10604
10714
|
function createAITelemetry(opts = {}) {
|
|
10605
10715
|
const userMeta = opts.metadata ?? {};
|
|
10606
10716
|
const neatlogsTracer = getRoutingNeatlogsTracer(TRACER_NAME2);
|
|
10607
10717
|
const callerTracer = opts.tracer;
|
|
10718
|
+
const tracer = callerTracer ? createMirroredTracer(callerTracer, neatlogsTracer) : neatlogsTracer;
|
|
10719
|
+
const metadata = callerTracer ? { ...userMeta } : { ...userMeta, neatlogsWrapped: true };
|
|
10608
10720
|
return {
|
|
10609
10721
|
isEnabled: true,
|
|
10610
10722
|
recordInputs: true,
|
|
@@ -10613,11 +10725,12 @@ function createAITelemetry(opts = {}) {
|
|
|
10613
10725
|
// internally, which would otherwise parent its native spans from the foreign
|
|
10614
10726
|
// global context AND push them onto it (so a co-tenant's next span inherits
|
|
10615
10727
|
// ours). The facade routes both through the private Neatlogs context.
|
|
10616
|
-
tracer
|
|
10728
|
+
tracer,
|
|
10617
10729
|
...opts.functionId !== void 0 ? { functionId: opts.functionId } : {},
|
|
10618
10730
|
// The marker is an implementation detail used only when Neatlogs owns the
|
|
10619
10731
|
// telemetry stream. Do not leak it into caller-owned providers.
|
|
10620
|
-
metadata
|
|
10732
|
+
metadata,
|
|
10733
|
+
integrations: [new LazyV7OpenTelemetryIntegration(tracer, metadata)]
|
|
10621
10734
|
};
|
|
10622
10735
|
}
|
|
10623
10736
|
function safeStringify2(value) {
|
|
@@ -10650,7 +10763,7 @@ function setOutputValue(span2, result) {
|
|
|
10650
10763
|
span2.setAttribute("output.value", text);
|
|
10651
10764
|
}
|
|
10652
10765
|
if (r.finishReason) {
|
|
10653
|
-
span2.setAttribute("
|
|
10766
|
+
span2.setAttribute("neatlogs.llm.finish_reason", String(r.finishReason));
|
|
10654
10767
|
}
|
|
10655
10768
|
return;
|
|
10656
10769
|
}
|
|
@@ -10659,7 +10772,7 @@ function setOutputValue(span2, result) {
|
|
|
10659
10772
|
span2.setAttribute("output.value", safeStringify2(r.object));
|
|
10660
10773
|
}
|
|
10661
10774
|
if (r.finishReason) {
|
|
10662
|
-
span2.setAttribute("
|
|
10775
|
+
span2.setAttribute("neatlogs.llm.finish_reason", String(r.finishReason));
|
|
10663
10776
|
}
|
|
10664
10777
|
return;
|
|
10665
10778
|
}
|
|
@@ -10679,7 +10792,7 @@ function setStreamOutputValue(span2, event) {
|
|
|
10679
10792
|
if (stringified) span2.setAttribute("output.value", stringified);
|
|
10680
10793
|
}
|
|
10681
10794
|
if (e.finishReason) {
|
|
10682
|
-
span2.setAttribute("
|
|
10795
|
+
span2.setAttribute("neatlogs.llm.finish_reason", String(e.finishReason));
|
|
10683
10796
|
}
|
|
10684
10797
|
}
|
|
10685
10798
|
var WRAPPED_FUNCTIONS = [
|
|
@@ -10699,6 +10812,8 @@ var wrappedExports = /* @__PURE__ */ new WeakSet();
|
|
|
10699
10812
|
var wrapperByOriginal = /* @__PURE__ */ new WeakMap();
|
|
10700
10813
|
function wrapAISDK(aiModule) {
|
|
10701
10814
|
const wrapped = { ...aiModule };
|
|
10815
|
+
const hasRegisterTelemetry = "registerTelemetry" in aiModule && typeof Reflect.get(aiModule, "registerTelemetry") === "function";
|
|
10816
|
+
const telemetryKey = hasRegisterTelemetry ? "telemetry" : "experimental_telemetry";
|
|
10702
10817
|
for (const name of WRAPPED_FUNCTIONS) {
|
|
10703
10818
|
const original = aiModule[name];
|
|
10704
10819
|
if (typeof original !== "function") continue;
|
|
@@ -10710,12 +10825,16 @@ function wrapAISDK(aiModule) {
|
|
|
10710
10825
|
if (name === "streamText" || name === "streamObject") {
|
|
10711
10826
|
wrapped[name] = cacheWrapper(
|
|
10712
10827
|
original,
|
|
10713
|
-
createStreamWrapper(name, original)
|
|
10828
|
+
createStreamWrapper(name, original, telemetryKey)
|
|
10714
10829
|
);
|
|
10715
10830
|
} else {
|
|
10716
10831
|
wrapped[name] = cacheWrapper(
|
|
10717
10832
|
original,
|
|
10718
|
-
createAsyncWrapper(
|
|
10833
|
+
createAsyncWrapper(
|
|
10834
|
+
name,
|
|
10835
|
+
original,
|
|
10836
|
+
telemetryKey
|
|
10837
|
+
)
|
|
10719
10838
|
);
|
|
10720
10839
|
}
|
|
10721
10840
|
}
|
|
@@ -10725,7 +10844,7 @@ function wrapAISDK(aiModule) {
|
|
|
10725
10844
|
const existing = getExistingWrapper(original);
|
|
10726
10845
|
wrapped[name] = existing ?? cacheWrapper(
|
|
10727
10846
|
original,
|
|
10728
|
-
createAgentConstructorWrapper(original)
|
|
10847
|
+
createAgentConstructorWrapper(original, telemetryKey)
|
|
10729
10848
|
);
|
|
10730
10849
|
}
|
|
10731
10850
|
return wrapped;
|
|
@@ -10739,26 +10858,30 @@ function cacheWrapper(original, wrapped) {
|
|
|
10739
10858
|
wrappedExports.add(wrapped);
|
|
10740
10859
|
return wrapped;
|
|
10741
10860
|
}
|
|
10742
|
-
function createAgentConstructorWrapper(original) {
|
|
10861
|
+
function createAgentConstructorWrapper(original, telemetryKey) {
|
|
10743
10862
|
return new Proxy(original, {
|
|
10744
10863
|
construct(target, args, newTarget) {
|
|
10745
10864
|
if (args.length === 0 || typeof args[0] !== "object" || args[0] === null) {
|
|
10746
10865
|
return Reflect.construct(target, args, newTarget);
|
|
10747
10866
|
}
|
|
10748
|
-
const settings = mergeAgentSettings(args[0]);
|
|
10867
|
+
const settings = mergeAgentSettings(args[0], telemetryKey);
|
|
10749
10868
|
return Reflect.construct(target, [settings, ...args.slice(1)], newTarget);
|
|
10750
10869
|
}
|
|
10751
10870
|
});
|
|
10752
10871
|
}
|
|
10753
|
-
function mergeAgentSettings(settings) {
|
|
10754
|
-
const merged = mergeTelemetry(settings);
|
|
10872
|
+
function mergeAgentSettings(settings, telemetryKey) {
|
|
10873
|
+
const merged = mergeTelemetry(settings, telemetryKey);
|
|
10755
10874
|
const userPrepareCall = settings.prepareCall;
|
|
10756
10875
|
if (typeof userPrepareCall !== "function") return merged;
|
|
10757
10876
|
return {
|
|
10758
10877
|
...merged,
|
|
10759
10878
|
prepareCall: async function wrappedPrepareCall(...args) {
|
|
10760
10879
|
const prepared = await Reflect.apply(userPrepareCall, this, args);
|
|
10761
|
-
return prepared == null ? prepared : mergeTelemetry(
|
|
10880
|
+
return prepared == null ? prepared : mergeTelemetry(
|
|
10881
|
+
prepared,
|
|
10882
|
+
telemetryKey,
|
|
10883
|
+
settings.telemetry ?? settings.experimental_telemetry
|
|
10884
|
+
);
|
|
10762
10885
|
}
|
|
10763
10886
|
};
|
|
10764
10887
|
}
|
|
@@ -10770,7 +10893,7 @@ function rootSpanKind(name) {
|
|
|
10770
10893
|
function getParentContext() {
|
|
10771
10894
|
return getNeatlogsParentContext();
|
|
10772
10895
|
}
|
|
10773
|
-
function createAsyncWrapper(name, original) {
|
|
10896
|
+
function createAsyncWrapper(name, original, telemetryKey) {
|
|
10774
10897
|
return async function wrappedAsyncFn(opts) {
|
|
10775
10898
|
const tracer = getNeatlogsTracer(TRACER_NAME2);
|
|
10776
10899
|
const parentContext = getParentContext();
|
|
@@ -10790,7 +10913,7 @@ function createAsyncWrapper(name, original) {
|
|
|
10790
10913
|
if (name === "rerank" && opts?.query) {
|
|
10791
10914
|
span2.setAttribute("ai.rerank.query", String(opts.query));
|
|
10792
10915
|
}
|
|
10793
|
-
const merged = mergeTelemetry(opts);
|
|
10916
|
+
const merged = mergeTelemetry(opts, telemetryKey);
|
|
10794
10917
|
const result = await original(merged);
|
|
10795
10918
|
if (!isEmbedOrRerank) {
|
|
10796
10919
|
setOutputValue(span2, result);
|
|
@@ -10807,7 +10930,7 @@ function createAsyncWrapper(name, original) {
|
|
|
10807
10930
|
);
|
|
10808
10931
|
};
|
|
10809
10932
|
}
|
|
10810
|
-
function createStreamWrapper(name, original) {
|
|
10933
|
+
function createStreamWrapper(name, original, telemetryKey) {
|
|
10811
10934
|
return function wrappedStreamFn(opts) {
|
|
10812
10935
|
const tracer = getNeatlogsTracer(TRACER_NAME2);
|
|
10813
10936
|
const parentContext = getParentContext();
|
|
@@ -10827,7 +10950,7 @@ function createStreamWrapper(name, original) {
|
|
|
10827
10950
|
};
|
|
10828
10951
|
try {
|
|
10829
10952
|
setInputValue(span2, opts);
|
|
10830
|
-
const merged = mergeTelemetry(opts);
|
|
10953
|
+
const merged = mergeTelemetry(opts, telemetryKey);
|
|
10831
10954
|
const userOnFinish = opts?.onFinish;
|
|
10832
10955
|
const userOnError = opts?.onError;
|
|
10833
10956
|
const wrappedOpts = {
|
|
@@ -10952,25 +11075,47 @@ function createMirroredTracer(primary, secondary) {
|
|
|
10952
11075
|
})
|
|
10953
11076
|
};
|
|
10954
11077
|
}
|
|
10955
|
-
function
|
|
11078
|
+
function isNeatlogsV7Integration(integration) {
|
|
11079
|
+
return typeof integration === "object" && integration !== null && NEATLOGS_V7_INTEGRATION in integration;
|
|
11080
|
+
}
|
|
11081
|
+
function mergeTelemetry(opts, telemetryKey, fallbackTelemetry) {
|
|
11082
|
+
const legacyTelemetry = opts?.experimental_telemetry ?? {};
|
|
11083
|
+
const v7Telemetry = opts?.telemetry ?? {};
|
|
11084
|
+
const preferredTelemetry = telemetryKey === "telemetry" ? { ...legacyTelemetry, ...v7Telemetry } : { ...v7Telemetry, ...legacyTelemetry };
|
|
10956
11085
|
const requestedTelemetry = {
|
|
10957
11086
|
...fallbackTelemetry,
|
|
10958
|
-
...
|
|
11087
|
+
...preferredTelemetry,
|
|
10959
11088
|
metadata: {
|
|
10960
11089
|
...fallbackTelemetry?.metadata,
|
|
10961
|
-
...
|
|
11090
|
+
...legacyTelemetry.metadata,
|
|
11091
|
+
...v7Telemetry.metadata
|
|
10962
11092
|
}
|
|
10963
11093
|
};
|
|
10964
|
-
const
|
|
11094
|
+
const existingNeatlogsIntegration = Array.isArray(
|
|
11095
|
+
requestedTelemetry.integrations
|
|
11096
|
+
) ? requestedTelemetry.integrations.find(isNeatlogsV7Integration) : void 0;
|
|
11097
|
+
const baseTelemetry = existingNeatlogsIntegration ? {
|
|
11098
|
+
isEnabled: true,
|
|
11099
|
+
recordInputs: true,
|
|
11100
|
+
recordOutputs: true,
|
|
11101
|
+
tracer: requestedTelemetry.tracer,
|
|
11102
|
+
...requestedTelemetry.functionId !== void 0 ? { functionId: requestedTelemetry.functionId } : {},
|
|
11103
|
+
metadata: requestedTelemetry.metadata,
|
|
11104
|
+
integrations: [existingNeatlogsIntegration]
|
|
11105
|
+
} : createAITelemetry({
|
|
10965
11106
|
functionId: requestedTelemetry.functionId,
|
|
10966
11107
|
metadata: requestedTelemetry.metadata,
|
|
10967
11108
|
tracer: requestedTelemetry.tracer
|
|
10968
11109
|
});
|
|
10969
11110
|
const callerTracer = requestedTelemetry.tracer;
|
|
10970
11111
|
const hasCallerTracer = callerTracer !== void 0;
|
|
11112
|
+
const requestedIntegrations = Array.isArray(requestedTelemetry.integrations) ? requestedTelemetry.integrations.filter(
|
|
11113
|
+
(integration) => !isNeatlogsV7Integration(integration)
|
|
11114
|
+
) : [];
|
|
11115
|
+
const { telemetry: _telemetry, experimental_telemetry: _legacy, ...rest } = opts ?? {};
|
|
10971
11116
|
return {
|
|
10972
|
-
...
|
|
10973
|
-
|
|
11117
|
+
...rest,
|
|
11118
|
+
[telemetryKey]: {
|
|
10974
11119
|
...baseTelemetry,
|
|
10975
11120
|
...requestedTelemetry,
|
|
10976
11121
|
isEnabled: true,
|
|
@@ -10980,7 +11125,8 @@ function mergeTelemetry(opts, fallbackTelemetry) {
|
|
|
10980
11125
|
// Do not add Neatlogs-only marker metadata to a caller-owned telemetry
|
|
10981
11126
|
// pipeline such as Laminar. Both providers receive the same AI SDK span
|
|
10982
11127
|
// data, while their providers, parent contexts, and exporters stay separate.
|
|
10983
|
-
metadata: hasCallerTracer ? requestedTelemetry.metadata : baseTelemetry.metadata
|
|
11128
|
+
metadata: hasCallerTracer ? requestedTelemetry.metadata : baseTelemetry.metadata,
|
|
11129
|
+
integrations: [...baseTelemetry.integrations, ...requestedIntegrations]
|
|
10984
11130
|
}
|
|
10985
11131
|
};
|
|
10986
11132
|
}
|