forked from phoenix/litellm-mirror
test otel
This commit is contained in:
parent
e2c3b2b694
commit
15d35cd62f
2 changed files with 31 additions and 7 deletions
|
@ -38,6 +38,25 @@ async def get_otel_spans():
|
|||
|
||||
print("Spans: ", recorded_spans) # noqa
|
||||
|
||||
most_recent_parent = None
|
||||
most_recent_start_time = 1000000
|
||||
spans_grouped_by_parent = {}
|
||||
for span in recorded_spans:
|
||||
if span.parent is not None:
|
||||
parent_trace_id = span.parent.trace_id
|
||||
if parent_trace_id not in spans_grouped_by_parent:
|
||||
spans_grouped_by_parent[parent_trace_id] = []
|
||||
spans_grouped_by_parent[parent_trace_id].append(span.name)
|
||||
|
||||
# check time of span
|
||||
if span.start_time > most_recent_start_time:
|
||||
most_recent_parent = parent_trace_id
|
||||
most_recent_start_time = span.start_time
|
||||
|
||||
# these are otel spans - get the span name
|
||||
span_names = [span.name for span in recorded_spans]
|
||||
return {"otel_spans": span_names}
|
||||
return {
|
||||
"otel_spans": span_names,
|
||||
"spans_grouped_by_parent": spans_grouped_by_parent,
|
||||
"most_recent_parent": most_recent_parent,
|
||||
}
|
||||
|
|
|
@ -100,12 +100,17 @@ async def test_chat_completion_check_otel_spans():
|
|||
print("otel_spans: ", otel_spans)
|
||||
|
||||
all_otel_spans = otel_spans["otel_spans"]
|
||||
most_recent_parent = str(otel_spans["most_recent_parent"])
|
||||
print("Most recent OTEL parent: ", most_recent_parent)
|
||||
print("\n spans grouped by parent: ", otel_spans["spans_grouped_by_parent"])
|
||||
parent_trace_spans = otel_spans["spans_grouped_by_parent"][most_recent_parent]
|
||||
|
||||
assert len(all_otel_spans) == 5
|
||||
print("Parent trace spans: ", parent_trace_spans)
|
||||
|
||||
assert len(parent_trace_spans) == 4
|
||||
|
||||
# 'postgres', 'redis', 'raw_gen_ai_request', 'litellm_request', 'Received Proxy Server Request' in the span
|
||||
assert "postgres" in all_otel_spans
|
||||
assert "redis" in all_otel_spans
|
||||
assert "raw_gen_ai_request" in all_otel_spans
|
||||
assert "litellm_request" in all_otel_spans
|
||||
assert "Received Proxy Server Request" in all_otel_spans
|
||||
assert "postgres" in parent_trace_spans
|
||||
assert "redis" in parent_trace_spans
|
||||
assert "raw_gen_ai_request" in parent_trace_spans
|
||||
assert "litellm_request" in parent_trace_spans
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue