Skip to content

Commit

Permalink
Merge pull request #4579 from rmosolgo/fix-block-arg
Browse files Browse the repository at this point in the history
Fix DataDogTrace LocalJumpError
  • Loading branch information
rmosolgo authored Aug 8, 2023
2 parents f39d5db + 36f5a79 commit 6b01c37
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
47 changes: 35 additions & 12 deletions lib/graphql/tracing/data_dog_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def #{trace_method}(**data)
RUBY
end
def execute_field(span_key = "execute_field", query:, field:, ast_node:, arguments:, object:)
def execute_field_span(span_key, query, field, ast_node, arguments, object)
return_type = field.type.unwrap
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
(field.trace.nil? && @trace_scalars) || field.trace
Expand All @@ -99,18 +99,31 @@ def execute_field(span_key = "execute_field", query:, field:, ast_node:, argumen
prepare_span_data = { query: query, field: field, ast_node: ast_node, arguments: arguments, object: object }
prepare_span(span_key, prepare_span_data, span)
end
super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
yield
end
else
yield
end
end
def execute_field(query:, field:, ast_node:, arguments:, object:)
execute_field_span("execute_field", query, field, ast_node, arguments, object) do
super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
end
end
def execute_field_lazy(query:, field:, ast_node:, arguments:, object:)
execute_field("execute_field_lazy", query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
execute_field_span("execute_field_lazy", query, field, ast_node, arguments, object) do
super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
end
end
def authorized(object:, type:, query:, span_key: "authorized")
def authorized(query:, type:, object:)
authorized_span("authorized", object, type, query) do
super(query: query, type: type, object: object)
end
end
def authorized_span(span_key, object, type, query)
platform_key = @platform_key_cache[DataDogTrace].platform_authorized_key_cache[type]
@tracer.trace(platform_key, service: @service_name) do |span|
span.span_type = 'custom'
Expand All @@ -121,15 +134,29 @@ def authorized(object:, type:, query:, span_key: "authorized")
if @has_prepare_span
prepare_span(span_key, {object: object, type: type, query: query}, span)
end
yield
end
end
def authorized_lazy(object:, type:, query:)
authorized_span("authorized_lazy", object, type, query) do
super(query: query, type: type, object: object)
end
end
def authorized_lazy(**kwargs, &block)
authorized(span_key: "authorized_lazy", **kwargs, &block)
def resolve_type(object:, type:, query:)
resolve_type_span("resolve_type", object, type, query) do
super(object: object, query: query, type: type)
end
end
def resolve_type(object:, type:, query:, span_key: "resolve_type")
def resolve_type_lazy(object:, type:, query:)
resolve_type_span("resolve_type_lazy", object, type, query) do
super(object: object, query: query, type: type)
end
end
def resolve_type_span(span_key, object, type, query)
platform_key = @platform_key_cache[DataDogTrace].platform_resolve_type_key_cache[type]
@tracer.trace(platform_key, service: @service_name) do |span|
span.span_type = 'custom'
Expand All @@ -140,14 +167,10 @@ def resolve_type(object:, type:, query:, span_key: "resolve_type")
if @has_prepare_span
prepare_span(span_key, {object: object, type: type, query: query}, span)
end
super(query: query, type: type, object: object)
yield
end
end
def resolve_type_lazy(**kwargs, &block)
resolve_type(span_key: "resolve_type_lazy", **kwargs, &block)
end
include PlatformTrace
# Implement this method in a subclass to apply custom tags to datadog spans
Expand Down
12 changes: 11 additions & 1 deletion spec/graphql/tracing/appsignal_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def instrumented
end

describe GraphQL::Tracing::AppsignalTrace do
class IntBox
def initialize(value)
@value = value
end
attr_reader :value
end

module AppsignalTraceTest
class Thing < GraphQL::Schema::Object
field :str, String
Expand All @@ -36,7 +43,7 @@ class Query < GraphQL::Schema::Object
field :int, Integer, null: false

def int
1
IntBox.new(1)
end

field :thing, Thing
Expand All @@ -48,6 +55,7 @@ def thing; :thing; end
class TestSchema < GraphQL::Schema
query(Query)
trace_with(GraphQL::Tracing::AppsignalTrace)
lazy_resolve(IntBox, :value)
end
end

Expand Down Expand Up @@ -81,13 +89,15 @@ class AppsignalAndDatadogTestSchema < GraphQL::Schema
query(AppsignalTraceTest::Query)
trace_with(GraphQL::Tracing::DataDogTrace)
trace_with(GraphQL::Tracing::AppsignalTrace)
lazy_resolve(IntBox, :value)
end

class AppsignalAndDatadogReverseOrderTestSchema < GraphQL::Schema
query(AppsignalTraceTest::Query)
# Include these modules in different order than above:
trace_with(GraphQL::Tracing::AppsignalTrace)
trace_with(GraphQL::Tracing::DataDogTrace)
lazy_resolve(IntBox, :value)
end


Expand Down
11 changes: 10 additions & 1 deletion spec/graphql/tracing/data_dog_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

describe GraphQL::Tracing::DataDogTrace do
module DataDogTraceTest
class Box
def initialize(value)
@value = value
end
attr_reader :value
end

class Thing < GraphQL::Schema::Object
field :str, String

def str; "blah"; end
def str; Box.new("blah"); end
end

class Query < GraphQL::Schema::Object
Expand All @@ -26,6 +33,7 @@ def thing; :thing; end
class TestSchema < GraphQL::Schema
query(Query)
trace_with(GraphQL::Tracing::DataDogTrace)
lazy_resolve(Box, :value)
end

class CustomTracerTestSchema < GraphQL::Schema
Expand All @@ -37,6 +45,7 @@ def prepare_span(trace_key, data, span)
end
query(Query)
trace_with(CustomDataDogTracing)
lazy_resolve(Box, :value)
end
end

Expand Down

0 comments on commit 6b01c37

Please sign in to comment.