obtrace 1.0.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +113 -0
- data/lib/obtrace_sdk/client.rb +135 -0
- data/lib/obtrace_sdk/middleware.rb +60 -0
- data/lib/obtrace_sdk/otel_setup.rb +71 -0
- data/lib/obtrace_sdk/rails.rb +37 -0
- data/lib/obtrace_sdk/semantic_metrics.rb +55 -0
- data/lib/obtrace_sdk/types.rb +22 -0
- data/lib/obtrace_sdk/version.rb +3 -0
- data/lib/obtrace_sdk.rb +6 -0
- metadata +141 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 11e3b6be8a7149d814f0bd72270af0d4ed6b17e0cdfafbb86a4a599ab795385e
|
|
4
|
+
data.tar.gz: 5a38f50b81015f31611beb14fceb3790eed0af016c9481809470ab8d1c58b97e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '09cb6ae8a535940b98ba059ef5591ff4b72f67e131f2eef2f0581335db381a877d2d33bf46d2a250d28c7de68af08b5aa000807053af9c553fd2e104a884030b'
|
|
7
|
+
data.tar.gz: b9cced4a83a66ddf582a39d831b90a6ad8b4f0fcf7f58e6056ccd5be3c4b9bcd11a4180cca68edf1676a61fce655cffa414dc535588569171e729f970a1bbfe1
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Obtrace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# obtrace-sdk-ruby
|
|
2
|
+
|
|
3
|
+
Ruby backend SDK for Obtrace telemetry transport and instrumentation.
|
|
4
|
+
|
|
5
|
+
## Scope
|
|
6
|
+
- OTLP logs/traces/metrics transport
|
|
7
|
+
- Context propagation
|
|
8
|
+
- Rack/Rails middleware baseline
|
|
9
|
+
|
|
10
|
+
## Design Principle
|
|
11
|
+
SDK is thin/dumb.
|
|
12
|
+
- No business logic authority in client SDK.
|
|
13
|
+
- Policy and product logic are server-side.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# when published as gem
|
|
19
|
+
gem install obtrace-sdk-ruby
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Current workspace usage:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require_relative "lib/obtrace_sdk"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
Required:
|
|
31
|
+
- `api_key`
|
|
32
|
+
- `ingest_base_url`
|
|
33
|
+
- `service_name`
|
|
34
|
+
|
|
35
|
+
Optional (auto-resolved from API key on the server side):
|
|
36
|
+
- `tenant_id`
|
|
37
|
+
- `project_id`
|
|
38
|
+
- `app_id`
|
|
39
|
+
- `env`
|
|
40
|
+
- `service_version`
|
|
41
|
+
|
|
42
|
+
## Quickstart
|
|
43
|
+
|
|
44
|
+
### Simplified setup
|
|
45
|
+
|
|
46
|
+
The API key resolves `tenant_id`, `project_id`, `app_id`, and `env` automatically on the server side, so only three fields are needed:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
require "obtrace_sdk"
|
|
50
|
+
|
|
51
|
+
cfg = ObtraceSDK::Config.new(
|
|
52
|
+
api_key: "obt_live_...",
|
|
53
|
+
ingest_base_url: "https://ingest.obtrace.io",
|
|
54
|
+
service_name: "my-service"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
client = ObtraceSDK::Client.new(cfg)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Full configuration
|
|
61
|
+
|
|
62
|
+
For advanced use cases you can override the resolved values explicitly:
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
require_relative "lib/obtrace_sdk"
|
|
66
|
+
|
|
67
|
+
cfg = ObtraceSDK::Config.new(
|
|
68
|
+
api_key: "<API_KEY>",
|
|
69
|
+
ingest_base_url: "https://inject.obtrace.ai",
|
|
70
|
+
service_name: "ruby-api"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
client = ObtraceSDK::Client.new(cfg)
|
|
74
|
+
client.log("info", "started")
|
|
75
|
+
client.metric(ObtraceSDK::SemanticMetrics::RUNTIME_CPU_UTILIZATION, 0.41)
|
|
76
|
+
client.span("checkout.charge", attrs: {
|
|
77
|
+
"feature.name" => "checkout",
|
|
78
|
+
"payment.provider" => "stripe"
|
|
79
|
+
})
|
|
80
|
+
client.flush
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Canonical metrics and custom spans
|
|
84
|
+
|
|
85
|
+
- Use `ObtraceSDK::SemanticMetrics::*` for globally normalized metric names.
|
|
86
|
+
- Custom spans use `client.span("name", attrs: {...})`.
|
|
87
|
+
- Keep free-form metric names only for application-specific signals outside the shared catalog.
|
|
88
|
+
|
|
89
|
+
## Frameworks
|
|
90
|
+
|
|
91
|
+
- Rack-compatible middleware baseline for Rails usage
|
|
92
|
+
- Reference docs:
|
|
93
|
+
- `docs/frameworks.md`
|
|
94
|
+
|
|
95
|
+
## Production Hardening
|
|
96
|
+
|
|
97
|
+
1. Keep API keys in environment/secret managers.
|
|
98
|
+
2. Separate keys per environment.
|
|
99
|
+
3. Use graceful shutdown hooks to flush queue before exit.
|
|
100
|
+
4. Validate telemetry flow after deploy.
|
|
101
|
+
|
|
102
|
+
## Troubleshooting
|
|
103
|
+
|
|
104
|
+
- Missing telemetry: verify endpoint reachability and auth key.
|
|
105
|
+
- Missing correlation: ensure propagation headers are injected.
|
|
106
|
+
- Debug transport with `debug: true` in config.
|
|
107
|
+
|
|
108
|
+
## Documentation
|
|
109
|
+
- Docs index: `docs/index.md`
|
|
110
|
+
- LLM context file: `llm.txt`
|
|
111
|
+
- MCP metadata: `mcp.json`
|
|
112
|
+
|
|
113
|
+
## Reference
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "json"
|
|
3
|
+
require "uri"
|
|
4
|
+
require_relative "otel_setup"
|
|
5
|
+
|
|
6
|
+
module ObtraceSDK
|
|
7
|
+
class Client
|
|
8
|
+
@@initialized = false
|
|
9
|
+
|
|
10
|
+
attr_reader :tracer, :meter, :handshake_ok
|
|
11
|
+
|
|
12
|
+
def initialize(cfg)
|
|
13
|
+
if @@initialized
|
|
14
|
+
warn("[obtrace-sdk-ruby] already initialized, skipping duplicate init")
|
|
15
|
+
return
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
raise ArgumentError, "api_key, ingest_base_url and service_name are required" if cfg.api_key.to_s.empty? || cfg.ingest_base_url.to_s.empty? || cfg.service_name.to_s.empty?
|
|
19
|
+
|
|
20
|
+
@@initialized = true
|
|
21
|
+
@cfg = cfg
|
|
22
|
+
@handshake_ok = false
|
|
23
|
+
@tracer_provider = OtelSetup.configure(cfg)
|
|
24
|
+
@tracer = @tracer_provider.tracer("obtrace-sdk-ruby", ObtraceSDK::VERSION)
|
|
25
|
+
@meter = nil
|
|
26
|
+
@meter_warning_logged = false
|
|
27
|
+
|
|
28
|
+
begin
|
|
29
|
+
@meter = OpenTelemetry.meter_provider.meter("obtrace-sdk-ruby", ObtraceSDK::VERSION)
|
|
30
|
+
rescue => _e
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
Thread.new { perform_handshake }
|
|
34
|
+
at_exit { shutdown }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private def perform_handshake
|
|
38
|
+
base = @cfg.ingest_base_url.to_s.chomp("/")
|
|
39
|
+
return if base.empty?
|
|
40
|
+
uri = URI("#{base}/v1/init")
|
|
41
|
+
payload = JSON.generate({
|
|
42
|
+
sdk: "obtrace-sdk-ruby",
|
|
43
|
+
sdk_version: "1.0.0",
|
|
44
|
+
service_name: @cfg.service_name,
|
|
45
|
+
service_version: @cfg.service_version.to_s,
|
|
46
|
+
runtime: "ruby",
|
|
47
|
+
runtime_version: RUBY_VERSION,
|
|
48
|
+
})
|
|
49
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
50
|
+
http.use_ssl = uri.scheme == "https"
|
|
51
|
+
http.open_timeout = 5
|
|
52
|
+
http.read_timeout = 5
|
|
53
|
+
req = Net::HTTP::Post.new(uri)
|
|
54
|
+
req["Content-Type"] = "application/json"
|
|
55
|
+
req["Authorization"] = "Bearer #{@cfg.api_key}"
|
|
56
|
+
req.body = payload
|
|
57
|
+
resp = http.request(req)
|
|
58
|
+
if resp.code.to_i == 200
|
|
59
|
+
@handshake_ok = true
|
|
60
|
+
warn("[obtrace-sdk-ruby] init handshake OK") if @cfg.debug
|
|
61
|
+
elsif @cfg.debug
|
|
62
|
+
warn("[obtrace-sdk-ruby] init handshake failed: #{resp.code}")
|
|
63
|
+
end
|
|
64
|
+
rescue => e
|
|
65
|
+
warn("[obtrace-sdk-ruby] init handshake error: #{e.message}") if @cfg.debug
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def log(level, message, context = nil)
|
|
69
|
+
attributes = { "obtrace.log.level" => level.to_s }
|
|
70
|
+
if context
|
|
71
|
+
context.each { |k, v| attributes["obtrace.attr.#{k}"] = v.to_s }
|
|
72
|
+
end
|
|
73
|
+
attributes["log.severity"] = level.to_s.upcase
|
|
74
|
+
attributes["log.message"] = message.to_s
|
|
75
|
+
|
|
76
|
+
span = OpenTelemetry::Trace.current_span
|
|
77
|
+
if span && span.context.valid?
|
|
78
|
+
span.add_event("log", attributes: attributes)
|
|
79
|
+
else
|
|
80
|
+
@tracer.in_span("log.#{level}", attributes: attributes) { |_s| }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def metric(name, value, unit = "1", context = nil)
|
|
85
|
+
warn("[obtrace-sdk-ruby] non-canonical metric name: #{name}") if @cfg.validate_semantic_metrics && @cfg.debug && !SemanticMetrics.semantic_metric?(name)
|
|
86
|
+
|
|
87
|
+
unless @meter
|
|
88
|
+
unless @meter_warning_logged
|
|
89
|
+
warn("[obtrace-sdk-ruby] meter provider not available, metrics will be dropped")
|
|
90
|
+
@meter_warning_logged = true
|
|
91
|
+
end
|
|
92
|
+
return
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
attrs = {}
|
|
96
|
+
context&.each { |k, v| attrs[k.to_s] = v.to_s }
|
|
97
|
+
|
|
98
|
+
gauge = @meter.create_gauge(name.to_s, unit: unit.to_s)
|
|
99
|
+
gauge.set(value.to_f, attributes: attrs)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def span(name, attrs: nil, &block)
|
|
103
|
+
span_attrs = {}
|
|
104
|
+
if attrs
|
|
105
|
+
attrs.each { |k, v| span_attrs[k.to_s] = v.is_a?(Numeric) || v.is_a?(TrueClass) || v.is_a?(FalseClass) ? v : v.to_s }
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if block
|
|
109
|
+
@tracer.in_span(name.to_s, attributes: span_attrs) do |s|
|
|
110
|
+
block.call(s)
|
|
111
|
+
end
|
|
112
|
+
else
|
|
113
|
+
@tracer.in_span(name.to_s, attributes: span_attrs) { |_s| }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def capture_error(exception, context = nil)
|
|
118
|
+
exception = Exception.new(exception.to_s) unless exception.is_a?(Exception)
|
|
119
|
+
|
|
120
|
+
attrs = {}
|
|
121
|
+
context&.each { |k, v| attrs[k.to_s] = v.to_s }
|
|
122
|
+
|
|
123
|
+
@tracer.in_span("error", attributes: attrs) do |s|
|
|
124
|
+
s.record_exception(exception)
|
|
125
|
+
s.status = OpenTelemetry::Trace::Status.error(exception.message.to_s)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
alias_method :capture_exception, :capture_error
|
|
130
|
+
|
|
131
|
+
def shutdown
|
|
132
|
+
@tracer_provider.shutdown if @tracer_provider.respond_to?(:shutdown)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module ObtraceSDK
|
|
2
|
+
class Middleware
|
|
3
|
+
def initialize(app, client)
|
|
4
|
+
@app = app
|
|
5
|
+
@client = client
|
|
6
|
+
@tracer = client.tracer
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(env)
|
|
10
|
+
span_name = "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
|
|
11
|
+
|
|
12
|
+
extracted_context = extract_context(env)
|
|
13
|
+
|
|
14
|
+
span_attrs = {
|
|
15
|
+
"http.method" => env["REQUEST_METHOD"].to_s,
|
|
16
|
+
"http.target" => env["PATH_INFO"].to_s,
|
|
17
|
+
"http.host" => env["HTTP_HOST"].to_s,
|
|
18
|
+
"http.scheme" => (env["rack.url_scheme"] || "http").to_s,
|
|
19
|
+
"http.user_agent" => env["HTTP_USER_AGENT"].to_s,
|
|
20
|
+
"net.peer.ip" => (env["HTTP_X_FORWARDED_FOR"] || env["REMOTE_ADDR"]).to_s
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if env["QUERY_STRING"] && !env["QUERY_STRING"].empty?
|
|
24
|
+
span_attrs["http.query"] = env["QUERY_STRING"]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
OpenTelemetry::Context.with_current(extracted_context) do
|
|
28
|
+
@tracer.in_span(span_name, attributes: span_attrs, kind: :server) do |s|
|
|
29
|
+
begin
|
|
30
|
+
status, headers, body = @app.call(env)
|
|
31
|
+
s.set_attribute("http.status_code", status.to_i)
|
|
32
|
+
if status.to_i >= 500
|
|
33
|
+
s.status = OpenTelemetry::Trace::Status.error("HTTP #{status}")
|
|
34
|
+
end
|
|
35
|
+
[status, headers, body]
|
|
36
|
+
rescue => e
|
|
37
|
+
s.record_exception(e)
|
|
38
|
+
s.status = OpenTelemetry::Trace::Status.error(e.message.to_s)
|
|
39
|
+
s.set_attribute("http.status_code", 500)
|
|
40
|
+
raise
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def extract_context(env)
|
|
49
|
+
traceparent = env["HTTP_TRACEPARENT"]
|
|
50
|
+
return OpenTelemetry::Context.current unless traceparent
|
|
51
|
+
|
|
52
|
+
OpenTelemetry.propagation.extract(
|
|
53
|
+
env,
|
|
54
|
+
getter: OpenTelemetry::Common::Propagation.rack_env_getter
|
|
55
|
+
)
|
|
56
|
+
rescue
|
|
57
|
+
OpenTelemetry::Context.current
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require "opentelemetry/sdk"
|
|
2
|
+
require "opentelemetry-exporter-otlp"
|
|
3
|
+
|
|
4
|
+
module ObtraceSDK
|
|
5
|
+
module OtelSetup
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def configure(cfg)
|
|
9
|
+
endpoint = "#{cfg.ingest_base_url.to_s.sub(%r{/$}, "")}/otlp/v1/traces"
|
|
10
|
+
|
|
11
|
+
exporter = OpenTelemetry::Exporter::OTLP::Exporter.new(
|
|
12
|
+
endpoint: endpoint,
|
|
13
|
+
headers: {
|
|
14
|
+
"Authorization" => "Bearer #{cfg.api_key}"
|
|
15
|
+
}.merge(cfg.default_headers || {}),
|
|
16
|
+
timeout: cfg.request_timeout_sec
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
resource_attrs = {
|
|
20
|
+
"service.name" => cfg.service_name,
|
|
21
|
+
"service.version" => cfg.service_version,
|
|
22
|
+
"deployment.environment" => cfg.env || "dev",
|
|
23
|
+
"runtime.name" => "ruby"
|
|
24
|
+
}
|
|
25
|
+
resource_attrs["obtrace.tenant_id"] = cfg.tenant_id if cfg.tenant_id
|
|
26
|
+
resource_attrs["obtrace.project_id"] = cfg.project_id if cfg.project_id
|
|
27
|
+
resource_attrs["obtrace.app_id"] = cfg.app_id if cfg.app_id
|
|
28
|
+
resource_attrs["obtrace.env"] = cfg.env if cfg.env
|
|
29
|
+
|
|
30
|
+
OpenTelemetry::SDK.configure do |c|
|
|
31
|
+
c.resource = OpenTelemetry::SDK::Resources::Resource.create(resource_attrs)
|
|
32
|
+
c.add_span_processor(
|
|
33
|
+
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(exporter)
|
|
34
|
+
)
|
|
35
|
+
auto_detect_instrumentations(c)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
OpenTelemetry.propagation = OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator
|
|
39
|
+
|
|
40
|
+
OpenTelemetry.tracer_provider
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def auto_detect_instrumentations(config)
|
|
44
|
+
instrumentations = [
|
|
45
|
+
["OpenTelemetry::Instrumentation::Net::HTTP", "opentelemetry-instrumentation-net_http"],
|
|
46
|
+
["OpenTelemetry::Instrumentation::Rack", "opentelemetry-instrumentation-rack"],
|
|
47
|
+
["OpenTelemetry::Instrumentation::Rails", "opentelemetry-instrumentation-rails"],
|
|
48
|
+
["OpenTelemetry::Instrumentation::PG", "opentelemetry-instrumentation-pg"],
|
|
49
|
+
["OpenTelemetry::Instrumentation::Redis", "opentelemetry-instrumentation-redis"],
|
|
50
|
+
["OpenTelemetry::Instrumentation::Sidekiq", "opentelemetry-instrumentation-sidekiq"],
|
|
51
|
+
["OpenTelemetry::Instrumentation::Faraday", "opentelemetry-instrumentation-faraday"],
|
|
52
|
+
["OpenTelemetry::Instrumentation::ActiveRecord", "opentelemetry-instrumentation-active_record"]
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
threads = instrumentations.map do |class_name, gem_name|
|
|
56
|
+
Thread.new(class_name, gem_name) do |cn, gn|
|
|
57
|
+
begin
|
|
58
|
+
require gn.gsub("-", "/")
|
|
59
|
+
rescue LoadError
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
threads.each(&:join)
|
|
64
|
+
|
|
65
|
+
instrumentations.each do |class_name, gem_name|
|
|
66
|
+
klass = Object.const_get(class_name) rescue next
|
|
67
|
+
config.use(class_name) if klass
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "obtrace_sdk"
|
|
2
|
+
|
|
3
|
+
module ObtraceSDK
|
|
4
|
+
class Railtie < ::Rails::Railtie
|
|
5
|
+
config.after_initialize do |app|
|
|
6
|
+
api_key = Railtie.credentials_fetch("obtrace_api_key") || ENV["OBTRACE_API_KEY"]
|
|
7
|
+
ingest_url = Railtie.credentials_fetch("obtrace_ingest_url") || ENV["OBTRACE_INGEST_BASE_URL"] || "https://inject.obtrace.ai"
|
|
8
|
+
service_name = Railtie.credentials_fetch("obtrace_service_name") || ENV["OBTRACE_SERVICE_NAME"] || ::Rails.application.class.module_parent_name.underscore rescue "rails-app"
|
|
9
|
+
|
|
10
|
+
next unless api_key
|
|
11
|
+
|
|
12
|
+
cfg = ObtraceSDK::Config.new(
|
|
13
|
+
api_key: api_key,
|
|
14
|
+
ingest_base_url: ingest_url,
|
|
15
|
+
service_name: service_name,
|
|
16
|
+
env: ::Rails.env.to_s,
|
|
17
|
+
tenant_id: Railtie.credentials_fetch("obtrace_tenant_id") || ENV["OBTRACE_TENANT_ID"],
|
|
18
|
+
project_id: Railtie.credentials_fetch("obtrace_project_id") || ENV["OBTRACE_PROJECT_ID"],
|
|
19
|
+
app_id: Railtie.credentials_fetch("obtrace_app_id") || ENV["OBTRACE_APP_ID"],
|
|
20
|
+
debug: ENV["OBTRACE_DEBUG"] == "true"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
client = ObtraceSDK::Client.new(cfg)
|
|
24
|
+
ObtraceSDK.instance_variable_set(:@rails_client, client)
|
|
25
|
+
|
|
26
|
+
app.middleware.insert(0, ObtraceSDK::Middleware, client)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.Railtie.credentials_fetch(key)
|
|
30
|
+
::Rails.application.credentials.send(key) rescue nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.rails_client
|
|
35
|
+
@rails_client
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module ObtraceSDK
|
|
2
|
+
module SemanticMetrics
|
|
3
|
+
THROUGHPUT = "http_requests_total"
|
|
4
|
+
ERROR_RATE = "http_5xx_total"
|
|
5
|
+
LATENCY_P95 = "latency_p95"
|
|
6
|
+
RUNTIME_CPU_UTILIZATION = "runtime.cpu.utilization"
|
|
7
|
+
RUNTIME_MEMORY_USAGE = "runtime.memory.usage"
|
|
8
|
+
RUNTIME_THREAD_COUNT = "runtime.thread.count"
|
|
9
|
+
RUNTIME_GC_PAUSE = "runtime.gc.pause"
|
|
10
|
+
RUNTIME_EVENTLOOP_LAG = "runtime.eventloop.lag"
|
|
11
|
+
CLUSTER_CPU_UTILIZATION = "cluster.cpu.utilization"
|
|
12
|
+
CLUSTER_MEMORY_USAGE = "cluster.memory.usage"
|
|
13
|
+
CLUSTER_NODE_COUNT = "cluster.node.count"
|
|
14
|
+
CLUSTER_POD_COUNT = "cluster.pod.count"
|
|
15
|
+
DB_OPERATION_LATENCY = "db.operation.latency"
|
|
16
|
+
DB_CLIENT_ERRORS = "db.client.errors"
|
|
17
|
+
DB_CONNECTIONS_USAGE = "db.connections.usage"
|
|
18
|
+
MESSAGING_CONSUMER_LAG = "messaging.consumer.lag"
|
|
19
|
+
WEB_VITAL_LCP = "web.vital.lcp"
|
|
20
|
+
WEB_VITAL_FCP = "web.vital.fcp"
|
|
21
|
+
WEB_VITAL_INP = "web.vital.inp"
|
|
22
|
+
WEB_VITAL_CLS = "web.vital.cls"
|
|
23
|
+
WEB_VITAL_TTFB = "web.vital.ttfb"
|
|
24
|
+
USER_ACTIONS = "obtrace.sim.web.react.actions"
|
|
25
|
+
|
|
26
|
+
ALL = [
|
|
27
|
+
THROUGHPUT,
|
|
28
|
+
ERROR_RATE,
|
|
29
|
+
LATENCY_P95,
|
|
30
|
+
RUNTIME_CPU_UTILIZATION,
|
|
31
|
+
RUNTIME_MEMORY_USAGE,
|
|
32
|
+
RUNTIME_THREAD_COUNT,
|
|
33
|
+
RUNTIME_GC_PAUSE,
|
|
34
|
+
RUNTIME_EVENTLOOP_LAG,
|
|
35
|
+
CLUSTER_CPU_UTILIZATION,
|
|
36
|
+
CLUSTER_MEMORY_USAGE,
|
|
37
|
+
CLUSTER_NODE_COUNT,
|
|
38
|
+
CLUSTER_POD_COUNT,
|
|
39
|
+
DB_OPERATION_LATENCY,
|
|
40
|
+
DB_CLIENT_ERRORS,
|
|
41
|
+
DB_CONNECTIONS_USAGE,
|
|
42
|
+
MESSAGING_CONSUMER_LAG,
|
|
43
|
+
WEB_VITAL_LCP,
|
|
44
|
+
WEB_VITAL_FCP,
|
|
45
|
+
WEB_VITAL_INP,
|
|
46
|
+
WEB_VITAL_CLS,
|
|
47
|
+
WEB_VITAL_TTFB,
|
|
48
|
+
USER_ACTIONS
|
|
49
|
+
].freeze
|
|
50
|
+
|
|
51
|
+
def self.semantic_metric?(name)
|
|
52
|
+
ALL.include?(name)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module ObtraceSDK
|
|
2
|
+
class Config
|
|
3
|
+
attr_accessor :api_key, :ingest_base_url, :tenant_id, :project_id, :app_id, :env
|
|
4
|
+
attr_accessor :service_name, :service_version, :request_timeout_sec
|
|
5
|
+
attr_accessor :default_headers, :debug, :validate_semantic_metrics
|
|
6
|
+
|
|
7
|
+
def initialize(api_key:, ingest_base_url:, service_name:, tenant_id: nil, project_id: nil, app_id: nil, env: "dev", service_version: "1.0.0", request_timeout_sec: 5, default_headers: {}, validate_semantic_metrics: false, debug: false)
|
|
8
|
+
@api_key = api_key
|
|
9
|
+
@ingest_base_url = ingest_base_url
|
|
10
|
+
@tenant_id = tenant_id
|
|
11
|
+
@project_id = project_id
|
|
12
|
+
@app_id = app_id
|
|
13
|
+
@env = env
|
|
14
|
+
@service_name = service_name
|
|
15
|
+
@service_version = service_version
|
|
16
|
+
@request_timeout_sec = request_timeout_sec
|
|
17
|
+
@default_headers = default_headers
|
|
18
|
+
@validate_semantic_metrics = validate_semantic_metrics
|
|
19
|
+
@debug = debug
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/obtrace_sdk.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: obtrace
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Obtrace
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-03-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: opentelemetry-sdk
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: opentelemetry-api
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.3'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: opentelemetry-exporter-otlp
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.26'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.26'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: opentelemetry-instrumentation-net_http
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: opentelemetry-instrumentation-rack
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: opentelemetry-instrumentation-rails
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: Ruby SDK for Obtrace observability platform. Captures logs, traces, and
|
|
98
|
+
metrics via OTLP.
|
|
99
|
+
email:
|
|
100
|
+
- dev@obtrace.ai
|
|
101
|
+
executables: []
|
|
102
|
+
extensions: []
|
|
103
|
+
extra_rdoc_files: []
|
|
104
|
+
files:
|
|
105
|
+
- LICENSE
|
|
106
|
+
- README.md
|
|
107
|
+
- lib/obtrace_sdk.rb
|
|
108
|
+
- lib/obtrace_sdk/client.rb
|
|
109
|
+
- lib/obtrace_sdk/middleware.rb
|
|
110
|
+
- lib/obtrace_sdk/otel_setup.rb
|
|
111
|
+
- lib/obtrace_sdk/rails.rb
|
|
112
|
+
- lib/obtrace_sdk/semantic_metrics.rb
|
|
113
|
+
- lib/obtrace_sdk/types.rb
|
|
114
|
+
- lib/obtrace_sdk/version.rb
|
|
115
|
+
homepage: https://github.com/obtraceai/obtrace-sdk-ruby
|
|
116
|
+
licenses:
|
|
117
|
+
- MIT
|
|
118
|
+
metadata:
|
|
119
|
+
homepage_uri: https://github.com/obtraceai/obtrace-sdk-ruby
|
|
120
|
+
source_code_uri: https://github.com/obtraceai/obtrace-sdk-ruby
|
|
121
|
+
changelog_uri: https://github.com/obtraceai/obtrace-sdk-ruby/releases
|
|
122
|
+
post_install_message:
|
|
123
|
+
rdoc_options: []
|
|
124
|
+
require_paths:
|
|
125
|
+
- lib
|
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '3.1'
|
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
|
+
requirements:
|
|
133
|
+
- - ">="
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: '0'
|
|
136
|
+
requirements: []
|
|
137
|
+
rubygems_version: 3.4.20
|
|
138
|
+
signing_key:
|
|
139
|
+
specification_version: 4
|
|
140
|
+
summary: Obtrace Ruby SDK — observability for Ruby applications
|
|
141
|
+
test_files: []
|