Skip to content

Commit 840eced

Browse files
ericapisaniclaude
andcommitted
test(langchain): Add pipeline name attribute assertions to on_llm_start tests
Add name kwarg to on_llm_start call in test_langchain_message_truncation and assert that gen_ai.pipeline.name is set correctly when a pipeline name is provided. Also add gen_ai.operation.name assertions to relevant tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b2fd97e commit 840eced

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sentry_sdk/integrations/langchain.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ def on_llm_start(
374374
)
375375
span = watched_span.span
376376

377+
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "generate_text")
378+
379+
pipeline_name = kwargs.get("name")
380+
if pipeline_name:
381+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, pipeline_name)
382+
377383
if model:
378384
span.set_data(
379385
SPANDATA.GEN_AI_REQUEST_MODEL,

tests/integrations/langchain/test_langchain.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ def test_langchain_message_truncation(sentry_init, capture_events):
10401040
serialized=serialized,
10411041
prompts=prompts,
10421042
run_id=run_id,
1043+
name="my_pipeline",
10431044
invocation_params={
10441045
"temperature": 0.7,
10451046
"max_tokens": 100,
@@ -1069,8 +1070,10 @@ def test_langchain_message_truncation(sentry_init, capture_events):
10691070
assert len(llm_spans) > 0
10701071

10711072
llm_span = llm_spans[0]
1072-
assert SPANDATA.GEN_AI_REQUEST_MESSAGES in llm_span["data"]
1073+
assert llm_span["data"]["gen_ai.operation.name"] == "generate_text"
1074+
assert llm_span["data"][SPANDATA.GEN_AI_PIPELINE_NAME] == "my_pipeline"
10731075

1076+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES in llm_span["data"]
10741077
messages_data = llm_span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
10751078
assert isinstance(messages_data, str)
10761079

@@ -1783,6 +1786,7 @@ def test_langchain_response_model_extraction(
17831786
assert len(llm_spans) > 0
17841787

17851788
llm_span = llm_spans[0]
1789+
assert llm_span["data"]["gen_ai.operation.name"] == "generate_text"
17861790

17871791
if expected_model is not None:
17881792
assert SPANDATA.GEN_AI_RESPONSE_MODEL in llm_span["data"]

0 commit comments

Comments
 (0)