Skip to content

πŸš€ Feature: Emit events for langchain state, tool call input/outputΒ #3435

@josephwangrb

Description

@josephwangrb

Which component is this feature for?

Langchain Instrumentation

πŸ”– Feature description

Emit events to capture chain level and tool call input&output.

🎀 Why is this feature needed ?

Currently, the OpenLLMetry LangChain instrumentation captures spans for chain and tool executions, including metadata such as input/output and timing information. However, it does not emit events for the input/output corresponding to key lifecycle points such as:

  • Chain start

  • Chain end

  • Tool start

  • Tool end

I noticed that we did add input/output as span attributes, but this logic should also emit them as events when should_emit_events return true? refer to: https://github.com/traceloop/openllmetry/blob/main/packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py#L420

✌️ How do you aim to achieve this?

When should_emit_events return true and should_send_prompts returns true, we emit input/output as events.

For example

        if should_emit_events() and should_send_prompts():
            emit_event(
                ToolEndEvent(
                    message=json.dumps(
                        {"outputs": outputs, "kwargs": kwargs},
                        cls=CallbackFilteredJSONEncoder,
                    ),
                )

πŸ”„οΈ Additional Information

It looks like the OpenTelemetry GenAI semantic conventions don’t currently define events for chain or tool lifecycle stages. Should OpenLLMetry aim to strictly follow the spec, or would it make sense to introduce a few practical extensions like this?

πŸ‘€ Have you spent some time to check if this feature request has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions