Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ puts result.text # Generated text response
The gem supports OpenTelemetry integration for monitoring and observability. You can configure telemetry settings to control what data is recorded and add metadata for better tracing:

**Telemetry Options:**
- `is_enabled`: Enable/disable telemetry (default: false)
- `record_inputs`: Record input messages (default: true, disable for sensitive data)
- `record_outputs`: Record output responses (default: true, disable for sensitive data)
- `enabled`: Enable/disable telemetry (default: true)
- `record_inputs`: Record input messages (default: false, disable for sensitive data)
- `record_outputs`: Record output responses (default: false, disable for sensitive data)
- `function_id`: Identifier for grouping telemetry data by function
- `metadata`: Additional metadata for OpenTelemetry traces (agent identification, service info, etc.)


```ruby
# Create telemetry settings
telemetry_settings = Ai::TelemetrySettings.new(
is_enabled: true,
enabled: true,
record_inputs: false, # Disable for sensitive data
record_outputs: true, # Enable for monitoring
function_id: 'user-chat-session',
Expand Down
8 changes: 7 additions & 1 deletion lib/ai/clients/mastra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def workflow(workflow_name)

private

sig { params(options: T::Hash[Symbol, T.anything]).returns(T::Hash[Symbol, T.anything]) }
def deep_camelize_keys(options)
json_options = JSON.parse(options.to_json)
json_options.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym }
end

sig do
params(
url: URI::Generic,
Expand Down Expand Up @@ -160,7 +166,7 @@ def response(url:, messages:, options:)
request['Origin'] = Ai.config.origin

# convert to camelCase and unpacking for API compatibility
camelized_options = options.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym }
camelized_options = deep_camelize_keys(options)
request.body = { messages: messages, **camelized_options }.to_json

response = http.request(request)
Expand Down
12 changes: 11 additions & 1 deletion lib/ai/types/telemetry_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module Ai
class TelemetrySettings < T::Struct
extend T::Sig

# Enable or disable telemetry. Enabled by default.
const :is_enabled, T::Boolean, default: true
const :enabled, T::Boolean, default: true

# Enable or disable input recording. You might want to disable this to avoid
# recording sensitive information, reduce data transfers, or increase performance.
Expand All @@ -23,5 +25,13 @@ class TelemetrySettings < T::Struct
# Custom OpenTelemetry tracer instance to use for the telemetry data.
# Note: In Ruby implementation, this would typically be configured at the client level
const :tracer, T.nilable(T.anything), default: nil

# Override as_json to automatically convert enabled to is_enabled for API compatibility
sig { returns(T::Hash[String, T.anything]) }
def as_json
serialize.tap do |hash|
hash['is_enabled'] = hash.delete('enabled')
end
end
end
end
34 changes: 18 additions & 16 deletions spec/fixtures/vcr_cassettes/mastra_generate_agent_object.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading