traceloop / traceloop/openllmetry

Bug Report: LangChain Metrics issues

Open
#2,166 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
7.4k
Forks
1.1k
Avg merge
8d 14h
Merged PRs (30d)
2

Description

  1. I see that we are adding custom attributes to metrics, However, TRACELOOP_ENTITY_NAME (traceloop.entity.name) is a very high cardinality attribute - https://github.com/traceloop/openllmetry/pull/2154/files#diff-caff857eafc9121a585e40cdac1c0815d97f474cd3d0bf1a23755572e3b38105R473
  • Most destinations would have limits on such fields with very high cardinality for metrics.
  • I feel this kind of information is best understood with traces/spans instead or at-least some control should be given to enable/disable this metric as required or limit attributes.
  1. Seeing this error generated for gen_ai.response.model when invoked as a agent.
Failed to encode key gen_ai.response.model: Invalid type <class 'NoneType'> of value None
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 113, in _encode_attributes
    pb2_attributes.append(_encode_key_value(key, value))
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 94, in _encode_key_value
    return PB2KeyValue(key=key, value=_encode_value(value))
                                      ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 90, in _encode_value
    raise Exception(f"Invalid type {type(value)} of value {value}")
Exception: Invalid type <class 'NoneType'> of value None
  1. I do not see gen_ai.client.token.usage being generated when used like below, I do see it generated with simple LLMChain but not when invoked via agent.
    llm = AzureChatOpenAI(
        openai_api_version=os.environ.get("AZURE_OPENAI_VERSION"),
        azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
        azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
        api_key=os.environ.get("AZURE_OPENAI_KEY"),
        model="gpt-4"
        )
    event_message = "this is a test"
    tools = [Tool().useless_tool]
    
    agent_template = categorise_event_prompt
    input_template = "{input}"
    
    prompt = ChatPromptTemplate.from_messages([
        ("system", agent_template),
        ("human", input_template),
        MessagesPlaceholder("agent_scratchpad")
    ])
    agent = create_openai_tools_agent(llm=llm, tools=tools, prompt=prompt)
    agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
    result = agent_executor.invoke({"input": event_message})

Originally posted by @nitin302 in https://github.com/traceloop/openllmetry/issues/2154#issuecomment-2418772694

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the AzureChatOpenAI agent example using create_openai_tools_agent and AgentExecutor, then inspect the instrumentation path that emits metrics and gen_ai attributes. Compare the agent behavior with the simple LLMChain case and the OTLP encoding error. Done means the reported high-cardinality, None-valued, and missing-token-usage cases are addressed or clearly scoped with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, python
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.