Skip to content

Bug Report: LangChain Metrics issues #2166

@nirga

Description

@nirga
  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 #2154 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions