Skip to content

Commit

Permalink
Merge pull request #225 from appsignal/ruby-app-updates
Browse files Browse the repository at this point in the history
Various (Ruby) app updates (for Ruby gem 4)
  • Loading branch information
tombruijn authored Aug 23, 2024
2 parents b701a47 + c5bffed commit af36f9e
Show file tree
Hide file tree
Showing 42 changed files with 354 additions and 198 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace :app do
task :bash do
@app = get_app
puts "Starting bash in #{@app}"
run_command "cd #{@app} && docker-compose exec app /bin/bash"
run_command "cd #{@app} && docker-compose exec --workdir /app app /bin/bash"
end

desc "Attach to app and get a console"
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace :integrations do
desc "Clone and reset integrations"
task :clone do
# Clone Ruby
clone_from_git("ruby/integration", "appsignal-ruby", :branch => "main")
clone_from_git("ruby/integration", "appsignal-ruby")
# Clone Elixir, it currently consists of multiple repos
FileUtils.mkdir_p("elixir/integration")
clone_from_git("elixir/integration/appsignal-elixir", "appsignal-elixir")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
path('error_queue_inline/', views.error_queue_inline, name='error_queue_inline'),
path('make_request/', views.make_request, name='make_request'),
path('custom_instrumentation/', views.custom_instrumentation, name='custom_instrumentation'),
path('metrics/', views.metrics, name='metrics'),
path('blog/', include("blog.urls"))
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import json
import time
from random import randrange

from opentelemetry import trace

Expand All @@ -19,7 +20,10 @@
set_root_name,
set_category,
set_name,
set_body
set_body,
set_gauge,
increment_counter,
add_distribution_value
)


Expand Down Expand Up @@ -103,5 +107,12 @@ def custom_instrumentation(request):
return HttpResponse("I reported some custom instrumentation!")


def metrics(request):
increment_counter("python_counter", randrange(1, 100))
set_gauge("python_gauge", randrange(1, 100))
add_distribution_value("python_distribution", randrange(1, 100))
return HttpResponse("I reported some metrics instrumentation!")


class MyException(Exception):
pass
1 change: 1 addition & 0 deletions python/django4-celery/app/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

def main():
"""Run administrative tasks."""
os.environ["OTEL_SERVICE_NAME"] = "django-app"
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'appsignal_python_opentelemetry.settings')

appsignal.start()
Expand Down
2 changes: 2 additions & 0 deletions python/django4-celery/app/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import os

import appsignal

Expand All @@ -11,6 +12,7 @@

@worker_process_init.connect(weak=False)
def init_celery_tracing(*args, **kwargs):
os.environ["OTEL_SERVICE_NAME"] = "celery-app"
appsignal.start()


Expand Down
2 changes: 1 addition & 1 deletion ruby/grape/app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: /integration
specs:
appsignal (3.9.1)
appsignal (4.0.0)
rack

GEM
Expand Down
3 changes: 1 addition & 2 deletions ruby/grape/app/api.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "grape"
require "appsignal/integrations/grape"

# In memory database for posts
class Posts
Expand All @@ -24,7 +23,7 @@ def find_by_id(id)

module MyApp
class BaseAPI < Grape::API
insert_before Grape::Middleware::Error, Appsignal::Grape::Middleware
insert_before Grape::Middleware::Error, Appsignal::Rack::GrapeMiddleware
end

module PostsAPI
Expand Down
11 changes: 4 additions & 7 deletions ruby/grape/app/config.ru
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
require "appsignal"
require "grape"

Appsignal.config = Appsignal::Config.new(
Dir.pwd,
ENV.fetch("RACK_ENV", "development")
)
use ::Rack::Events, [Appsignal::Rack::EventHandler.new]

Appsignal.load(:grape)
Appsignal.start
Appsignal.start_logger

require_relative "api"

use ::Rack::Events, [Appsignal::Rack::EventHandler.new]

MyApp::API.compile!
run MyApp::API
1 change: 1 addition & 0 deletions ruby/hanami2-postgres/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spec/examples.txt
18 changes: 14 additions & 4 deletions ruby/hanami2-postgres/app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ source "https://rubygems.org"

gem "appsignal", :path => "/integration"

gem "hanami", "~> 2.0.0"
gem "hanami-router", "~> 2.0.0"
gem "hanami-controller", "~> 2.0.0"
gem "hanami-validations", "~> 2.0.0"
gem "hanami", "~> 2.1.0"
gem "hanami-router", "~> 2.1.0"
gem "hanami-controller", "~> 2.1.0"
gem "hanami-validations", "~> 2.1.0"
gem "hanami-assets", "~> 2.1"
gem "hanami-view", "~> 2.1"

group :development do
gem "hanami-webconsole", "~> 2.1"
end

group :test do
gem "capybara"
end

gem "dry-types", "~> 1.0", ">= 1.6.1"
gem "puma"
Expand Down
Loading

0 comments on commit af36f9e

Please sign in to comment.