Skip to content

Commit afeb482

Browse files
committed
WIP
1 parent 46bdcd5 commit afeb482

5 files changed

Lines changed: 119 additions & 11 deletions

File tree

.github/workflows/e2e_tests.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ jobs:
4343
source .env
4444
docker compose --profile e2e up -d sentry-svelte-mini
4545
46+
- name: Wait for services to be healthy
47+
run: |
48+
echo "Waiting for Rails mini app to be ready..."
49+
timeout 60 bash -c 'until curl -s http://localhost:5000/health | grep -q "ok"; do echo "Waiting for Rails app..."; sleep 2; done'
50+
echo "✅ Rails mini app is ready"
51+
52+
echo "Waiting for Svelte mini app to be ready..."
53+
timeout 60 bash -c 'until curl -s http://localhost:5001/health | grep -q "ok"; do echo "Waiting for Svelte app..."; sleep 2; done'
54+
echo "✅ Svelte mini app is ready"
55+
56+
echo "All services are healthy!"
57+
4658
- name: Run e2e tests
4759
run: |
4860
cd .devcontainer

Rakefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,22 @@ namespace :spec do
3232

3333
# Wait for services to be ready
3434
puts "Waiting for services to be ready..."
35-
unless system("timeout 60 bash -c 'until curl -s http://localhost:5000/trace_headers >/dev/null && curl -s http://localhost:5001 >/dev/null; do sleep 2; done'")
36-
puts "Services failed to become ready"
35+
puts "Checking Rails mini app health..."
36+
unless system("timeout 60 bash -c 'until curl -s http://localhost:5000/health | grep -q \"ok\"; do echo \"Waiting for Rails app...\"; sleep 2; done'")
37+
puts "Rails mini app failed to become ready"
3738
Dir.chdir('.devcontainer') { system("docker-compose --profile e2e down") }
3839
exit(1)
3940
end
41+
puts "✅ Rails mini app is ready"
42+
43+
puts "Checking Svelte mini app health..."
44+
unless system("timeout 60 bash -c 'until curl -s http://localhost:5001/health | grep -q \"ok\"; do echo \"Waiting for Svelte app...\"; sleep 2; done'")
45+
puts "Svelte mini app failed to become ready"
46+
Dir.chdir('.devcontainer') { system("docker-compose --profile e2e down") }
47+
exit(1)
48+
end
49+
puts "✅ Svelte mini app is ready"
50+
puts "All services are healthy!"
4051

4152
# Run tests in sentry container with proper environment variables
4253
Dir.chdir('.devcontainer') do

sentry-ruby/lib/sentry/transport/debug_transport.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,37 @@ def initialize_backend(configuration)
6262
def initialize_log_file(configuration)
6363
log_file = Pathname(configuration.sdk_debug_transport_log_file || DEFAULT_LOG_FILE_PATH)
6464

65-
FileUtils.mkdir_p(log_file.dirname) unless log_file.dirname.exist?
65+
unless log_file.dirname.exist?
66+
begin
67+
FileUtils.mkdir_p(log_file.dirname)
68+
rescue Errno::EACCES => e
69+
raise "Cannot create log directory #{log_file.dirname}: #{e.message}"
70+
end
71+
end
72+
73+
check_log_file_permissions(log_file)
6674

6775
log_file
6876
end
77+
78+
def check_log_file_permissions(log_file)
79+
if log_file.exist?
80+
unless log_file.writable?
81+
raise "Cannot write to log file #{log_file}: Permission denied"
82+
end
83+
else
84+
unless log_file.dirname.writable?
85+
raise "Cannot write to log directory #{log_file.dirname}: Permission denied"
86+
end
87+
88+
begin
89+
File.open(log_file, "a") { |f| f.write("") }
90+
rescue Errno::EACCES => e
91+
raise "Cannot write to log file #{log_file}: #{e.message}"
92+
rescue => e
93+
raise "Failed to initialize log file #{log_file}: #{e.message}"
94+
end
95+
end
96+
end
6997
end
7098
end

spec/apps/rails-mini/app.rb

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ class RailsMiniApp < Rails::Application
2727
config.api_only = true
2828
config.force_ssl = false
2929

30+
# Validate DSN before starting
31+
initializer :validate_dsn, before: :configure_sentry do
32+
dsn_string = ENV["SENTRY_DSN"]
33+
34+
if dsn_string.nil? || dsn_string.empty?
35+
puts "ERROR: SENTRY_DSN environment variable is required but not set"
36+
exit(1)
37+
end
38+
39+
begin
40+
dsn = Sentry::DSN.new(dsn_string)
41+
unless dsn.valid?
42+
puts "ERROR: Invalid SENTRY_DSN: #{dsn_string}"
43+
puts "DSN must include host, path, public_key, and project_id"
44+
exit(1)
45+
end
46+
puts "✅ SENTRY_DSN validation passed: #{dsn_string}"
47+
rescue URI::InvalidURIError => e
48+
puts "ERROR: Invalid SENTRY_DSN format: #{e.message}"
49+
exit(1)
50+
rescue => e
51+
puts "ERROR: Failed to parse SENTRY_DSN: #{e.message}"
52+
exit(1)
53+
end
54+
end
55+
3056
# Configure Sentry
3157
initializer :configure_sentry do
3258
Sentry.init do |config|
@@ -40,7 +66,7 @@ class RailsMiniApp < Rails::Application
4066
config.release = "sentry-ruby-rails-mini-#{Time.now.utc}"
4167

4268
config.transport.transport_class = Sentry::DebugTransport
43-
config.sdk_debug_transport_log_file = "/workspace/sentry/log/sentry_debug_events.log"
69+
config.sdk_debug_transport_log_file = File.join(Dir.pwd, "log", "sentry_debug_events.log")
4470
config.background_worker_threads = 0
4571
end
4672
end
@@ -66,30 +92,41 @@ def set_cors_headers
6692
class EventsController < ActionController::Base
6793
before_action :set_cors_headers
6894

69-
95+
def health
96+
render json: {
97+
status: "ok",
98+
timestamp: Time.now.utc.iso8601,
99+
sentry_initialized: Sentry.initialized?,
100+
log_file_writable: check_log_file_writable
101+
}
102+
end
70103

71104
def trace_headers
72-
# Return current trace propagation headers
73105
headers = Sentry.get_trace_propagation_headers || {}
74106
render json: { headers: headers }
75107
end
76108

77-
78-
79109
private
80110

111+
def check_log_file_writable
112+
log_file_path = File.join(Dir.pwd, "log", "sentry_debug_events.log")
113+
File.writable?(File.dirname(log_file_path)) &&
114+
(!File.exist?(log_file_path) || File.writable?(log_file_path))
115+
rescue
116+
false
117+
end
118+
81119
def set_cors_headers
82120
response.headers['Access-Control-Allow-Origin'] = '*'
83121
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
84122
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization, sentry-trace, baggage'
85123
end
86124
end
87125

88-
# Initialize the Rails app first
89126
RailsMiniApp.initialize!
90127

91-
# Configure routes after initialization
92128
RailsMiniApp.routes.draw do
129+
get '/health', to: 'events#health'
93130
get '/error', to: 'error#error'
94131
get '/trace_headers', to: 'events#trace_headers'
95132

spec/apps/svelte-mini/vite.config.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@ import { defineConfig } from 'vite'
22
import { svelte } from '@sveltejs/vite-plugin-svelte'
33

44
export default defineConfig({
5-
plugins: [svelte()],
5+
plugins: [
6+
svelte(),
7+
{
8+
name: 'health-check',
9+
configureServer(server) {
10+
server.middlewares.use('/health', (req, res, next) => {
11+
if (req.method === 'GET') {
12+
res.setHeader('Content-Type', 'application/json')
13+
res.setHeader('Access-Control-Allow-Origin', '*')
14+
res.end(JSON.stringify({
15+
status: 'ok',
16+
timestamp: new Date().toISOString(),
17+
service: 'svelte-mini'
18+
}))
19+
} else {
20+
next()
21+
}
22+
})
23+
}
24+
}
25+
],
626
server: {
727
port: 5001,
828
host: '0.0.0.0',

0 commit comments

Comments
 (0)