traceloop-sdk 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/traceloop/sdk.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef7f96edbf9739fbb0a916f70b76e96d46dbd51a0968296be422a274ed0419e2
|
4
|
+
data.tar.gz: 539dad2f13ce3d802da2b156528a0dcd482c753a576d53d98f96976422927389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24df823be0d6409af0deabbaef16be493f52676372824ab5d7676085ae03a60ac3e503ef1c139063f9e934c98c980592eb84c2f307f10572d07f0c654a385db8
|
7
|
+
data.tar.gz: 13d57f55b9d4ada1346dbd7909b59c9a65a6561f915595323918b7afd8555707bda4f8fdc3a533fbb3fd5b494d80a496c194ec8e51fb1051157ec3b5201ee0d7
|
data/lib/traceloop/sdk.rb
CHANGED
@@ -50,6 +50,8 @@ module Traceloop
|
|
50
50
|
# https://github.com/gbaptista/gemini-ai?tab=readme-ov-file#generate_content
|
51
51
|
if response.has_key?("candidates")
|
52
52
|
log_gemini_response(response)
|
53
|
+
elsif response.has_key?("body")
|
54
|
+
log_bedrock_response(response)
|
53
55
|
else
|
54
56
|
log_openai_response(response)
|
55
57
|
end
|
@@ -66,6 +68,32 @@ module Traceloop
|
|
66
68
|
})
|
67
69
|
end
|
68
70
|
|
71
|
+
def log_bedrock_response(response)
|
72
|
+
body = JSON.parse(response.body.read())
|
73
|
+
|
74
|
+
@span.add_attributes({
|
75
|
+
OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_RESPONSE_MODEL => body.dig("model"),
|
76
|
+
})
|
77
|
+
if body.has_key?("usage")
|
78
|
+
input_tokens = body.dig("usage", "input_tokens")
|
79
|
+
output_tokens = body.dig("usage", "output_tokens")
|
80
|
+
|
81
|
+
@span.add_attributes({
|
82
|
+
OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_USAGE_TOTAL_TOKENS => input_tokens + output_tokens,
|
83
|
+
OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_USAGE_COMPLETION_TOKENS => output_tokens,
|
84
|
+
OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_USAGE_PROMPT_TOKENS => input_tokens,
|
85
|
+
})
|
86
|
+
end
|
87
|
+
if body.has_key?("content")
|
88
|
+
@span.add_attributes({
|
89
|
+
"#{OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_COMPLETIONS}.0.role" => body.dig("role"),
|
90
|
+
"#{OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_COMPLETIONS}.0.content" => body.dig("content").first.dig("text")
|
91
|
+
})
|
92
|
+
end
|
93
|
+
|
94
|
+
response.body.rewind()
|
95
|
+
end
|
96
|
+
|
69
97
|
def log_openai_response(response)
|
70
98
|
@span.add_attributes({
|
71
99
|
OpenTelemetry::SemanticConventionsAi::SpanAttributes::LLM_RESPONSE_MODEL => response.dig("model"),
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traceloop-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Traceloop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-semantic_conventions_ai
|