Skip to content

Instantly share code, notes, and snippets.

@rromanchuk
Created August 12, 2020 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rromanchuk/0fe5508e512e73ca8028caf6c3a30750 to your computer and use it in GitHub Desktop.
Save rromanchuk/0fe5508e512e73ca8028caf6c3a30750 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class ApplicationController < ActionController::Base
def index
MyService.async_call(current_user)
end
end
# config/intitalizers/datadog-tracer.rb
require "ddtrace"
require "fast_jsonapi/instrumentation/skylight"
Datadog.configure do |c|
if Rails.env.production?
c.analytics_enabled = true
c.use :rails, service_name: "redact"
c.use :active_record, describes: :primary, service_name: 'write-db'
c.use :active_record, describes: :primary_replica, service_name: 'read-db'
c.env = "prod"
c.use :redis, analytics_enabled: true
c.use :aws, analytics_enabled: true
c.use :http, analytics_enabled: true
c.use :action_cable, analytics_enabled: true
c.use :redis, describes: { url: 'redis://redact/3' }, service_name: 'redact', analytics_enabled: true
c.use :redis, describes: { url: 'redis://redact/2' }, service_name: 'redact', analytics_enabled: true
c.use :redis, describes: { url: 'redis://redact/6' }, service_name: 'redact', analytics_enabled: true
c.use :redis, describes: { url: 'redis://redact/0' }, service_name: 'redact', analytics_enabled: true
c.use :redis, describes: { url: 'redis://redact' }, service_name: 'redact', analytics_enabled: true
elsif Rails.env.staging?
# snipped
else
# snipped
end
end
ddtrace (0.38.0)
msgpack
rails (6.0.3.2)
actioncable (= 6.0.3.2)
actionmailbox (= 6.0.3.2)
actionmailer (= 6.0.3.2)
actionpack (= 6.0.3.2)
actiontext (= 6.0.3.2)
actionview (= 6.0.3.2)
activejob (= 6.0.3.2)
activemodel (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
bundler (>= 1.3.0)
railties (= 6.0.3.2)
# app/services/my_service.rb
class MyService < Service
attr_reader :user
def initialize(user)
@user = user
end
def call
pp user
end
end
# app/services/service.rb
class Service
private_methods :new
class << self
def call(*args)
new(*args).call
end
def async_call(*args)
ServiceJob.perform_later(to_s, args)
end
end
end
# app/jobs/service_job.rb
class ServiceJob < ApplicationJob
queue_as :default
def perform(service_name, args)
service_name.constantize.call(*args)
end
end
@rromanchuk
Copy link
Author

rromanchuk commented Aug 12, 2020

ActiveJob::SerializationError: Unsupported argument type: Datadog::Span
  from active_job/serializers.rb:28:in `serialize'
  from active_support/callbacks.rb:121:in `block in run_callbacks'
  from active_support/callbacks.rb:139:in `run_callbacks'
  from active_job/enqueuing.rb:55:in `enqueue'
  from active_job/enqueuing.rb:22:in `perform_later'
  from app/services/service.rb:12:in `async_call'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment