Create OTel Exporter for LangChain tracing - #1568
Conversation
| [tool.poetry] | ||
| name = "langsmith" | ||
| version = "0.3.13" | ||
| version = "0.3.14rc1" |
There was a problem hiding this comment.
will rebase to current version before merging
There was a problem hiding this comment.
I'm not up to speed with the gen ai OTEL semantic conventions but looks reasonable (cc Alex Kira (@akira) to review more)
| if client.otel_exporter is not None: | ||
| _otel_tracing_thread_handle_batch(client, tracing_queue, next_batch) | ||
| else: | ||
| _tracing_thread_handle_batch( |
There was a problem hiding this comment.
is it possible to have both OTEL and regular LangSmith tracing or would only go to one or the other?
There was a problem hiding this comment.
one or the other, but ls accepts the otel messages
There was a problem hiding this comment.
ack on "one or the other", but the latter point "accepts the otel messages" is probably not that useful unless I missed something.
If you run it with opentelemetry-instrument to bootstrap the otel exporters, both langsmith and other instrumentation will export to the same collector. That's true.
However, they will be in different traces as the tracer implementation here is an export only-concern. Meaning it cannot propagate trace context to normal otel instrumentation. For that reason, they'd be in different traces, and likely less useful as a result.
There was a problem hiding this comment.
Adrian Cole (@codefromthecrypt) I was referring to LangSmith if a user wanted to fan out on receiver to multiple OTel backends. ack that this implementation is export only, but it should still be possible to inject headers into LangSmith OTel tracing. Would be happy to work with you as a design partner to discuss future features for distributed tracing with you though!
| # Set GenAI attributes according to OTEL semantic conventions | ||
| # Set gen_ai.operation.name | ||
| operation_name = run_info.get("run_type", "chain") | ||
| span.set_attribute(GEN_AI_OPERATION_NAME, operation_name) |
There was a problem hiding this comment.
what are the mappings for this, would it come through as "chat", etc?
There was a problem hiding this comment.
mapping in _get_operation_name
|
|
||
| # Additional GenAI attributes | ||
| GEN_AI_REQUEST_STREAMING = "gen_ai.request.streaming" | ||
| GEN_AI_REQUEST_HEADERS = "gen_ai.request.headers" |
There was a problem hiding this comment.
are these genai semconv or should they be langsmith prefixed?
There was a problem hiding this comment.
langsmith prefixed
Add OpenTelemetry Export Support to LangSmith
Purpose
Folks want to natively trace LangChain and LangGraph through our sdk. The implementation follows OpenTelemetry GenAI Semantic Conventions
Usage
The OTEL integration can be enabled by:
Installing the OTEL dependencies:
pip install langsmith[otel]Setting environment variable:
LANGSMITH_OTEL_ENABLED=trueBy default, the exporter will send data to the LangSmith API OTEL endpoint, but this can be customized by setting standard OTEL environment variables:
Depends on https://github.com/langchain-ai/langchainplus/pull/8582 (including integration test passing)