Skip to content

🚀 Feature: use metadata from invoke calls in Langchain to populate span attributes #3213

Closed

Description

@zmievsa-semasoftware

Which component is this feature for?

Langchain Instrumentation

🔖 Feature description

I'd like to add arbitrary data as an attribute for my events and extract it from metadata when using batch and abatch methods. However, currently it doesn't work: attributes do not get populated from metadata.

🎤 Why is this feature needed ?

Otherwise, when using batch, I have no way to correlate errors to data if I disabled prompts. I disable prompts in some places because the data there is sensitive but if an error happens -- we need to be able to at least get an identifier of this data.

✌️ How do you aim to achieve this?

Not sure yet, let's discuss.

🔄️ Additional Information

I tried using callbacks but they are applied outside of traceloop per-workflow span, not inside of it :(

👀 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?

None

Activity

  1. nirga commented on Aug 2, 2025

    @nirga
    Member

    Hey @zmievsa-semasoftware - can you give an example of how you pass those attributes?

  2. zmievsa commented on Aug 2, 2025

    @zmievsa

    Like so

            results = await commit_categorization_chain.abatch(
                [{"commit_data": json.dumps(commit, indent=2)} for commit in commits],
                config=[{"metadata": {"commit_id": commit.get("commit_id", "")}} for commit in commits],
            )
  3. nirga commented on Aug 2, 2025

    @nirga
    Member

    I believe we are adding the metadata to the trace as association properties. Is there a chance commit_id isn't serializable? Can you screenshot the span attributes of the span / trace you're getting?

  4. zmievsa commented on Aug 2, 2025

    @zmievsa

    It just attaches context but I am not sure that context is automatically added as attributes to spans. That would require you to register a custom span processor that adds these attributes to it during span creation such as what this package does but with baggage.

    Image

    The commit_id is 100% serializable: I tried to add the following code to the instrumentor just as a test and everything worked successfully: commit_id appeared in otel.

    Image
  5. nirga commented on Aug 2, 2025

    @nirga
    Member

    Oh I see now - we use the context to propagate the metadata to all spans - but we do that in the SDK - are you using the instrumentation directly?

  6. zmievsa commented on Aug 2, 2025

    @zmievsa

    Yup, I am :(

  7. zmievsa-semasoftware commented on Aug 3, 2025

    @zmievsa-semasoftware
    Author

    @nirga you are a rockstar! Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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