Skip to content

Commit ae5b3f2

Browse files
committed
handle data fields the same everywhere
1 parent 0bea3de commit ae5b3f2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sentry_sdk/integrations/langchain.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,10 @@ def on_llm_start(
277277
)
278278
if should_send_default_pii() and self.include_prompts:
279279
set_data_normalized(span, SPANDATA.GEN_AI_REQUEST_MESSAGES, prompts)
280-
for k, v in DATA_FIELDS.items():
281-
if k in all_params:
282-
set_data_normalized(span, v, all_params[k])
280+
281+
for key, attribute in DATA_FIELDS.items():
282+
if key in all_params and all_params[key] is not None:
283+
set_data_normalized(span, attribute, all_params[key], unpack=False)
283284

284285
def on_chat_model_start(self, serialized, messages, *, run_id, **kwargs):
285286
# type: (SentryLangchainCallback, Dict[str, Any], List[List[BaseMessage]], UUID, Any) -> Any
@@ -311,7 +312,7 @@ def on_chat_model_start(self, serialized, messages, *, run_id, **kwargs):
311312
span.set_data(SPANDATA.GEN_AI_REQUEST_MODEL, model)
312313

313314
for key, attribute in DATA_FIELDS.items():
314-
if key in all_params:
315+
if key in all_params and all_params[key] is not None:
315316
set_data_normalized(span, attribute, all_params[key], unpack=False)
316317

317318
if should_send_default_pii() and self.include_prompts:
@@ -327,6 +328,9 @@ def on_chat_model_start(self, serialized, messages, *, run_id, **kwargs):
327328
def on_chat_model_end(self, response, *, run_id, **kwargs):
328329
# type: (SentryLangchainCallback, LLMResult, UUID, Any) -> Any
329330
"""Run when Chat Model ends running."""
331+
import ipdb
332+
333+
ipdb.set_trace()
330334
with capture_internal_exceptions():
331335
if not run_id:
332336
return
@@ -453,6 +457,9 @@ def on_llm_error(self, error, *, run_id, **kwargs):
453457
def on_chat_model_error(self, error, *, run_id, **kwargs):
454458
# type: (SentryLangchainCallback, Union[Exception, KeyboardInterrupt], UUID, Any) -> Any
455459
"""Run when Chat Model errors."""
460+
import ipdb
461+
462+
ipdb.set_trace()
456463
with capture_internal_exceptions():
457464
self._handle_error(run_id, error)
458465

0 commit comments

Comments
 (0)