debugbundle 1.4.0 → 1.5.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 +4 -4
- data/README.md +7 -1
- data/lib/debugbundle/client.rb +12 -4
- data/lib/debugbundle/client_event_support.rb +27 -2
- data/lib/debugbundle/logging.rb +30 -16
- data/lib/debugbundle/rack/middleware.rb +13 -3
- data/lib/debugbundle/relay/handler.rb +9 -1
- data/lib/debugbundle/telemetry_privacy.rb +194 -0
- data/lib/debugbundle/version.rb +1 -1
- data/lib/debugbundle.rb +1 -0
- metadata +3 -23
- data/Gemfile +0 -17
- data/Makefile +0 -52
- data/debugbundle.gemspec +0 -30
- data/spec/before_send_spec.rb +0 -74
- data/spec/client_spec.rb +0 -432
- data/spec/debugbundle_spec.rb +0 -54
- data/spec/file_transport_spec.rb +0 -54
- data/spec/fixtures/event-envelope.schema.json +0 -142
- data/spec/logger_integration_spec.rb +0 -118
- data/spec/rack_integration_spec.rb +0 -44
- data/spec/rack_middleware_spec.rb +0 -210
- data/spec/rails_railtie_spec.rb +0 -96
- data/spec/rails_relay_spec.rb +0 -121
- data/spec/redaction_spec.rb +0 -42
- data/spec/relay_spec.rb +0 -274
- data/spec/remote_config_spec.rb +0 -80
- data/spec/repository_metadata_spec.rb +0 -65
- data/spec/sidekiq_integration_spec.rb +0 -66
- data/spec/sidekiq_middleware_spec.rb +0 -50
- data/spec/spec_helper.rb +0 -23
- data/spec/suppression_spec.rb +0 -16
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://debugbundle.com/schemas/event-envelope-ruby-fixture.json",
|
|
4
|
-
"oneOf": [
|
|
5
|
-
{
|
|
6
|
-
"$ref": "#/$defs/request_event_envelope"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"$ref": "#/$defs/log_event_envelope"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"$ref": "#/$defs/frontend_exception_envelope"
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
|
-
"$defs": {
|
|
16
|
-
"string_map": {
|
|
17
|
-
"type": "object",
|
|
18
|
-
"additionalProperties": true
|
|
19
|
-
},
|
|
20
|
-
"service": {
|
|
21
|
-
"type": "object",
|
|
22
|
-
"additionalProperties": false,
|
|
23
|
-
"required": ["name", "environment"],
|
|
24
|
-
"properties": {
|
|
25
|
-
"name": { "type": "string", "minLength": 1 },
|
|
26
|
-
"runtime": { "type": ["string", "null"], "minLength": 1 },
|
|
27
|
-
"framework": { "type": ["string", "null"], "minLength": 1 },
|
|
28
|
-
"environment": { "type": "string", "minLength": 1 }
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"correlation": {
|
|
32
|
-
"type": "object",
|
|
33
|
-
"additionalProperties": false,
|
|
34
|
-
"properties": {
|
|
35
|
-
"request_id": { "type": ["string", "null"] },
|
|
36
|
-
"trace_id": { "type": ["string", "null"] },
|
|
37
|
-
"session_id": { "type": ["string", "null"] },
|
|
38
|
-
"user_id_hash": { "type": ["string", "null"] }
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"envelope_base": {
|
|
42
|
-
"type": "object",
|
|
43
|
-
"additionalProperties": false,
|
|
44
|
-
"required": [
|
|
45
|
-
"schema_version",
|
|
46
|
-
"event_id",
|
|
47
|
-
"event_type",
|
|
48
|
-
"sdk_name",
|
|
49
|
-
"sdk_version",
|
|
50
|
-
"service",
|
|
51
|
-
"occurred_at",
|
|
52
|
-
"correlation",
|
|
53
|
-
"payload"
|
|
54
|
-
],
|
|
55
|
-
"properties": {
|
|
56
|
-
"schema_version": { "type": "string", "minLength": 1 },
|
|
57
|
-
"event_id": { "type": "string", "format": "uuid" },
|
|
58
|
-
"event_type": { "type": "string", "minLength": 1 },
|
|
59
|
-
"project_token": { "type": "string", "minLength": 1 },
|
|
60
|
-
"project_id": { "type": ["string", "null"], "format": "uuid" },
|
|
61
|
-
"sdk_name": { "type": "string", "minLength": 1 },
|
|
62
|
-
"sdk_version": { "type": "string", "minLength": 1 },
|
|
63
|
-
"service": { "$ref": "#/$defs/service" },
|
|
64
|
-
"occurred_at": { "type": "string", "format": "date-time" },
|
|
65
|
-
"correlation": { "$ref": "#/$defs/correlation" },
|
|
66
|
-
"context": {
|
|
67
|
-
"type": "object",
|
|
68
|
-
"additionalProperties": true
|
|
69
|
-
},
|
|
70
|
-
"payload": {}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
"request_event_envelope": {
|
|
74
|
-
"allOf": [
|
|
75
|
-
{ "$ref": "#/$defs/envelope_base" },
|
|
76
|
-
{
|
|
77
|
-
"properties": {
|
|
78
|
-
"event_type": { "const": "request_event" },
|
|
79
|
-
"payload": {
|
|
80
|
-
"type": "object",
|
|
81
|
-
"additionalProperties": false,
|
|
82
|
-
"required": ["method", "path", "query", "headers", "response_status", "duration_ms"],
|
|
83
|
-
"properties": {
|
|
84
|
-
"method": { "type": "string", "minLength": 1 },
|
|
85
|
-
"path": { "type": "string", "minLength": 1 },
|
|
86
|
-
"query": { "$ref": "#/$defs/string_map" },
|
|
87
|
-
"headers": { "$ref": "#/$defs/string_map" },
|
|
88
|
-
"body": {},
|
|
89
|
-
"response_status": { "type": "integer", "minimum": 0 },
|
|
90
|
-
"duration_ms": { "type": "number", "minimum": 0 },
|
|
91
|
-
"route_template": { "type": ["string", "null"] },
|
|
92
|
-
"controller": { "type": ["string", "null"] },
|
|
93
|
-
"action": { "type": ["string", "null"] },
|
|
94
|
-
"response_headers": { "$ref": "#/$defs/string_map" },
|
|
95
|
-
"response_body": {}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
},
|
|
102
|
-
"log_event_envelope": {
|
|
103
|
-
"allOf": [
|
|
104
|
-
{ "$ref": "#/$defs/envelope_base" },
|
|
105
|
-
{
|
|
106
|
-
"properties": {
|
|
107
|
-
"event_type": { "const": "log_event" },
|
|
108
|
-
"payload": {
|
|
109
|
-
"type": "object",
|
|
110
|
-
"additionalProperties": false,
|
|
111
|
-
"required": ["level", "message", "attributes"],
|
|
112
|
-
"properties": {
|
|
113
|
-
"level": { "type": "string", "minLength": 1 },
|
|
114
|
-
"message": { "type": "string", "minLength": 1 },
|
|
115
|
-
"attributes": { "$ref": "#/$defs/string_map" }
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
]
|
|
121
|
-
},
|
|
122
|
-
"frontend_exception_envelope": {
|
|
123
|
-
"allOf": [
|
|
124
|
-
{ "$ref": "#/$defs/envelope_base" },
|
|
125
|
-
{
|
|
126
|
-
"properties": {
|
|
127
|
-
"event_type": { "const": "frontend_exception" },
|
|
128
|
-
"sdk_name": { "const": "@debugbundle/sdk-browser" },
|
|
129
|
-
"payload": {
|
|
130
|
-
"type": "object",
|
|
131
|
-
"additionalProperties": true,
|
|
132
|
-
"required": ["message"],
|
|
133
|
-
"properties": {
|
|
134
|
-
"message": { "type": "string", "minLength": 1 }
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'stringio'
|
|
5
|
-
|
|
6
|
-
RSpec.describe 'stdlib logger integration' do
|
|
7
|
-
it 'captures log events without changing logger output' do
|
|
8
|
-
transport_events = []
|
|
9
|
-
transport = Class.new do
|
|
10
|
-
define_method(:initialize) do |transport_events|
|
|
11
|
-
@transport_events = transport_events
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
define_method(:call) do |request|
|
|
15
|
-
@transport_events << request
|
|
16
|
-
DebugBundle::Transport::Result.new(status_code: 202)
|
|
17
|
-
end
|
|
18
|
-
end.new(transport_events)
|
|
19
|
-
|
|
20
|
-
output = StringIO.new
|
|
21
|
-
logger = Logger.new(output)
|
|
22
|
-
logger.progname = 'checkout'
|
|
23
|
-
|
|
24
|
-
client = DebugBundle::Client.new(project_token: 'dbundle_proj_test', transport: transport)
|
|
25
|
-
client.capture_logger(logger)
|
|
26
|
-
client.capture_logger(logger)
|
|
27
|
-
|
|
28
|
-
logger.warn('payment retry failed')
|
|
29
|
-
client.flush
|
|
30
|
-
|
|
31
|
-
event = transport_events.fetch(0).fetch(:events).fetch(0)
|
|
32
|
-
|
|
33
|
-
expect(output.string).to include('payment retry failed')
|
|
34
|
-
expect(event.fetch('event_type')).to eq('log_event')
|
|
35
|
-
expect(event.fetch('payload')).to include('message' => 'payment retry failed', 'level' => 'warning')
|
|
36
|
-
expect(event.fetch('payload').fetch('attributes')).to include('logger_name' => 'checkout')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'registers a semantic logger appender when SemanticLogger is available' do
|
|
40
|
-
transport_events = []
|
|
41
|
-
transport = Class.new do
|
|
42
|
-
define_method(:initialize) do |transport_events|
|
|
43
|
-
@transport_events = transport_events
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
define_method(:call) do |request|
|
|
47
|
-
@transport_events << request
|
|
48
|
-
DebugBundle::Transport::Result.new(status_code: 202)
|
|
49
|
-
end
|
|
50
|
-
end.new(transport_events)
|
|
51
|
-
|
|
52
|
-
semantic_logger = Module.new do
|
|
53
|
-
class << self
|
|
54
|
-
attr_reader :appenders
|
|
55
|
-
|
|
56
|
-
def add_appender(appender:)
|
|
57
|
-
@appenders ||= []
|
|
58
|
-
@appenders << appender
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
stub_const('SemanticLogger', semantic_logger)
|
|
64
|
-
|
|
65
|
-
log_entry = Struct.new(:message, :level, :name, :payload, :tags).new(
|
|
66
|
-
'semantic failure',
|
|
67
|
-
:error,
|
|
68
|
-
'semantic-checkout',
|
|
69
|
-
{ order_id: 123 },
|
|
70
|
-
%w[payments critical]
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
client = DebugBundle::Client.new(project_token: 'dbundle_proj_test', transport: transport)
|
|
74
|
-
appender = client.capture_semantic_logger
|
|
75
|
-
appender.log(log_entry)
|
|
76
|
-
client.flush
|
|
77
|
-
|
|
78
|
-
event = transport_events.fetch(0).fetch(:events).fetch(0)
|
|
79
|
-
|
|
80
|
-
expect(SemanticLogger.appenders).to include(appender)
|
|
81
|
-
expect(event.fetch('payload')).to include('message' => 'semantic failure', 'level' => 'error')
|
|
82
|
-
expect(event.fetch('payload').fetch('attributes')).to include(
|
|
83
|
-
'logger_name' => 'semantic-checkout',
|
|
84
|
-
'payload' => { 'order_id' => 123 },
|
|
85
|
-
'tags' => %w[payments critical]
|
|
86
|
-
)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'guards semantic logger capture against recursive SDK logging' do
|
|
90
|
-
capture_count = 0
|
|
91
|
-
appender = nil
|
|
92
|
-
log_entry = Struct.new(:message, :level, :name, :payload, :tags).new(
|
|
93
|
-
'semantic recursion check',
|
|
94
|
-
:error,
|
|
95
|
-
'semantic-checkout',
|
|
96
|
-
{},
|
|
97
|
-
[]
|
|
98
|
-
)
|
|
99
|
-
recursive_client = Class.new do
|
|
100
|
-
define_method(:initialize) do |on_capture|
|
|
101
|
-
@on_capture = on_capture
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
define_method(:capture_log) do |_message, level:, context:|
|
|
105
|
-
@on_capture.call(level, context)
|
|
106
|
-
end
|
|
107
|
-
end.new(lambda do |_level, _context|
|
|
108
|
-
capture_count += 1
|
|
109
|
-
appender.log(log_entry)
|
|
110
|
-
end)
|
|
111
|
-
|
|
112
|
-
appender = DebugBundle::Logging::SemanticLoggerAppender.new(client: recursive_client)
|
|
113
|
-
|
|
114
|
-
appender.log(log_entry)
|
|
115
|
-
|
|
116
|
-
expect(capture_count).to eq(1)
|
|
117
|
-
end
|
|
118
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'rack'
|
|
5
|
-
require 'rack/mock'
|
|
6
|
-
|
|
7
|
-
RSpec.describe 'Rack integration' do
|
|
8
|
-
let(:transport_events) { [] }
|
|
9
|
-
let(:transport) do
|
|
10
|
-
Class.new do
|
|
11
|
-
define_method(:initialize) do |transport_events|
|
|
12
|
-
@transport_events = transport_events
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
define_method(:call) do |request|
|
|
16
|
-
@transport_events << request
|
|
17
|
-
DebugBundle::Transport::Result.new(status_code: 202)
|
|
18
|
-
end
|
|
19
|
-
end.new(transport_events)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'captures request context in a real Rack builder stack' do
|
|
23
|
-
client = DebugBundle::Client.new(project_token: 'dbundle_proj_test', service: 'rack-checkout', transport: transport)
|
|
24
|
-
app = Rack::Builder.new do
|
|
25
|
-
use DebugBundle::Rack::Middleware, client: client
|
|
26
|
-
run ->(_env) { [503, { 'Content-Type' => 'text/plain' }, ['ok']] }
|
|
27
|
-
end.to_app
|
|
28
|
-
|
|
29
|
-
response = Rack::MockRequest.new(app).get(
|
|
30
|
-
'/checkout?cart_id=123',
|
|
31
|
-
'HTTP_X_REQUEST_ID' => 'req-rack',
|
|
32
|
-
'HTTP_X_DEBUGBUNDLE_TRACE_ID' => 'trace-rack'
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
client.flush
|
|
36
|
-
event = transport_events.fetch(0).fetch(:events).fetch(0)
|
|
37
|
-
|
|
38
|
-
expect(response.status).to eq(503)
|
|
39
|
-
expect(response.body).to eq('ok')
|
|
40
|
-
expect(event.fetch('event_type')).to eq('request_event')
|
|
41
|
-
expect(event.fetch('correlation')).to include('request_id' => 'req-rack', 'trace_id' => 'trace-rack')
|
|
42
|
-
expect(event.fetch('payload')).to include('path' => '/checkout', 'method' => 'GET', 'response_status' => 503)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'base64'
|
|
5
|
-
require 'json'
|
|
6
|
-
require 'openssl'
|
|
7
|
-
|
|
8
|
-
RSpec.describe DebugBundle::Rack::Middleware do
|
|
9
|
-
let(:transport_events) { [] }
|
|
10
|
-
let(:client) do
|
|
11
|
-
transport = Class.new do
|
|
12
|
-
define_method(:initialize) do |transport_events|
|
|
13
|
-
@transport_events = transport_events
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
define_method(:call) do |request|
|
|
17
|
-
@transport_events << request
|
|
18
|
-
DebugBundle::Transport::Result.new(status_code: 202)
|
|
19
|
-
end
|
|
20
|
-
end.new(transport_events)
|
|
21
|
-
|
|
22
|
-
config_fetcher = lambda do |_etag|
|
|
23
|
-
{
|
|
24
|
-
status_code: 200,
|
|
25
|
-
etag: 'rack-etag',
|
|
26
|
-
body: {
|
|
27
|
-
capture_policy: {
|
|
28
|
-
preset: 'balanced',
|
|
29
|
-
capture_logs: 'warning',
|
|
30
|
-
capture_request_events: 'all',
|
|
31
|
-
capture_breadcrumbs: 'exception_only',
|
|
32
|
-
capture_probe_events: 'buffer_only',
|
|
33
|
-
immediate_client_error_statuses: []
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
DebugBundle::Client.new(
|
|
40
|
-
project_token: 'dbundle_proj_test',
|
|
41
|
-
service: 'checkout-api',
|
|
42
|
-
transport: transport,
|
|
43
|
-
config_fetcher: config_fetcher
|
|
44
|
-
)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'captures request metadata and preserves the response' do
|
|
48
|
-
app = lambda do |_env|
|
|
49
|
-
[201, { 'Content-Type' => 'application/json', 'Set-Cookie' => 'secret' }, ['ok']]
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
middleware = described_class.new(app, client: client)
|
|
53
|
-
status, headers, body = middleware.call(
|
|
54
|
-
'REQUEST_METHOD' => 'POST',
|
|
55
|
-
'PATH_INFO' => '/checkout',
|
|
56
|
-
'QUERY_STRING' => 'cart_id=123',
|
|
57
|
-
'HTTP_X_REQUEST_ID' => 'req-1',
|
|
58
|
-
'HTTP_X_DEBUGBUNDLE_TRACE_ID' => 'trace-1',
|
|
59
|
-
'HTTP_AUTHORIZATION' => 'Bearer secret',
|
|
60
|
-
'HTTP_USER_AGENT' => 'RSpec'
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
client.flush
|
|
64
|
-
event = transport_events.fetch(0).fetch(:events).fetch(0)
|
|
65
|
-
|
|
66
|
-
expect(status).to eq(201)
|
|
67
|
-
expect(headers).to include('Content-Type' => 'application/json')
|
|
68
|
-
expect(body).to eq(['ok'])
|
|
69
|
-
expect(event.fetch('event_type')).to eq('request_event')
|
|
70
|
-
expect(event.fetch('correlation')).to include('request_id' => 'req-1', 'trace_id' => 'trace-1')
|
|
71
|
-
expect(event.fetch('payload').fetch('headers')).to include('user-agent' => 'RSpec')
|
|
72
|
-
expect(event.fetch('payload').fetch('headers')).not_to have_key('authorization')
|
|
73
|
-
expect(event.fetch('payload').fetch('response_headers')).to include('content-type' => 'application/json')
|
|
74
|
-
expect(event.fetch('payload').fetch('response_headers')).not_to have_key('set-cookie')
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'captures exceptions and re-raises them' do
|
|
78
|
-
app = lambda do |_env|
|
|
79
|
-
raise 'checkout failure'
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
middleware = described_class.new(app, client: client)
|
|
83
|
-
|
|
84
|
-
expect do
|
|
85
|
-
middleware.call(
|
|
86
|
-
'REQUEST_METHOD' => 'GET',
|
|
87
|
-
'PATH_INFO' => '/checkout',
|
|
88
|
-
'QUERY_STRING' => '',
|
|
89
|
-
'HTTP_X_REQUEST_ID' => 'req-2'
|
|
90
|
-
)
|
|
91
|
-
end.to raise_error(RuntimeError, 'checkout failure')
|
|
92
|
-
|
|
93
|
-
client.flush
|
|
94
|
-
event = transport_events.fetch(0).fetch(:events).fetch(0)
|
|
95
|
-
|
|
96
|
-
expect(event.fetch('event_type')).to eq('backend_exception')
|
|
97
|
-
expect(event.fetch('payload')).to include('handled' => false)
|
|
98
|
-
expect(event.fetch('correlation')).to include('request_id' => 'req-2')
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it 'activates trigger-token probe shipping for a single request' do
|
|
102
|
-
trigger_key = 'trigger-secret'
|
|
103
|
-
expires_at = (Time.now.utc + 60).iso8601
|
|
104
|
-
payload_json = JSON.generate(
|
|
105
|
-
activation_id: 'probe-1',
|
|
106
|
-
label_pattern: 'checkout.*',
|
|
107
|
-
service: '*',
|
|
108
|
-
environment: '*',
|
|
109
|
-
trigger_expires_at: expires_at
|
|
110
|
-
)
|
|
111
|
-
payload_segment = Base64.urlsafe_encode64(payload_json, padding: false)
|
|
112
|
-
signature = OpenSSL::HMAC.digest('sha256', trigger_key, payload_segment)
|
|
113
|
-
token = "dbundle_probe_#{payload_segment}.#{Base64.urlsafe_encode64(signature, padding: false)}"
|
|
114
|
-
|
|
115
|
-
transport = Class.new do
|
|
116
|
-
define_method(:initialize) do |transport_events|
|
|
117
|
-
@transport_events = transport_events
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
define_method(:call) do |request|
|
|
121
|
-
@transport_events << request
|
|
122
|
-
DebugBundle::Transport::Result.new(status_code: 202)
|
|
123
|
-
end
|
|
124
|
-
end.new(transport_events)
|
|
125
|
-
|
|
126
|
-
config_fetcher = lambda do |_etag|
|
|
127
|
-
{
|
|
128
|
-
status_code: 200,
|
|
129
|
-
etag: 'rack-trigger-etag',
|
|
130
|
-
body: {
|
|
131
|
-
probes_enabled: true,
|
|
132
|
-
remote_probes_enabled: true,
|
|
133
|
-
trigger_token_key: trigger_key,
|
|
134
|
-
capture_policy: {
|
|
135
|
-
preset: 'balanced',
|
|
136
|
-
capture_logs: 'warning',
|
|
137
|
-
capture_request_events: 'all',
|
|
138
|
-
capture_breadcrumbs: 'exception_only',
|
|
139
|
-
capture_probe_events: 'buffer_only',
|
|
140
|
-
immediate_client_error_statuses: []
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
trigger_client = DebugBundle::Client.new(
|
|
147
|
-
project_token: 'dbundle_proj_test',
|
|
148
|
-
service: 'checkout-api',
|
|
149
|
-
transport: transport,
|
|
150
|
-
config_fetcher: config_fetcher
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
app = lambda do |_env|
|
|
154
|
-
trigger_client.probe('checkout.tax', { region: 'us-east-1' })
|
|
155
|
-
[200, { 'Content-Type' => 'application/json' }, ['ok']]
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
middleware = described_class.new(app, client: trigger_client)
|
|
159
|
-
middleware.call(
|
|
160
|
-
'REQUEST_METHOD' => 'GET',
|
|
161
|
-
'PATH_INFO' => '/checkout',
|
|
162
|
-
'QUERY_STRING' => '',
|
|
163
|
-
'HTTP_X_DEBUGBUNDLE_PROBE_TRIGGER' => token,
|
|
164
|
-
'HTTP_X_REQUEST_ID' => 'req-trigger'
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
trigger_client.flush
|
|
168
|
-
events = transport_events.fetch(0).fetch(:events)
|
|
169
|
-
probe_event = events.find { |entry| entry.fetch('event_type') == 'probe_event' }
|
|
170
|
-
|
|
171
|
-
expect(probe_event).not_to be_nil
|
|
172
|
-
expect(probe_event.fetch('payload')).to include(
|
|
173
|
-
'label' => 'checkout.tax',
|
|
174
|
-
'activation_id' => 'probe-1',
|
|
175
|
-
'probe_label_pattern' => 'checkout.*'
|
|
176
|
-
)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it 'captures Rails route, controller, and action metadata when present' do
|
|
180
|
-
app = lambda do |_env|
|
|
181
|
-
[422, { 'Content-Type' => 'application/json' }, ['invalid']]
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
middleware = described_class.new(app, client: client)
|
|
185
|
-
middleware.call(
|
|
186
|
-
'REQUEST_METHOD' => 'POST',
|
|
187
|
-
'PATH_INFO' => '/patients/123/checkouts',
|
|
188
|
-
'QUERY_STRING' => '',
|
|
189
|
-
'action_dispatch.request_id' => 'req-rails',
|
|
190
|
-
'action_dispatch.route_uri_pattern' => '/patients/:patient_id/checkouts',
|
|
191
|
-
'action_dispatch.request.parameters' => {
|
|
192
|
-
'controller' => 'checkouts',
|
|
193
|
-
'action' => 'create'
|
|
194
|
-
}
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
client.flush
|
|
198
|
-
event = transport_events.fetch(0).fetch(:events).fetch(0)
|
|
199
|
-
payload = event.fetch('payload')
|
|
200
|
-
context = event.fetch('context')
|
|
201
|
-
|
|
202
|
-
expect(payload).to include(
|
|
203
|
-
'route_template' => '/patients/:patient_id/checkouts'
|
|
204
|
-
)
|
|
205
|
-
expect(context).to include(
|
|
206
|
-
'controller' => 'checkouts',
|
|
207
|
-
'action' => 'create'
|
|
208
|
-
)
|
|
209
|
-
end
|
|
210
|
-
end
|
data/spec/rails_railtie_spec.rb
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'json'
|
|
5
|
-
require 'logger'
|
|
6
|
-
require 'rack/test'
|
|
7
|
-
require 'rails'
|
|
8
|
-
require 'debugbundle/rails'
|
|
9
|
-
|
|
10
|
-
RSpec.describe 'Rails Railtie integration' do
|
|
11
|
-
include Rack::Test::Methods
|
|
12
|
-
|
|
13
|
-
def app
|
|
14
|
-
@app ||= build_rails_app
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
after do
|
|
18
|
-
@app = nil
|
|
19
|
-
DebugBundle.client = nil
|
|
20
|
-
Rails.instance_variable_set(:@application, nil)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'mounts the configured relay route and forwards browser events' do
|
|
24
|
-
post '/relay/browser',
|
|
25
|
-
JSON.generate('batch' => [browser_event]),
|
|
26
|
-
{
|
|
27
|
-
'CONTENT_TYPE' => 'application/json',
|
|
28
|
-
'HTTP_HOST' => 'app.example.com',
|
|
29
|
-
'HTTP_ORIGIN' => 'https://app.example.com'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
expect(last_response.status).to eq(202)
|
|
33
|
-
expect(last_response.headers.fetch('Content-Type')).to include('application/json')
|
|
34
|
-
expect(JSON.parse(last_response.body)).to include('accepted' => 1, 'rejected' => 0)
|
|
35
|
-
expect(@transport_events.fetch(0).fetch(:events).fetch(0).fetch('service')).to include(
|
|
36
|
-
'name' => 'rails-checkout',
|
|
37
|
-
'environment' => 'production'
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
post '/debugbundle/browser',
|
|
41
|
-
JSON.generate('batch' => [browser_event]),
|
|
42
|
-
{
|
|
43
|
-
'CONTENT_TYPE' => 'application/json',
|
|
44
|
-
'HTTP_HOST' => 'app.example.com',
|
|
45
|
-
'HTTP_ORIGIN' => 'https://app.example.com'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
expect(last_response.status).to eq(404)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def build_rails_app
|
|
52
|
-
@transport_events = []
|
|
53
|
-
forward_transport = Class.new do
|
|
54
|
-
define_method(:initialize) do |transport_events|
|
|
55
|
-
@transport_events = transport_events
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
define_method(:call) do |request|
|
|
59
|
-
@transport_events << request
|
|
60
|
-
DebugBundle::Transport::Result.new(status_code: 202)
|
|
61
|
-
end
|
|
62
|
-
end.new(@transport_events)
|
|
63
|
-
|
|
64
|
-
app_class = Class.new(Rails::Application) do
|
|
65
|
-
config.root = File.expand_path('..', __dir__)
|
|
66
|
-
config.eager_load = false
|
|
67
|
-
config.secret_key_base = 'test-secret'
|
|
68
|
-
config.logger = Logger.new(nil)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
app_class.config.hosts << 'app.example.com' if app_class.config.respond_to?(:hosts)
|
|
72
|
-
app_class.config.debugbundle.project_token = 'dbundle_proj_test'
|
|
73
|
-
app_class.config.debugbundle.service = 'rails-checkout'
|
|
74
|
-
app_class.config.debugbundle.environment = 'production'
|
|
75
|
-
app_class.config.debugbundle.relay_durable_write = false
|
|
76
|
-
app_class.config.debugbundle.relay_allowed_origins = ['https://app.example.com']
|
|
77
|
-
app_class.config.debugbundle.relay_forward_transport = forward_transport
|
|
78
|
-
app_class.config.debugbundle.relay_path = '/relay/browser'
|
|
79
|
-
app_class.initialize!
|
|
80
|
-
app_class
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def browser_event
|
|
84
|
-
{
|
|
85
|
-
'schema_version' => '2026-03-01',
|
|
86
|
-
'event_id' => 'evt-1',
|
|
87
|
-
'event_type' => 'frontend_exception',
|
|
88
|
-
'sdk_name' => '@debugbundle/sdk-browser',
|
|
89
|
-
'sdk_version' => '0.1.0',
|
|
90
|
-
'occurred_at' => Time.now.utc.iso8601,
|
|
91
|
-
'service' => { 'name' => 'browser-app', 'environment' => 'production' },
|
|
92
|
-
'correlation' => { 'trace_id' => 'trace-1' },
|
|
93
|
-
'payload' => { 'message' => 'boom' }
|
|
94
|
-
}
|
|
95
|
-
end
|
|
96
|
-
end
|