Skip to content

Commit 6b1ba71

Browse files
committed
feat(instrumentation-llamaindex): migrate to OTel 1.40 GenAI semantic conventions
1 parent 51cd26b commit 6b1ba71

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packages/instrumentation-llamaindex/src/custom-llm-instrumentation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const openAIFinishReasonMap: Record<string, string> = {
6060

6161
export class CustomLLMInstrumentation {
6262
constructor(
63-
private config: LlamaIndexInstrumentationConfig,
63+
private config: () => LlamaIndexInstrumentationConfig,
6464
private diag: DiagLogger,
6565
private tracer: () => Tracer,
6666
) {}
@@ -90,15 +90,15 @@ export class CustomLLMInstrumentation {
9090
GEN_AI_OPERATION_NAME_VALUE_CHAT,
9191
);
9292
span.setAttribute(ATTR_GEN_AI_REQUEST_TOP_P, this.metadata.topP);
93-
if (shouldSendPrompts(plugin.config) && messages) {
93+
if (shouldSendPrompts(plugin.config()) && messages) {
9494
span.setAttribute(
9595
ATTR_GEN_AI_INPUT_MESSAGES,
9696
formatInputMessages(messages, mapOpenAIContentBlock),
9797
);
9898
}
9999
} catch (e) {
100100
plugin.diag.warn(e);
101-
plugin.config.exceptionLogger?.(e);
101+
plugin.config().exceptionLogger?.(e);
102102
}
103103

104104
const execContext = trace.setSpan(context.active(), span);
@@ -177,7 +177,7 @@ export class CustomLLMInstrumentation {
177177

178178
// output messages: content — always set inside shouldSendPrompts
179179
if (
180-
shouldSendPrompts(this.config) &&
180+
shouldSendPrompts(this.config()) &&
181181
(result as llamaindex.ChatResponse).message
182182
) {
183183
const content = (result as llamaindex.ChatResponse).message.content;
@@ -198,7 +198,7 @@ export class CustomLLMInstrumentation {
198198
span.setStatus({ code: SpanStatusCode.OK });
199199
} catch (e) {
200200
this.diag.warn(e);
201-
this.config.exceptionLogger?.(e);
201+
this.config().exceptionLogger?.(e);
202202
}
203203

204204
span.end();
@@ -244,7 +244,7 @@ export class CustomLLMInstrumentation {
244244
);
245245
}
246246

247-
if (shouldSendPrompts(this.config)) {
247+
if (shouldSendPrompts(this.config())) {
248248
span.setAttribute(
249249
ATTR_GEN_AI_OUTPUT_MESSAGES,
250250
formatOutputMessage(
@@ -258,7 +258,7 @@ export class CustomLLMInstrumentation {
258258
}
259259
} catch (e) {
260260
this.diag.warn(e);
261-
this.config.exceptionLogger?.(e);
261+
this.config().exceptionLogger?.(e);
262262
}
263263
span.setStatus({ code: SpanStatusCode.OK });
264264
span.end();

packages/instrumentation-llamaindex/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class LlamaIndexInstrumentation extends InstrumentationBase {
4141
constructor(config: LlamaIndexInstrumentationConfig = {}) {
4242
super("@traceloop/instrumentation-llamaindex", version, config);
4343
this.customLLMInstrumentation = new CustomLLMInstrumentation(
44-
this._config,
44+
() => this._config,
4545
this._diag,
4646
() => this.tracer,
4747
);

packages/instrumentation-llamaindex/test/instrumentation.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,10 @@ describe("CustomLLMInstrumentation — OTel 1.40 attributes", () => {
270270
});
271271

272272
function makeInstrumentation(traceContent = true) {
273-
return new CustomLLMInstrumentation({ traceContent }, noopDiag, () =>
274-
otelProvider.getTracer("test"),
273+
return new CustomLLMInstrumentation(
274+
() => ({ traceContent }),
275+
noopDiag,
276+
() => otelProvider.getTracer("test"),
275277
);
276278
}
277279

0 commit comments

Comments
 (0)