@latitude-data/telemetry 2.0.4 → 3.0.0-alpha.1

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.
@@ -0,0 +1,169 @@
1
+ import { SpanProcessor, Span, ReadableSpan, SpanExporter, NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
2
+ import * as otel from '@opentelemetry/api';
3
+ import { TracerProvider, Context } from '@opentelemetry/api';
4
+
5
+ /**
6
+ * Supported LLM instrumentation types.
7
+ * Use these string identifiers to enable auto-instrumentation.
8
+ */
9
+ type InstrumentationType = "openai" | "anthropic" | "bedrock" | "cohere" | "langchain" | "llamaindex" | "togetherai" | "vertexai" | "aiplatform";
10
+ /**
11
+ * Options for creating LLM instrumentations.
12
+ */
13
+ interface CreateInstrumentationsOptions {
14
+ /** List of instrumentation types to enable. */
15
+ instrumentations: InstrumentationType[];
16
+ /**
17
+ * Optional module references for auto-instrumentation.
18
+ * If not provided, the instrumentation will attempt to require the module.
19
+ * Used for Traceloop-based instrumentations.
20
+ */
21
+ modules?: Partial<Record<InstrumentationType, unknown>>;
22
+ /**
23
+ * Per-instrumentation token enrichment settings.
24
+ * @default { openai: true }
25
+ */
26
+ enrichTokens?: Partial<Record<InstrumentationType, boolean>>;
27
+ }
28
+ /**
29
+ * Registers LLM instrumentations with the global OpenTelemetry instrumentation registry.
30
+ *
31
+ * This is a convenience wrapper around `createLatitudeInstrumentations` and
32
+ * `@opentelemetry/instrumentation`'s `registerInstrumentations`.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node"
37
+ * import { registerLatitudeInstrumentations, LatitudeSpanProcessor } from "@latitude-data/telemetry"
38
+ *
39
+ * const provider = new NodeTracerProvider({
40
+ * spanProcessors: [new LatitudeSpanProcessor(apiKey, projectSlug)],
41
+ * })
42
+ *
43
+ * await registerLatitudeInstrumentations({
44
+ * instrumentations: ["openai", "anthropic"],
45
+ * tracerProvider: provider,
46
+ * })
47
+ *
48
+ * provider.register()
49
+ * ```
50
+ */
51
+ declare function registerLatitudeInstrumentations(options: CreateInstrumentationsOptions & {
52
+ tracerProvider: TracerProvider;
53
+ }): Promise<void>;
54
+
55
+ interface RedactSpanProcessorOptions {
56
+ attributes: (string | RegExp)[];
57
+ mask?: (attribute: string, value: unknown) => string;
58
+ }
59
+ declare class RedactSpanProcessor implements SpanProcessor {
60
+ private options;
61
+ constructor(options: RedactSpanProcessorOptions);
62
+ onStart(_span: Span, _context: otel.Context): void;
63
+ onEnd(span: ReadableSpan): void;
64
+ forceFlush(): Promise<void>;
65
+ shutdown(): Promise<void>;
66
+ private shouldRedact;
67
+ private redactAttributes;
68
+ }
69
+
70
+ type SmartFilterOptions = {
71
+ /**
72
+ * When true, all spans are exported (legacy behavior).
73
+ * Default false — only LLM-relevant spans are exported.
74
+ */
75
+ disableSmartFilter?: boolean;
76
+ /**
77
+ * When smart filter is on, also export spans for which this returns true
78
+ * (in addition to {@link isDefaultExportSpan}).
79
+ */
80
+ shouldExportSpan?: (span: ReadableSpan) => boolean;
81
+ /** Instrumentation scope names to drop (exact match) even if they pass the default predicate. */
82
+ blockedInstrumentationScopes?: string[];
83
+ };
84
+ /** Input for {@link buildShouldExportSpanFromFields}; allows `undefined` field values for ergonomics. */
85
+ type SmartFilterFieldsInput = {
86
+ disableSmartFilter?: boolean | undefined;
87
+ shouldExportSpan?: ((span: ReadableSpan) => boolean) | undefined;
88
+ blockedInstrumentationScopes?: string[] | undefined;
89
+ };
90
+ /**
91
+ * Builds the export predicate from loose option fields (`exactOptionalPropertyTypes`-safe call sites).
92
+ */
93
+ declare function buildShouldExportSpanFromFields(fields: SmartFilterFieldsInput): (span: ReadableSpan) => boolean;
94
+ /** True if the span uses OpenTelemetry GenAI semantic conventions or common LLM attribute namespaces. */
95
+ declare function isGenAiOrLlmAttributeSpan(span: ReadableSpan): boolean;
96
+ /** True if the span was created with Latitude's tracer scopes. */
97
+ declare function isLatitudeInstrumentationSpan(span: ReadableSpan): boolean;
98
+ /**
99
+ * Default export predicate (smart filter): Latitude scopes, GenAI / LLM attributes,
100
+ * or known LLM instrumentation scopes.
101
+ */
102
+ declare function isDefaultExportSpan(span: ReadableSpan): boolean;
103
+ declare function buildShouldExportSpan(options: SmartFilterOptions): (span: ReadableSpan) => boolean;
104
+ /**
105
+ * Drops spans that fail the export predicate before passing them to the inner processor.
106
+ * Inner processor should perform redaction and export.
107
+ */
108
+ declare class ExportFilterSpanProcessor implements SpanProcessor {
109
+ private readonly shouldExport;
110
+ private readonly inner;
111
+ constructor(shouldExport: (span: ReadableSpan) => boolean, inner: SpanProcessor);
112
+ onStart(span: Span, parentContext: Context): void;
113
+ onEnd(span: ReadableSpan): void;
114
+ forceFlush(): Promise<void>;
115
+ shutdown(): Promise<void>;
116
+ }
117
+ /** Runs optional redaction then the export processor (batch/simple). */
118
+ declare class RedactThenExportSpanProcessor implements SpanProcessor {
119
+ private readonly redact;
120
+ private readonly exportProcessor;
121
+ constructor(redact: SpanProcessor | null, exportProcessor: SpanProcessor);
122
+ onStart(span: Span, parentContext: Context): void;
123
+ onEnd(span: ReadableSpan): void;
124
+ forceFlush(): Promise<void>;
125
+ shutdown(): Promise<void>;
126
+ }
127
+
128
+ type ContextOptions = {
129
+ name?: string;
130
+ tags?: string[];
131
+ metadata?: Record<string, unknown>;
132
+ sessionId?: string;
133
+ userId?: string;
134
+ };
135
+ type InitLatitudeOptions = SmartFilterOptions & {
136
+ apiKey: string;
137
+ projectSlug: string;
138
+ instrumentations?: InstrumentationType[];
139
+ disableRedact?: boolean;
140
+ redact?: RedactSpanProcessorOptions;
141
+ disableBatch?: boolean;
142
+ exporter?: SpanExporter;
143
+ };
144
+ type LatitudeSpanProcessorOptions = SmartFilterOptions & {
145
+ disableRedact?: boolean;
146
+ redact?: RedactSpanProcessorOptions;
147
+ disableBatch?: boolean;
148
+ exporter?: SpanExporter;
149
+ };
150
+
151
+ declare function capture<T>(name: string, fn: () => T | Promise<T>, options?: ContextOptions): T | Promise<T>;
152
+
153
+ declare function initLatitude(options: InitLatitudeOptions): {
154
+ provider: NodeTracerProvider;
155
+ flush: () => Promise<void>;
156
+ shutdown: () => Promise<void>;
157
+ ready: Promise<void>;
158
+ };
159
+
160
+ declare class LatitudeSpanProcessor implements SpanProcessor {
161
+ private readonly tail;
162
+ constructor(apiKey: string, projectSlug: string, options?: LatitudeSpanProcessorOptions);
163
+ onStart(span: Span, parentContext: Context): void;
164
+ onEnd(span: ReadableSpan): void;
165
+ forceFlush(): Promise<void>;
166
+ shutdown(): Promise<void>;
167
+ }
168
+
169
+ export { type ContextOptions, ExportFilterSpanProcessor, type InitLatitudeOptions, type InstrumentationType, LatitudeSpanProcessor, type LatitudeSpanProcessorOptions, RedactSpanProcessor, type RedactSpanProcessorOptions, RedactThenExportSpanProcessor, type SmartFilterFieldsInput, type SmartFilterOptions, buildShouldExportSpan, buildShouldExportSpanFromFields, capture, initLatitude, isDefaultExportSpan, isGenAiOrLlmAttributeSpan, isLatitudeInstrumentationSpan, registerLatitudeInstrumentations };
package/dist/index.d.ts CHANGED
@@ -1,339 +1,169 @@
1
- import { z } from 'zod';
1
+ import { SpanProcessor, Span, ReadableSpan, SpanExporter, NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
2
2
  import * as otel from '@opentelemetry/api';
3
- import { TextMapPropagator } from '@opentelemetry/api';
4
- import { Provider } from 'rosetta-ai';
5
- import { SpanProcessor, ReadableSpan, SpanExporter, NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
6
- import * as latitude from '@latitude-data/sdk';
7
- import { Latitude } from '@latitude-data/sdk';
8
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
3
+ import { TracerProvider, Context } from '@opentelemetry/api';
9
4
 
10
- interface BaseInstrumentation {
11
- isEnabled(): boolean;
12
- enable(): void;
13
- disable(): void;
14
- }
15
-
16
- type LatitudeInstrumentationOptions = {
17
- module: typeof Latitude;
18
- completions?: boolean;
19
- };
20
-
21
- declare enum LogSources {
22
- API = "api",
23
- AgentAsTool = "agent_as_tool",
24
- Copilot = "copilot",
25
- EmailTrigger = "email_trigger",
26
- Evaluation = "evaluation",
27
- Experiment = "experiment",
28
- IntegrationTrigger = "integration_trigger",
29
- Playground = "playground",
30
- ScheduledTrigger = "scheduled_trigger",
31
- SharedPrompt = "shared_prompt",
32
- ShadowTest = "shadow_test",
33
- ABTestChallenger = "ab_test_challenger",
34
- User = "user",
35
- Optimization = "optimization"
36
- }
37
-
38
- declare const traceContextSchema: z.ZodObject<{
39
- traceparent: z.ZodString;
40
- tracestate: z.ZodOptional<z.ZodString>;
41
- baggage: z.ZodOptional<z.ZodString>;
42
- }, z.core.$strip>;
43
- type TraceContext = z.infer<typeof traceContextSchema>;
44
-
45
- type StartSpanOptions = {
46
- name?: string;
47
- attributes?: otel.Attributes;
48
- };
49
- type EndSpanOptions = {
50
- attributes?: otel.Attributes;
51
- };
52
- type ErrorOptions = {
53
- attributes?: otel.Attributes;
54
- };
55
- type StartToolSpanOptions = StartSpanOptions & {
56
- name: string;
57
- call: {
58
- id: string;
59
- arguments: Record<string, unknown>;
60
- };
61
- };
62
- type EndToolSpanOptions = EndSpanOptions & {
63
- result: {
64
- value: unknown;
65
- isError: boolean;
66
- };
67
- };
68
- type StartCompletionSpanOptions = StartSpanOptions & {
69
- provider: string;
70
- model: string;
71
- configuration?: Record<string, unknown>;
72
- input?: string | Record<string, unknown>[];
73
- versionUuid?: string;
74
- promptUuid?: string;
75
- experimentUuid?: string;
76
- };
77
- type EndCompletionSpanOptions = EndSpanOptions & {
78
- output?: string | Record<string, unknown>[];
79
- tokens?: {
80
- prompt?: number;
81
- cached?: number;
82
- reasoning?: number;
83
- completion?: number;
84
- };
85
- finishReason?: string;
86
- };
87
- type StartHttpSpanOptions = StartSpanOptions & {
88
- request: {
89
- method: string;
90
- url: string;
91
- headers: Record<string, string>;
92
- body: string | Record<string, unknown>;
93
- };
94
- };
95
- type EndHttpSpanOptions = EndSpanOptions & {
96
- response: {
97
- status: number;
98
- headers: Record<string, string>;
99
- body: string | Record<string, unknown>;
100
- };
101
- };
102
- type PromptSpanOptions = StartSpanOptions & {
103
- documentLogUuid: string;
104
- versionUuid?: string;
105
- promptUuid: string;
106
- projectId?: number;
107
- experimentUuid?: string;
108
- testDeploymentId?: number;
109
- externalId?: string;
110
- template: string;
111
- parameters?: Record<string, unknown>;
112
- source?: LogSources;
113
- };
114
- type ChatSpanOptions = StartSpanOptions & {
115
- documentLogUuid: string;
116
- previousTraceId: string;
117
- source?: LogSources;
118
- versionUuid?: string;
119
- promptUuid?: string;
120
- };
121
- type ExternalSpanOptions = StartSpanOptions & {
122
- promptUuid: string;
123
- documentLogUuid: string;
124
- source?: LogSources;
125
- versionUuid?: string;
126
- externalId?: string;
127
- };
128
- type CaptureOptions = StartSpanOptions & {
129
- path: string;
130
- projectId: number;
131
- versionUuid?: string;
132
- conversationUuid?: string;
133
- };
134
- type ManualInstrumentationOptions = {
135
- provider?: Provider;
136
- };
137
- declare class ManualInstrumentation implements BaseInstrumentation {
138
- private enabled;
139
- private readonly tracer;
140
- private readonly options;
141
- constructor(tracer: otel.Tracer, options?: ManualInstrumentationOptions);
142
- isEnabled(): boolean;
143
- enable(): void;
144
- disable(): void;
145
- resume(ctx: TraceContext): otel.Context;
146
- private error;
147
- private span;
148
- unknown(ctx: otel.Context, options?: StartSpanOptions): {
149
- context: otel.Context;
150
- end: (_options?: EndSpanOptions) => void;
151
- fail: (_error: Error, _options?: ErrorOptions) => void;
152
- };
153
- tool(ctx: otel.Context, options: StartToolSpanOptions): {
154
- end: (options: EndToolSpanOptions) => void;
155
- context: otel.Context;
156
- fail: (_error: Error, _options?: ErrorOptions) => void;
157
- };
158
- private attribifyConfiguration;
159
- completion(ctx: otel.Context, options: StartCompletionSpanOptions): {
160
- end: (options?: EndCompletionSpanOptions) => void;
161
- context: otel.Context;
162
- fail: (_error: Error, _options?: ErrorOptions) => void;
163
- };
164
- embedding(ctx: otel.Context, options?: StartSpanOptions): {
165
- context: otel.Context;
166
- end: (_options?: EndSpanOptions) => void;
167
- fail: (_error: Error, _options?: ErrorOptions) => void;
168
- };
169
- private attribifyHeaders;
170
- http(ctx: otel.Context, options: StartHttpSpanOptions): {
171
- end: (options: EndHttpSpanOptions) => void;
172
- context: otel.Context;
173
- fail: (_error: Error, _options?: ErrorOptions) => void;
174
- };
175
- prompt(ctx: otel.Context, { documentLogUuid, versionUuid, promptUuid, projectId, experimentUuid, testDeploymentId, externalId, template, parameters, name, source, ...rest }: PromptSpanOptions): {
176
- context: otel.Context;
177
- end: (_options?: EndSpanOptions) => void;
178
- fail: (_error: Error, _options?: ErrorOptions) => void;
179
- };
180
- chat(ctx: otel.Context, { documentLogUuid, previousTraceId, source, name, versionUuid, promptUuid, ...rest }: ChatSpanOptions): {
181
- context: otel.Context;
182
- end: (_options?: EndSpanOptions) => void;
183
- fail: (_error: Error, _options?: ErrorOptions) => void;
184
- };
185
- external(ctx: otel.Context, { promptUuid, documentLogUuid, source, versionUuid, externalId, name, ...rest }: ExternalSpanOptions): {
186
- context: otel.Context;
187
- end: (_options?: EndSpanOptions) => void;
188
- fail: (_error: Error, _options?: ErrorOptions) => void;
189
- };
190
- unresolvedExternal(ctx: otel.Context, { path, projectId, versionUuid, conversationUuid, name, ...rest }: CaptureOptions): {
191
- context: otel.Context;
192
- end: (_options?: EndSpanOptions) => void;
193
- fail: (_error: Error, _options?: ErrorOptions) => void;
194
- };
5
+ /**
6
+ * Supported LLM instrumentation types.
7
+ * Use these string identifiers to enable auto-instrumentation.
8
+ */
9
+ type InstrumentationType = "openai" | "anthropic" | "bedrock" | "cohere" | "langchain" | "llamaindex" | "togetherai" | "vertexai" | "aiplatform";
10
+ /**
11
+ * Options for creating LLM instrumentations.
12
+ */
13
+ interface CreateInstrumentationsOptions {
14
+ /** List of instrumentation types to enable. */
15
+ instrumentations: InstrumentationType[];
16
+ /**
17
+ * Optional module references for auto-instrumentation.
18
+ * If not provided, the instrumentation will attempt to require the module.
19
+ * Used for Traceloop-based instrumentations.
20
+ */
21
+ modules?: Partial<Record<InstrumentationType, unknown>>;
22
+ /**
23
+ * Per-instrumentation token enrichment settings.
24
+ * @default { openai: true }
25
+ */
26
+ enrichTokens?: Partial<Record<InstrumentationType, boolean>>;
195
27
  }
28
+ /**
29
+ * Registers LLM instrumentations with the global OpenTelemetry instrumentation registry.
30
+ *
31
+ * This is a convenience wrapper around `createLatitudeInstrumentations` and
32
+ * `@opentelemetry/instrumentation`'s `registerInstrumentations`.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node"
37
+ * import { registerLatitudeInstrumentations, LatitudeSpanProcessor } from "@latitude-data/telemetry"
38
+ *
39
+ * const provider = new NodeTracerProvider({
40
+ * spanProcessors: [new LatitudeSpanProcessor(apiKey, projectSlug)],
41
+ * })
42
+ *
43
+ * await registerLatitudeInstrumentations({
44
+ * instrumentations: ["openai", "anthropic"],
45
+ * tracerProvider: provider,
46
+ * })
47
+ *
48
+ * provider.register()
49
+ * ```
50
+ */
51
+ declare function registerLatitudeInstrumentations(options: CreateInstrumentationsOptions & {
52
+ tracerProvider: TracerProvider;
53
+ }): Promise<void>;
196
54
 
197
55
  interface RedactSpanProcessorOptions {
198
56
  attributes: (string | RegExp)[];
199
- mask?: (attribute: string, value: any) => string;
57
+ mask?: (attribute: string, value: unknown) => string;
200
58
  }
201
59
  declare class RedactSpanProcessor implements SpanProcessor {
202
60
  private options;
203
61
  constructor(options: RedactSpanProcessorOptions);
204
- onStart(_span: ReadableSpan, _context: otel.Context): void;
62
+ onStart(_span: Span, _context: otel.Context): void;
205
63
  onEnd(span: ReadableSpan): void;
206
64
  forceFlush(): Promise<void>;
207
65
  shutdown(): Promise<void>;
208
66
  private shouldRedact;
209
67
  private redactAttributes;
210
68
  }
211
- declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
212
69
 
213
- type TelemetryContext = otel.Context;
214
- declare const BACKGROUND: () => otel.Context;
215
- declare class SpanFactory {
216
- private readonly telemetry;
217
- constructor(telemetry: ManualInstrumentation);
218
- span(options?: StartSpanOptions, ctx?: TelemetryContext): {
219
- context: otel.Context;
220
- end: (_options?: EndSpanOptions) => void;
221
- fail: (_error: Error, _options?: ErrorOptions) => void;
222
- };
223
- tool(options: StartToolSpanOptions, ctx?: TelemetryContext): {
224
- end: (options: EndToolSpanOptions) => void;
225
- context: otel.Context;
226
- fail: (_error: Error, _options?: ErrorOptions) => void;
227
- };
228
- completion(options: StartCompletionSpanOptions, ctx?: TelemetryContext): {
229
- end: (options?: EndCompletionSpanOptions) => void;
230
- context: otel.Context;
231
- fail: (_error: Error, _options?: ErrorOptions) => void;
232
- };
233
- embedding(options?: StartSpanOptions, ctx?: TelemetryContext): {
234
- context: otel.Context;
235
- end: (_options?: EndSpanOptions) => void;
236
- fail: (_error: Error, _options?: ErrorOptions) => void;
237
- };
238
- http(options: StartHttpSpanOptions, ctx?: TelemetryContext): {
239
- end: (options: EndHttpSpanOptions) => void;
240
- context: otel.Context;
241
- fail: (_error: Error, _options?: ErrorOptions) => void;
242
- };
243
- prompt(options: PromptSpanOptions, ctx?: TelemetryContext): {
244
- context: otel.Context;
245
- end: (_options?: EndSpanOptions) => void;
246
- fail: (_error: Error, _options?: ErrorOptions) => void;
247
- };
248
- chat(options: ChatSpanOptions, ctx?: TelemetryContext): {
249
- context: otel.Context;
250
- end: (_options?: EndSpanOptions) => void;
251
- fail: (_error: Error, _options?: ErrorOptions) => void;
252
- };
253
- external(options: ExternalSpanOptions, ctx?: TelemetryContext): {
254
- context: otel.Context;
255
- end: (_options?: EndSpanOptions) => void;
256
- fail: (_error: Error, _options?: ErrorOptions) => void;
257
- };
258
- }
259
- declare class ContextManager {
260
- private readonly telemetry;
261
- constructor(telemetry: ManualInstrumentation);
262
- resume(ctx: TraceContext): otel.Context;
263
- active(): otel.Context;
264
- with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(ctx: TelemetryContext, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
265
- }
266
- declare class InstrumentationManager {
267
- private readonly instrumentations;
268
- constructor(instrumentations: BaseInstrumentation[]);
269
- enable(): void;
270
- disable(): void;
271
- }
272
- declare class TracerManager {
273
- private readonly nodeProvider;
274
- private readonly scopeVersion;
275
- constructor(nodeProvider: NodeTracerProvider, scopeVersion: string);
276
- get(scope: Instrumentation): otel.Tracer;
277
- provider(scope: Instrumentation): ScopedTracerProvider;
278
- }
279
- declare class ScopedTracerProvider implements otel.TracerProvider {
280
- private readonly scope;
281
- private readonly version;
282
- private readonly provider;
283
- constructor(scope: string, version: string, provider: otel.TracerProvider);
284
- getTracer(_name: string, _version?: string, options?: otel.TracerOptions): otel.Tracer;
70
+ type SmartFilterOptions = {
71
+ /**
72
+ * When true, all spans are exported (legacy behavior).
73
+ * Default false — only LLM-relevant spans are exported.
74
+ */
75
+ disableSmartFilter?: boolean;
76
+ /**
77
+ * When smart filter is on, also export spans for which this returns true
78
+ * (in addition to {@link isDefaultExportSpan}).
79
+ */
80
+ shouldExportSpan?: (span: ReadableSpan) => boolean;
81
+ /** Instrumentation scope names to drop (exact match) even if they pass the default predicate. */
82
+ blockedInstrumentationScopes?: string[];
83
+ };
84
+ /** Input for {@link buildShouldExportSpanFromFields}; allows `undefined` field values for ergonomics. */
85
+ type SmartFilterFieldsInput = {
86
+ disableSmartFilter?: boolean | undefined;
87
+ shouldExportSpan?: ((span: ReadableSpan) => boolean) | undefined;
88
+ blockedInstrumentationScopes?: string[] | undefined;
89
+ };
90
+ /**
91
+ * Builds the export predicate from loose option fields (`exactOptionalPropertyTypes`-safe call sites).
92
+ */
93
+ declare function buildShouldExportSpanFromFields(fields: SmartFilterFieldsInput): (span: ReadableSpan) => boolean;
94
+ /** True if the span uses OpenTelemetry GenAI semantic conventions or common LLM attribute namespaces. */
95
+ declare function isGenAiOrLlmAttributeSpan(span: ReadableSpan): boolean;
96
+ /** True if the span was created with Latitude's tracer scopes. */
97
+ declare function isLatitudeInstrumentationSpan(span: ReadableSpan): boolean;
98
+ /**
99
+ * Default export predicate (smart filter): Latitude scopes, GenAI / LLM attributes,
100
+ * or known LLM instrumentation scopes.
101
+ */
102
+ declare function isDefaultExportSpan(span: ReadableSpan): boolean;
103
+ declare function buildShouldExportSpan(options: SmartFilterOptions): (span: ReadableSpan) => boolean;
104
+ /**
105
+ * Drops spans that fail the export predicate before passing them to the inner processor.
106
+ * Inner processor should perform redaction and export.
107
+ */
108
+ declare class ExportFilterSpanProcessor implements SpanProcessor {
109
+ private readonly shouldExport;
110
+ private readonly inner;
111
+ constructor(shouldExport: (span: ReadableSpan) => boolean, inner: SpanProcessor);
112
+ onStart(span: Span, parentContext: Context): void;
113
+ onEnd(span: ReadableSpan): void;
114
+ forceFlush(): Promise<void>;
115
+ shutdown(): Promise<void>;
285
116
  }
286
- declare const DEFAULT_SPAN_EXPORTER: (apiKey: string) => OTLPTraceExporter;
287
- declare enum Instrumentation {
288
- Anthropic = "anthropic",
289
- AIPlatform = "aiplatform",
290
- Bedrock = "bedrock",
291
- Cohere = "cohere",
292
- Langchain = "langchain",
293
- Latitude = "latitude",
294
- LlamaIndex = "llamaindex",
295
- Manual = "manual",
296
- OpenAI = "openai",
297
- TogetherAI = "togetherai",
298
- VertexAI = "vertexai"
117
+ /** Runs optional redaction then the export processor (batch/simple). */
118
+ declare class RedactThenExportSpanProcessor implements SpanProcessor {
119
+ private readonly redact;
120
+ private readonly exportProcessor;
121
+ constructor(redact: SpanProcessor | null, exportProcessor: SpanProcessor);
122
+ onStart(span: Span, parentContext: Context): void;
123
+ onEnd(span: ReadableSpan): void;
124
+ forceFlush(): Promise<void>;
125
+ shutdown(): Promise<void>;
299
126
  }
300
- type TelemetryOptions = {
127
+
128
+ type ContextOptions = {
129
+ name?: string;
130
+ tags?: string[];
131
+ metadata?: Record<string, unknown>;
132
+ sessionId?: string;
133
+ userId?: string;
134
+ };
135
+ type InitLatitudeOptions = SmartFilterOptions & {
136
+ apiKey: string;
137
+ projectSlug: string;
138
+ instrumentations?: InstrumentationType[];
139
+ disableRedact?: boolean;
140
+ redact?: RedactSpanProcessorOptions;
301
141
  disableBatch?: boolean;
302
142
  exporter?: SpanExporter;
303
- processors?: SpanProcessor[];
304
- propagators?: TextMapPropagator[];
305
- instrumentations?: {
306
- [Instrumentation.Latitude]?: typeof latitude.Latitude | LatitudeInstrumentationOptions;
307
- [Instrumentation.AIPlatform]?: any;
308
- [Instrumentation.Anthropic]?: any;
309
- [Instrumentation.Bedrock]?: any;
310
- [Instrumentation.Cohere]?: any;
311
- [Instrumentation.OpenAI]?: any;
312
- [Instrumentation.LlamaIndex]?: any;
313
- [Instrumentation.TogetherAI]?: any;
314
- [Instrumentation.VertexAI]?: any;
315
- [Instrumentation.Langchain]?: {
316
- callbackManagerModule?: any;
317
- };
318
- [Instrumentation.Manual]?: ManualInstrumentationOptions;
319
- };
320
143
  };
321
- declare class LatitudeTelemetry {
322
- private options;
323
- private nodeProvider;
324
- private manualInstrumentation;
325
- private instrumentationsList;
326
- readonly span: SpanFactory;
327
- readonly context: ContextManager;
328
- readonly instrumentation: InstrumentationManager;
329
- readonly tracer: TracerManager;
330
- private readonly lifecycle;
331
- constructor(apiKey: string, options?: TelemetryOptions);
332
- flush(): Promise<void>;
144
+ type LatitudeSpanProcessorOptions = SmartFilterOptions & {
145
+ disableRedact?: boolean;
146
+ redact?: RedactSpanProcessorOptions;
147
+ disableBatch?: boolean;
148
+ exporter?: SpanExporter;
149
+ };
150
+
151
+ declare function capture<T>(name: string, fn: () => T | Promise<T>, options?: ContextOptions): T | Promise<T>;
152
+
153
+ declare function initLatitude(options: InitLatitudeOptions): {
154
+ provider: NodeTracerProvider;
155
+ flush: () => Promise<void>;
156
+ shutdown: () => Promise<void>;
157
+ ready: Promise<void>;
158
+ };
159
+
160
+ declare class LatitudeSpanProcessor implements SpanProcessor {
161
+ private readonly tail;
162
+ constructor(apiKey: string, projectSlug: string, options?: LatitudeSpanProcessorOptions);
163
+ onStart(span: Span, parentContext: Context): void;
164
+ onEnd(span: ReadableSpan): void;
165
+ forceFlush(): Promise<void>;
333
166
  shutdown(): Promise<void>;
334
- private initInstrumentations;
335
- capture<T>(options: CaptureOptions, fn: (ctx: TelemetryContext) => T | Promise<T>): Promise<T>;
336
167
  }
337
168
 
338
- export { BACKGROUND, DEFAULT_REDACT_SPAN_PROCESSOR, DEFAULT_SPAN_EXPORTER, Instrumentation, LatitudeTelemetry, RedactSpanProcessor };
339
- export type { CaptureOptions, ChatSpanOptions, EndCompletionSpanOptions, EndHttpSpanOptions, EndSpanOptions, EndToolSpanOptions, ErrorOptions, ExternalSpanOptions, PromptSpanOptions as PromptSegmentOptions, RedactSpanProcessorOptions, StartCompletionSpanOptions, StartHttpSpanOptions, StartSpanOptions, StartToolSpanOptions, TelemetryContext, TelemetryOptions };
169
+ export { type ContextOptions, ExportFilterSpanProcessor, type InitLatitudeOptions, type InstrumentationType, LatitudeSpanProcessor, type LatitudeSpanProcessorOptions, RedactSpanProcessor, type RedactSpanProcessorOptions, RedactThenExportSpanProcessor, type SmartFilterFieldsInput, type SmartFilterOptions, buildShouldExportSpan, buildShouldExportSpanFromFields, capture, initLatitude, isDefaultExportSpan, isGenAiOrLlmAttributeSpan, isLatitudeInstrumentationSpan, registerLatitudeInstrumentations };