-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add Adaline Trace integration for OpenTelemetry #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adds native support for exporting OpenTelemetry traces to Adaline Trace,
the hosted observability platform for LLM applications.
Changes:
- Add AdalineTraceExporter class (SpanExporter implementation)
- Add AdalineTracer wrapper class with helper methods
- Export classes from @adaline/gateway package
- Add comprehensive but concise documentation to README
Features:
- Scoped tracing (only Gateway operations, not entire app)
- Automatic span creation for all LLM calls
- Built-in trace() helper for grouping workflows
- Session IDs and tags for categorization
- Configurable service name, version, and debug mode
Usage:
```typescript
import { Gateway, AdalineTracer } from "@adaline/gateway";
const adalineTracer = new AdalineTracer({
apiKey: process.env.ADALINE_API_KEY,
projectId: process.env.ADALINE_PROJECT_ID,
});
const gateway = new Gateway({
telemetry: { tracer: adalineTracer.tracer }
});
```
All Gateway operations are automatically traced with full observability:
model names, cache hits, latency, time-to-first-token, and span hierarchies.
Greptile OverviewGreptile SummaryAdds native OpenTelemetry integration for exporting traces to Adaline Trace, a hosted observability platform for LLM applications. Key Changes:
Implementation Quality:
Issue Found:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant AdalineTracer
participant Gateway
participant NodeTracerProvider
participant BatchSpanProcessor
participant AdalineTraceExporter
participant AdalineAPI as Adaline Trace API
User->>AdalineTracer: new AdalineTracer(options)
AdalineTracer->>AdalineTraceExporter: new AdalineTraceExporter(options)
AdalineTracer->>NodeTracerProvider: new NodeTracerProvider(resource)
AdalineTracer->>BatchSpanProcessor: new BatchSpanProcessor(exporter)
AdalineTracer->>NodeTracerProvider: addSpanProcessor(processor)
AdalineTracer->>NodeTracerProvider: getTracer('adaline-gateway')
NodeTracerProvider-->>AdalineTracer: tracer
User->>Gateway: new Gateway({ telemetry: { tracer } })
Gateway->>Gateway: TelemetryManager.setTracer(tracer)
User->>Gateway: completeChat(request)
Gateway->>Gateway: tracer.startActiveSpan('complete-chat')
Gateway->>Gateway: Execute LLM call
Gateway->>Gateway: span.end()
Gateway->>BatchSpanProcessor: Queue span
BatchSpanProcessor->>AdalineTraceExporter: export(spans)
AdalineTraceExporter->>AdalineTraceExporter: groupSpansByTrace(spans)
AdalineTraceExporter->>AdalineTraceExporter: sendTrace(traceId, spans)
AdalineTraceExporter->>AdalineTraceExporter: convertSpan(span)
AdalineTraceExporter->>AdalineAPI: POST /v2/api/logs/trace
AdalineAPI-->>AdalineTraceExporter: 200 OK
AdalineTraceExporter-->>BatchSpanProcessor: ExportResultCode.SUCCESS
User->>AdalineTracer: shutdown()
AdalineTracer->>NodeTracerProvider: shutdown()
NodeTracerProvider->>BatchSpanProcessor: shutdown()
BatchSpanProcessor->>AdalineTraceExporter: forceFlush()
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 1 comment
| const response = await fetch(this.endpoint, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Authorization': `Bearer ${this.apiKey}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify(trace), | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: timeout option is not applied to the fetch call
| const response = await fetch(this.endpoint, { | |
| method: 'POST', | |
| headers: { | |
| 'Authorization': `Bearer ${this.apiKey}`, | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(trace), | |
| }); | |
| const controller = new AbortController(); | |
| const timeoutId = setTimeout(() => controller.abort(), this.timeout); | |
| try { | |
| const response = await fetch(this.endpoint, { | |
| method: 'POST', | |
| headers: { | |
| 'Authorization': `Bearer ${this.apiKey}`, | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(trace), | |
| signal: controller.signal, | |
| }); | |
| clearTimeout(timeoutId); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: core/gateway/src/plugins/telemetry/adaline-trace.exporter.ts
Line: 164:171
Comment:
**logic:** `timeout` option is not applied to the fetch call
```suggestion
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
try {
const response = await fetch(this.endpoint, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(trace),
signal: controller.signal,
});
clearTimeout(timeoutId);
```
How can I resolve this? If you propose a fix, please make it concise.|
A question for this is how we should generally handle the 1MB limit with Adaline trace. I've ran into this issue before. |
|
is this tested? The package doesnt builds with this changes for me! related logs |
Adds native support for exporting OpenTelemetry traces to Adaline Trace, the hosted observability platform for LLM applications.
Changes:
Features:
Usage:
All Gateway operations are automatically traced with full observability: model names, cache hits, latency, time-to-first-token, and span hierarchies.