Skip to content

Commit

Permalink
Merge branch '2.12' into backport-11173-to-2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
romainkomorndatadog authored Oct 28, 2024
2 parents 591fdc8 + 0307129 commit be4740d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
10 changes: 8 additions & 2 deletions ddtrace/internal/datadog/profiling/stack_v2/src/stack_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ _stack_v2_link_span(PyObject* self, PyObject* args, PyObject* kwargs)
uint64_t thread_id;
uint64_t span_id;
uint64_t local_root_span_id;
const char* span_type;
const char* span_type = nullptr;

PyThreadState* state = PyThreadState_Get();

Expand All @@ -104,10 +104,16 @@ _stack_v2_link_span(PyObject* self, PyObject* args, PyObject* kwargs)
static const char* const_kwlist[] = { "span_id", "local_root_span_id", "span_type", NULL };
static char** kwlist = const_cast<char**>(const_kwlist);

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "KKs", kwlist, &span_id, &local_root_span_id, &span_type)) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "KKz", kwlist, &span_id, &local_root_span_id, &span_type)) {
return NULL;
}

// From Python, span_type is a string or None, and when given None, it is passed as a nullptr.
static const std::string empty_string = "";
if (span_type == nullptr) {
span_type = empty_string.c_str();
}

ThreadSpanLinks::get_instance().link_span(thread_id, span_id, local_root_span_id, std::string(span_type));

Py_RETURN_NONE;
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/llmobs/_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def annotate(
if parameters is not None:
log.warning("Setting parameters is deprecated, please set parameters and other metadata as tags instead.")
cls._tag_params(span, parameters)
if input_data or output_data:
if input_data is not None or output_data is not None:
if span_kind == "llm":
cls._tag_llm_io(span, input_messages=input_data, output_messages=output_data)
elif span_kind == "embedding":
Expand Down Expand Up @@ -598,9 +598,9 @@ def _tag_text_io(cls, span, input_value=None, output_value=None):
"""Tags input/output values for non-LLM kind spans.
Will be mapped to span's `meta.{input,output}.values` fields.
"""
if input_value:
if input_value is not None:
span.set_tag_str(INPUT_VALUE, safe_json(input_value))
if output_value:
if output_value is not None:
span.set_tag_str(OUTPUT_VALUE, safe_json(output_value))

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
LLM Observability: This fix resolves an issue where input and output values equal to zero were not being annotated
on workflow, task, agent and tool spans when using `LLMObs.annotate`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
profiling: resolves an issue where endpoint profiling for stack v2 throws
``TypeError`` exception when it is given a ``Span`` with ``None`` span_type.
11 changes: 11 additions & 0 deletions tests/llmobs/test_llmobs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,17 @@ def test_annotate_input_string(LLMObs):
assert retrieval_span.get_tag(INPUT_VALUE) == "test_input"


def test_annotate_numeric_io(LLMObs):
with LLMObs.task() as task_span:
LLMObs.annotate(span=task_span, input_data=0, output_data=0)
assert task_span.get_tag(INPUT_VALUE) == "0"
assert task_span.get_tag(OUTPUT_VALUE) == "0"
with LLMObs.task() as task_span:
LLMObs.annotate(span=task_span, input_data=1.23, output_data=1.23)
assert task_span.get_tag(INPUT_VALUE) == "1.23"
assert task_span.get_tag(OUTPUT_VALUE) == "1.23"


def test_annotate_input_serializable_value(LLMObs):
with LLMObs.task() as task_span:
LLMObs.annotate(span=task_span, input_data=["test_input"])
Expand Down

0 comments on commit be4740d

Please sign in to comment.