agentbill-sdk 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a5d6d3184f1e30d721acd50e8b51ac947d086352bdd4f3f26702adc127b021c
4
- data.tar.gz: 57eb001ae9a6ba61c002855ad1abbe17fe14fcc3c8fc269b55903b780da669d2
3
+ metadata.gz: 17b96a78039bd5ad557ee6abc8606a2240e9e4d9e69a496fd1fa99bd3d1814a1
4
+ data.tar.gz: e126680a47d95e27ec984f94cba1631ed86c056111a1b40f2e7226c9cb274432
5
5
  SHA512:
6
- metadata.gz: 686aef33e7ff8e70994ffe7ad034beddea13b5adf6fc9cd072288898c253f64c49aae92a28c7068f3de4252304b5b6ed5a86698886a87353ce3912afabb870b2
7
- data.tar.gz: 2a86b18d8ea9a824fc2de991ae25f7f83473eda13f9ffaa96e6e451d1cca0729fa6cc3d3331e6a292a94e31fb604643b651e23697bbeec96dde6de6cae2d3c1f
6
+ metadata.gz: 2d465e3290f46ce834684c4960d78b61041d562f6378b2c234df7713d41d9927809559f2c907ab49fa10110c24c7ab16f50ec4a3203e2d0b8e64cb605c980637
7
+ data.tar.gz: c29f3c706608e6e43659aff341a89d6f809ebda394c18edf1e7f6bd99c3256569bb2dbb2714bd855ec8c248cea3d7a0c7ade528e902f87da8f9064d90a5076c6
@@ -0,0 +1,56 @@
1
+ name: Publish to RubyGems
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'ruby-v*'
7
+ workflow_dispatch:
8
+ inputs:
9
+ version:
10
+ description: 'Version to publish'
11
+ required: true
12
+
13
+ jobs:
14
+ publish:
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ contents: read
18
+ id-token: write
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: '3.2'
27
+ bundler-cache: true
28
+
29
+ - name: Install dependencies
30
+ run: bundle install
31
+
32
+ - name: Run tests
33
+ run: bundle exec rake test
34
+
35
+ - name: Build gem
36
+ run: gem build agentbill.gemspec
37
+
38
+ - name: Publish to RubyGems
39
+ run: |
40
+ mkdir -p $HOME/.gem
41
+ touch $HOME/.gem/credentials
42
+ chmod 0600 $HOME/.gem/credentials
43
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
44
+ gem push *.gem
45
+ env:
46
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
47
+
48
+ - name: Create GitHub Release
49
+ uses: actions/create-release@v1
50
+ env:
51
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52
+ with:
53
+ tag_name: ${{ github.ref }}
54
+ release_name: Ruby SDK ${{ github.ref }}
55
+ draft: false
56
+ prerelease: false
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.2] - 2025-10-27
9
+
10
+ ### Changed
11
+ - Version bump for consistency across SDKs
12
+
8
13
  ## [1.0.0] - 2025-10-21
9
14
 
10
15
  ### Added
data/README.md CHANGED
@@ -4,10 +4,10 @@ OpenTelemetry-based SDK for automatically tracking and billing AI agent usage.
4
4
 
5
5
  ## Installation
6
6
 
7
- ### From GitHub (Recommended)
7
+ ### From RubyGems (Recommended)
8
8
  ```ruby
9
9
  # In your Gemfile
10
- gem 'agentbill', git: 'https://github.com/Agent-Bill/Ruby.git'
10
+ gem 'agentbill-sdk'
11
11
  ```
12
12
 
13
13
  ### From RubyGems
@@ -0,0 +1,45 @@
1
+ require 'agentbill'
2
+
3
+ # Initialize AgentBill
4
+ agentbill = AgentBill::Client.init({
5
+ api_key: ENV['AGENTBILL_API_KEY'] || 'your-api-key',
6
+ base_url: ENV['AGENTBILL_BASE_URL'],
7
+ customer_id: 'customer-123',
8
+ debug: true
9
+ })
10
+
11
+ # Start a span for a database query
12
+ span = agentbill.tracer.start_span('database_query', {
13
+ 'db.system' => 'postgresql',
14
+ 'db.operation' => 'SELECT',
15
+ 'db.table' => 'users'
16
+ })
17
+
18
+ # Simulate work
19
+ sleep(0.1)
20
+
21
+ # Add more attributes during execution
22
+ span.set_attributes({
23
+ 'db.rows_returned' => 42,
24
+ 'query.duration_ms' => 95
25
+ })
26
+
27
+ # Set status (1 = success, 2 = error)
28
+ span.set_status(1)
29
+ span.end
30
+
31
+ # Start another span for an API call
32
+ api_span = agentbill.tracer.start_span('external_api_call', {
33
+ 'http.method' => 'POST',
34
+ 'http.url' => 'https://api.example.com/endpoint',
35
+ 'http.status_code' => 200
36
+ })
37
+
38
+ sleep(0.2)
39
+ api_span.set_status(1)
40
+ api_span.end
41
+
42
+ # Flush all spans to AgentBill
43
+ agentbill.flush
44
+
45
+ puts "✅ OTEL spans tracked successfully!"
@@ -1,3 +1,3 @@
1
1
  module AgentBill
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/agentbill.rb CHANGED
@@ -86,16 +86,44 @@ module AgentBill
86
86
  client
87
87
  end
88
88
 
89
- def track_signal(event_name:, revenue: 0, data: {})
89
+ # Track a comprehensive signal with all 68 parameters
90
+ #
91
+ # Supports all parameters:
92
+ # - event_name (required)
93
+ # - data_source, timestamp
94
+ # - agent_external_id, customer_external_id, account_external_id, user_external_id,
95
+ # order_external_id, session_id, conversation_id, thread_id
96
+ # - model, provider, prompt_hash, prompt_sample, response_sample, function_name, tool_name
97
+ # - prompt_tokens, completion_tokens, total_tokens, streaming_tokens, cached_tokens, reasoning_tokens
98
+ # - latency_ms, time_to_first_token, time_to_action_ms, queue_time_ms, processing_time_ms
99
+ # - revenue, cost, conversion_value, revenue_source
100
+ # - experiment_id, experiment_group, variant_id, ab_test_name
101
+ # - conversion_type, conversion_step, funnel_stage, goal_achieved
102
+ # - feedback_score, user_satisfaction, error_type, error_message, retry_count, success_rate
103
+ # - tags, category, priority, severity, compliance_flag, data_classification
104
+ # - product_id, feature_flag, environment, deployment_version, region, tenant_id
105
+ # - parent_span_id, trace_id
106
+ # - custom_dimensions, metadata, data
107
+ #
108
+ # Example:
109
+ # agentbill.track_signal(
110
+ # event_name: "user_conversion",
111
+ # revenue: 99.99,
112
+ # customer_external_id: "cust_123",
113
+ # experiment_id: "exp_abc",
114
+ # conversion_type: "purchase",
115
+ # tags: ["checkout", "success"]
116
+ # )
117
+ def track_signal(**params)
118
+ raise ArgumentError, "event_name is required" unless params[:event_name]
119
+
90
120
  uri = URI("#{@config[:base_url] || 'https://bgwyprqxtdreuutzpbgw.supabase.co'}/functions/v1/record-signals")
91
121
 
92
- payload = {
93
- event_name: event_name,
94
- revenue: revenue,
95
- customer_id: @config[:customer_id],
96
- timestamp: Time.now.to_i,
97
- data: data
98
- }
122
+ # Add timestamp if not provided
123
+ params[:timestamp] ||= Time.now.to_f
124
+
125
+ # Remove nil values
126
+ payload = params.reject { |_, v| v.nil? }
99
127
 
100
128
  begin
101
129
  http = Net::HTTP.new(uri.host, uri.port)
@@ -109,12 +137,15 @@ module AgentBill
109
137
  response = http.request(request)
110
138
 
111
139
  if @config[:debug]
112
- puts "[AgentBill] Signal tracked: #{event_name}, revenue: $#{revenue}"
140
+ puts "[AgentBill] Signal tracked: #{params[:event_name]}"
113
141
  end
142
+
143
+ response.code == '200'
114
144
  rescue => e
115
145
  if @config[:debug]
116
146
  puts "[AgentBill] Failed to track signal: #{e.message}"
117
147
  end
148
+ false
118
149
  end
119
150
  end
120
151
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agentbill-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - AgentBill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-24 00:00:00.000000000 Z
11
+ date: 2025-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,6 +50,7 @@ files:
50
50
  - ".github/ISSUE_TEMPLATE/feature_request.md"
51
51
  - ".github/pull_request_template.md"
52
52
  - ".github/workflows/ci.yml"
53
+ - ".github/workflows/publish.yml"
53
54
  - ".gitignore"
54
55
  - ".rspec"
55
56
  - ".rubocop.yml"
@@ -63,6 +64,7 @@ files:
63
64
  - SECURITY.md
64
65
  - agentbill.gemspec
65
66
  - examples/anthropic_basic.rb
67
+ - examples/manual_otel_tracking.rb
66
68
  - examples/openai_basic.rb
67
69
  - lib/agentbill.rb
68
70
  - lib/agentbill/tracer.rb