-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #828 from DataDog/bump_to_version_0.28.0
Bump to version 0.28.0
- Loading branch information
Showing
27 changed files
with
530 additions
and
124 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
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
78 changes: 78 additions & 0 deletions
78
lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.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,78 @@ | ||
require 'ddtrace/contrib/action_view/ext' | ||
|
||
module Datadog | ||
module Contrib | ||
module ActionView | ||
module Instrumentation | ||
# Instrumentation for partial rendering | ||
module PartialRenderer | ||
def render(*args, &block) | ||
datadog_tracer.trace( | ||
Ext::SPAN_RENDER_PARTIAL, | ||
span_type: Datadog::Ext::HTTP::TEMPLATE | ||
) do |span| | ||
with_datadog_span(span) { super(*args) } | ||
end | ||
end | ||
|
||
def render_partial(*args) | ||
begin | ||
template = datadog_template(*args) | ||
|
||
datadog_render_partial(template) | ||
rescue StandardError => e | ||
Datadog::Tracer.log.debug(e.message) | ||
end | ||
|
||
# execute the original function anyway | ||
super(*args) | ||
end | ||
|
||
def datadog_render_partial(template) | ||
template_name = Utils.normalize_template_name(template.try('identifier')) | ||
|
||
if template_name | ||
active_datadog_span.set_tag( | ||
Ext::TAG_TEMPLATE_NAME, | ||
template_name | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_accessor :active_datadog_span | ||
|
||
def datadog_tracer | ||
Datadog.configuration[:action_view][:tracer] | ||
end | ||
|
||
def with_datadog_span(span) | ||
self.active_datadog_span = span | ||
yield | ||
ensure | ||
self.active_datadog_span = nil | ||
end | ||
|
||
# Rails < 6 partial rendering | ||
module RailsLessThan6 | ||
include PartialRenderer | ||
|
||
def datadog_template(*args) | ||
@template | ||
end | ||
end | ||
|
||
# Rails >= 6 partial rendering | ||
module Rails6Plus | ||
include PartialRenderer | ||
|
||
def datadog_template(*args) | ||
args[1] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.