@latitude-data/telemetry 3.0.0-alpha.0 → 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.
- package/README.md +415 -115
- package/dist/index.cjs +405 -325
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -96
- package/dist/index.d.ts +142 -96
- package/dist/index.js +403 -314
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,56 @@
|
|
|
1
|
+
import { SpanProcessor, Span, ReadableSpan, SpanExporter, NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
1
2
|
import * as otel from '@opentelemetry/api';
|
|
2
|
-
import {
|
|
3
|
-
import { SpanProcessor, Span, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-node';
|
|
4
|
-
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
3
|
+
import { TracerProvider, Context } from '@opentelemetry/api';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
baggage?: string;
|
|
29
|
-
}): otel.Context;
|
|
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>>;
|
|
30
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>;
|
|
31
54
|
|
|
32
55
|
interface RedactSpanProcessorOptions {
|
|
33
56
|
attributes: (string | RegExp)[];
|
|
@@ -43,81 +66,104 @@ declare class RedactSpanProcessor implements SpanProcessor {
|
|
|
43
66
|
private shouldRedact;
|
|
44
67
|
private redactAttributes;
|
|
45
68
|
}
|
|
46
|
-
declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
|
|
47
69
|
|
|
48
|
-
type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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>;
|
|
64
116
|
}
|
|
65
|
-
|
|
66
|
-
declare
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
OpenAI = "openai",
|
|
75
|
-
TogetherAI = "togetherai",
|
|
76
|
-
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>;
|
|
77
126
|
}
|
|
78
|
-
|
|
79
|
-
|
|
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;
|
|
80
141
|
disableBatch?: boolean;
|
|
81
142
|
exporter?: SpanExporter;
|
|
82
|
-
processors?: SpanProcessor[];
|
|
83
|
-
propagators?: TextMapPropagator[];
|
|
84
|
-
instrumentations?: {
|
|
85
|
-
[Instrumentation.AIPlatform]?: unknown;
|
|
86
|
-
[Instrumentation.Anthropic]?: unknown;
|
|
87
|
-
[Instrumentation.Bedrock]?: unknown;
|
|
88
|
-
[Instrumentation.Cohere]?: unknown;
|
|
89
|
-
[Instrumentation.OpenAI]?: unknown;
|
|
90
|
-
[Instrumentation.LlamaIndex]?: unknown;
|
|
91
|
-
[Instrumentation.TogetherAI]?: unknown;
|
|
92
|
-
[Instrumentation.VertexAI]?: unknown;
|
|
93
|
-
[Instrumentation.Langchain]?: {
|
|
94
|
-
callbackManagerModule?: unknown;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
143
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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>;
|
|
109
166
|
shutdown(): Promise<void>;
|
|
110
|
-
private initProviderInstrumentations;
|
|
111
|
-
/**
|
|
112
|
-
* Wrap a block of code with trace-wide context attributes.
|
|
113
|
-
* Baggage entries (tags, metadata, sessionId, userId) are propagated
|
|
114
|
-
* to all spans created within the callback via BaggageSpanProcessor.
|
|
115
|
-
*
|
|
116
|
-
* If there is no active span, a root span is created so all child spans
|
|
117
|
-
* are grouped under a single trace. If a span is already active, only
|
|
118
|
-
* baggage is set without creating an extra wrapper span.
|
|
119
|
-
*/
|
|
120
|
-
capture<T>(options: CaptureOptions, fn: (ctx: TelemetryContext) => T | Promise<T>): Promise<T>;
|
|
121
167
|
}
|
|
122
168
|
|
|
123
|
-
export { type
|
|
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 };
|