Skip to content

Create a base AIM subscriber to abstract handling Llm* events #3487

@amychisholm03

Description

@amychisholm03

Description

We have begun to move a few AIM packages over to subscriber-based, namely openai and @google/genai (at the time of writing). They reuse similar logic; it would be useful to have a base class that encapsulates this behavior.

Some features of this new base AIM subscriber:

  • Subscriber.enabled is set to super.enabled && this.agent?.config?.ai_monitoring?.enabled or super.enabled && this.agent?.config?.ai_monitoring?.streaming?.enabled for streams
  • Same function names, like instrumentStream, addLlmMeta, recordEvent, and recordChatCompletionMessages. These can be defined in the base AIM subscriber as no-ops and then implemented in its children classes (e.g. OpenAISubscriber).
  • handler(data,ctx) for a chat completions subscriber typically just creates a segment with name AI_PREFIX.COMPLETION. The base AIM subscriber could default to this behavior.
  • Similarly for AI_PREFIX.EMBEDDING too
  • Previous instrumentation checked against agent.config for the ai_monitoring value. Most subscribers just use config because they don't expect agent.config to change at runtime. I would suggest a getter for config that equates to agent.config to avoid this potential oversight.

Acceptance Criteria

  • A base subscriber for AIM is created that standardizes how we handle AI packages in subscribers.
  • All instances of agent.config are replaced with config to avoid redundancy
  • Relevant unit tests are created

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Reviewed

Relationships

None yet

Development

No branches or pull requests

Issue actions