gyliu513 / langX101

Apache License 2.0
6 stars 4 forks source link

Use decorator for OTEL related code #145

Closed gyliu513 closed 10 months ago

gyliu513 commented 10 months ago

If you take a look at langSmith https://docs.smith.langchain.com/ , it is using decorator to enable tracing.

from langsmith.run_helpers import traceable

@traceable(run_type="llm", name="openai.ChatCompletion.create")
def my_chat_model(*args: Any, **kwargs: Any) -> OpenAIObject:
    return openai.ChatCompletion.create(*args, **kwargs)

For the otel code here https://github.com/gyliu513/langX101/blob/main/otel/watsonx-programatic/watsonx-instrument.py#L1-L52 , we also need a decorator to enable customer do not need to always write those preparation code but use decorator to enable tracing with otel.

huang-cn commented 10 months ago

@gyliu513 I've found a way to resolve this, by optimizing the instrumentation code, now only 2 lines of code are required. https://github.com/gyliu513/langX101/blob/37bc0a990b558d331f0269ccc78f8b56ba2a9c21/otel/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/watsonx-langchain-simplify.py#L7-L18

Basically instead of letting the end user to perform those opentelemetry tracing/metering related routine code, I now use our Instrumentor to do it.

gyliu513 commented 10 months ago

@huang-cn can we use decorate for this code?

huang-cn commented 10 months ago

@gyliu513 as we've discussed this morning, using the decorator to wrap customer method/function is difficult for us to capture useful information because the feature/input/output of the customer method are unknown.