-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
integration/apps/rails-seven/app/controllers/di_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class DiController < ApplicationController | ||
def ar_serializer | ||
test = Test.create! | ||
render json: Datadog::DI.component.serializer.serialize_value(test) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'spec_helper' | ||
require 'json' | ||
|
||
RSpec.describe 'Dynamic Instrumentation' do | ||
include_context 'integration test' | ||
|
||
describe 'ActiveRecord integration' do | ||
subject { JSON.parse(get('di/ar_serializer').body) } | ||
|
||
it 'is loaded' do | ||
# If AR integration is loaded, this output will be the result of | ||
# the custom serializer. | ||
# If AR integration is not loaded, the output here will have a bunch of | ||
# internal AR fields but not the attributes themselves. | ||
expect(subject).to match( | ||
{"type"=>"Test", | ||
"entries"=> | ||
[[{"type"=>"Symbol", "value"=>"attributes"}, | ||
{"type"=>"Hash", | ||
"entries"=> | ||
[[{"type"=>"String", "value"=>"id"}, {"type"=>"Integer", "value"=>String}], | ||
[{"type"=>"String", "value"=>"version"}, {"type"=>"NilClass", "isNull"=>true}], | ||
[{"type"=>"String", "value"=>"data"}, {"type"=>"NilClass", "isNull"=>true}], | ||
[{"type"=>"String", "value"=>"created_at"}, | ||
{"type"=>"ActiveSupport::TimeWithZone", "value"=>String}], | ||
[{"type"=>"String", "value"=>"updated_at"}, | ||
{"type"=>"ActiveSupport::TimeWithZone", "value"=>String}]]}], | ||
[{"type"=>"Symbol", "value"=>"new_record"}, {"type"=>"FalseClass", "value"=>"false"}]]} | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../core/contrib/rails/utils' | ||
|
||
module Datadog | ||
module DI | ||
module Contrib | ||
module_function def load_now_or_later | ||
if Datadog::Core::Contrib::Rails::Utils.railtie_supported? | ||
require_relative 'contrib/railtie' | ||
else | ||
load_now | ||
end | ||
end | ||
|
||
module_function def load_now | ||
if defined?(ActiveRecord::Base) | ||
require_relative 'contrib/active_record' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module DI | ||
module Contrib | ||
# Railtie class initializes dynamic instrumentation contrib code | ||
# in Rails environments. | ||
class Railtie < Rails::Railtie | ||
initializer 'datadog.dynamic_instrumentation.initialize' do |app| | ||
Contrib.load_now | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Datadog | ||
module DI | ||
module Contrib | ||
def self?.load_now_or_later: () -> void | ||
|
||
def self?.load_now: () -> void | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Datadog | ||
module DI | ||
module Contrib | ||
class Railtie < Rails::Railtie | ||
end | ||
end | ||
end | ||
end |