Skip to content
中文

Provider observation and the App's own recording targets ​

A stable Provider binds observation rules; each request is associated only with its own target, and child scopes inherit the association.

ProviderObservation is a Support observation at the wire boundary, not a Core execution event. Accept rules can distinguish metadata from content; when not enabled, no content payload is built and no error body is read. It is a failure-isolated side channel that does not change model results, cancellation, or retries.

createProviderObservationScope returns observer and attach. observer can be bound when constructing a stable Provider, and attach binds a log target for the current request. The App owns redaction, read/record permissions, and retention; Core does not understand whether this target is a file, a database, or a message record.

Progressive examples for the same business case ​

Observe metadata only ​

Beginner · Node.js

ts
import { Support } from '@jangts/agent-core';
const scope = Support.createProviderObservationScope<{ requestId: string }>({
  accepts(_owner, descriptor) { return descriptor.content === 'metadata'; },
  write(owner, event, spanId) { console.log(owner.requestId, spanId, event.event); },
});
console.log(scope.observer);
js
import { Support } from '@jangts/agent-core';
const scope = Support.createProviderObservationScope({
    accepts(_owner, descriptor) { return descriptor.content === 'metadata'; },
    write(owner, event, spanId) { console.log(owner.requestId, spanId, event.event); },
});
console.log(scope.observer);

Bind your own correlation value per request ​

Configuration · Node.js

This example only assembles; for actual calls, configure that diagnostics into the corresponding request execution rather than forcing an App ID into the Core identity.

ts
import { Support } from '@jangts/agent-core';
import { createDiagnostics } from '@jangts/agent-core/diagnostics';
const scope = Support.createProviderObservationScope<{ requestId: string }>({
  accepts: (_owner, descriptor) => descriptor.content === 'metadata',
  write(owner, event, spanId) { console.log(owner.requestId, spanId, event.event); },
});
const provider = new Support.CompatibleModelProvider({
  config: { baseUrl: process.env.MODEL_BASE_URL!, apiKey: process.env.MODEL_API_KEY!, model: process.env.MODEL_NAME! },
  observe: { provider: scope.observer },
});
const diagnostics = scope.attach(createDiagnostics(), { requestId: 'app-request-1' });
console.log(provider, diagnostics.identity?.runId);
js
import { Support } from '@jangts/agent-core';
import { createDiagnostics } from '@jangts/agent-core/diagnostics';
const scope = Support.createProviderObservationScope({
    accepts: (_owner, descriptor) => descriptor.content === 'metadata',
    write(owner, event, spanId) { console.log(owner.requestId, spanId, event.event); },
});
const provider = new Support.CompatibleModelProvider({
    config: { baseUrl: process.env.MODEL_BASE_URL, apiKey: process.env.MODEL_API_KEY, model: process.env.MODEL_NAME },
    observe: { provider: scope.observer },
});
const diagnostics = scope.attach(createDiagnostics(), { requestId: 'app-request-1' });
console.log(provider, diagnostics.identity?.runId);

API reference, usage examples and developer guides.