Skip to content

Commit

Permalink
Merge pull request #5190 from zvkemp/fix-requires
Browse files Browse the repository at this point in the history
require parent Tracing module before defining children
  • Loading branch information
rmosolgo authored Dec 10, 2024
2 parents dd24fce + ce1c9a1 commit 6f0f721
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 93 deletions.
58 changes: 28 additions & 30 deletions lib/graphql/tracing.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
# frozen_string_literal: true
require "graphql/tracing/trace"
require "graphql/tracing/legacy_trace"
require "graphql/tracing/legacy_hooks_trace"

# Legacy tracing:
require "graphql/tracing/active_support_notifications_tracing"
require "graphql/tracing/platform_tracing"
require "graphql/tracing/appoptics_tracing"
require "graphql/tracing/appsignal_tracing"
require "graphql/tracing/data_dog_tracing"
require "graphql/tracing/new_relic_tracing"
require "graphql/tracing/scout_tracing"
require "graphql/tracing/statsd_tracing"
require "graphql/tracing/prometheus_tracing"

# New Tracing:
require "graphql/tracing/active_support_notifications_trace"
require "graphql/tracing/platform_trace"
require "graphql/tracing/appoptics_trace"
require "graphql/tracing/appsignal_trace"
require "graphql/tracing/data_dog_trace"
require "graphql/tracing/new_relic_trace"
require "graphql/tracing/notifications_trace"
require "graphql/tracing/sentry_trace"
require "graphql/tracing/scout_trace"
require "graphql/tracing/statsd_trace"
require "graphql/tracing/prometheus_trace"
if defined?(PrometheusExporter::Server)
require "graphql/tracing/prometheus_trace/graphql_collector"
end

module GraphQL
module Tracing
NullTrace = Trace.new
autoload :Trace, "graphql/tracing/trace"
autoload :CallLegacyTracers, "graphql/tracing/call_legacy_tracers"
autoload :LegacyTrace, "graphql/tracing/legacy_trace"
autoload :LegacyHooksTrace, "graphql/tracing/legacy_hooks_trace"
autoload :NullTrace, "graphql/tracing/null_trace"

autoload :ActiveSupportNotificationsTracing, "graphql/tracing/active_support_notifications_tracing"
autoload :PlatformTracing, "graphql/tracing/platform_tracing"
autoload :AppOpticsTracing, "graphql/tracing/appoptics_tracing"
autoload :AppsignalTracing, "graphql/tracing/appsignal_tracing"
autoload :DataDogTracing, "graphql/tracing/data_dog_tracing"
autoload :NewRelicTracing, "graphql/tracing/new_relic_tracing"
autoload :NotificationsTracing, "graphql/tracing/notifications_tracing"
autoload :ScoutTracing, "graphql/tracing/scout_tracing"
autoload :StatsdTracing, "graphql/tracing/statsd_tracing"
autoload :PrometheusTracing, "graphql/tracing/prometheus_tracing"

autoload :ActiveSupportNotificationsTrace, "graphql/tracing/active_support_notifications_trace"
autoload :PlatformTrace, "graphql/tracing/platform_trace"
autoload :AppOpticsTrace, "graphql/tracing/appoptics_trace"
autoload :AppsignalTrace, "graphql/tracing/appsignal_trace"
autoload :DataDogTrace, "graphql/tracing/data_dog_trace"
autoload :NewRelicTrace, "graphql/tracing/new_relic_trace"
autoload :NotificationsTrace, "graphql/tracing/notifications_trace"
autoload :SentryTrace, "graphql/tracing/sentry_trace"
autoload :ScoutTrace, "graphql/tracing/scout_trace"
autoload :StatsdTrace, "graphql/tracing/statsd_trace"
autoload :PrometheusTrace, "graphql/tracing/prometheus_trace"

# Objects may include traceable to gain a `.trace(...)` method.
# The object must have a `@tracers` ivar of type `Array<<#trace(k, d, &b)>>`.
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/tracing/active_support_notifications_trace.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'graphql/tracing/notifications_trace'
require "graphql/tracing/notifications_trace"

module GraphQL
module Tracing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'graphql/tracing/notifications_tracing'
require "graphql/tracing/notifications_tracing"

module GraphQL
module Tracing
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/appoptics_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing

Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/appoptics_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing

Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/appsignal_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module AppsignalTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/appsignal_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
class AppsignalTracing < PlatformTracing
Expand Down
66 changes: 66 additions & 0 deletions lib/graphql/tracing/call_legacy_tracers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

module GraphQL
module Tracing
# This trace class calls legacy-style tracer with payload hashes.
# New-style `trace_with` modules significantly reduce the overhead of tracing,
# but that advantage is lost when legacy-style tracers are also used (since the payload hashes are still constructed).
module CallLegacyTracers
def lex(query_string:)
(@multiplex || @query).trace("lex", { query_string: query_string }) { super }
end

def parse(query_string:)
(@multiplex || @query).trace("parse", { query_string: query_string }) { super }
end

def validate(query:, validate:)
query.trace("validate", { validate: validate, query: query }) { super }
end

def analyze_multiplex(multiplex:)
multiplex.trace("analyze_multiplex", { multiplex: multiplex }) { super }
end

def analyze_query(query:)
query.trace("analyze_query", { query: query }) { super }
end

def execute_multiplex(multiplex:)
multiplex.trace("execute_multiplex", { multiplex: multiplex }) { super }
end

def execute_query(query:)
query.trace("execute_query", { query: query }) { super }
end

def execute_query_lazy(query:, multiplex:)
multiplex.trace("execute_query_lazy", { multiplex: multiplex, query: query }) { super }
end

def execute_field(field:, query:, ast_node:, arguments:, object:)
query.trace("execute_field", { field: field, query: query, ast_node: ast_node, arguments: arguments, object: object, owner: field.owner, path: query.context[:current_path] }) { super }
end

def execute_field_lazy(field:, query:, ast_node:, arguments:, object:)
query.trace("execute_field_lazy", { field: field, query: query, ast_node: ast_node, arguments: arguments, object: object, owner: field.owner, path: query.context[:current_path] }) { super }
end

def authorized(query:, type:, object:)
query.trace("authorized", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end

def authorized_lazy(query:, type:, object:)
query.trace("authorized_lazy", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end

def resolve_type(query:, type:, object:)
query.trace("resolve_type", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end

def resolve_type_lazy(query:, type:, object:)
query.trace("resolve_type_lazy", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end
end
end
end
2 changes: 2 additions & 0 deletions lib/graphql/tracing/data_dog_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module DataDogTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/data_dog_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
class DataDogTracing < PlatformTracing
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/tracing/legacy_hooks_trace.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GraphQL
module Tracing
module LegacyHooksTrace
Expand Down
65 changes: 4 additions & 61 deletions lib/graphql/tracing/legacy_trace.rb
Original file line number Diff line number Diff line change
@@ -1,67 +1,10 @@
# frozen_string_literal: true
module GraphQL
module Tracing
# This trace class calls legacy-style tracer with payload hashes.
# New-style `trace_with` modules significantly reduce the overhead of tracing,
# but that advantage is lost when legacy-style tracers are also used (since the payload hashes are still constructed).
module CallLegacyTracers
def lex(query_string:)
(@multiplex || @query).trace("lex", { query_string: query_string }) { super }
end

def parse(query_string:)
(@multiplex || @query).trace("parse", { query_string: query_string }) { super }
end

def validate(query:, validate:)
query.trace("validate", { validate: validate, query: query }) { super }
end

def analyze_multiplex(multiplex:)
multiplex.trace("analyze_multiplex", { multiplex: multiplex }) { super }
end

def analyze_query(query:)
query.trace("analyze_query", { query: query }) { super }
end

def execute_multiplex(multiplex:)
multiplex.trace("execute_multiplex", { multiplex: multiplex }) { super }
end

def execute_query(query:)
query.trace("execute_query", { query: query }) { super }
end

def execute_query_lazy(query:, multiplex:)
multiplex.trace("execute_query_lazy", { multiplex: multiplex, query: query }) { super }
end

def execute_field(field:, query:, ast_node:, arguments:, object:)
query.trace("execute_field", { field: field, query: query, ast_node: ast_node, arguments: arguments, object: object, owner: field.owner, path: query.context[:current_path] }) { super }
end

def execute_field_lazy(field:, query:, ast_node:, arguments:, object:)
query.trace("execute_field_lazy", { field: field, query: query, ast_node: ast_node, arguments: arguments, object: object, owner: field.owner, path: query.context[:current_path] }) { super }
end

def authorized(query:, type:, object:)
query.trace("authorized", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end

def authorized_lazy(query:, type:, object:)
query.trace("authorized_lazy", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end

def resolve_type(query:, type:, object:)
query.trace("resolve_type", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end

def resolve_type_lazy(query:, type:, object:)
query.trace("resolve_type_lazy", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
end
end
require "graphql/tracing/trace"
require "graphql/tracing/call_legacy_tracers"

module GraphQL
module Tracing
class LegacyTrace < Trace
include CallLegacyTracers
end
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/new_relic_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module NewRelicTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/new_relic_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
class NewRelicTracing < PlatformTracing
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/notifications_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
# This implementation forwards events to a notification handler (i.e.
Expand Down
9 changes: 9 additions & 0 deletions lib/graphql/tracing/null_trace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "graphql/tracing/trace"

module GraphQL
module Tracing
NullTrace = Trace.new
end
end
5 changes: 5 additions & 0 deletions lib/graphql/tracing/prometheus_trace.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module PrometheusTrace
if defined?(PrometheusExporter::Server)
autoload :GraphQLCollector, "graphql/tracing/prometheus_trace/graphql_collector"
end
include PlatformTrace

def initialize(client: PrometheusExporter::Client.default, keys_whitelist: ["execute_field", "execute_field_lazy"], collector_type: "graphql", **rest)
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/prometheus_trace/graphql_collector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing"

module GraphQL
module Tracing
module PrometheusTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/prometheus_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
class PrometheusTracing < PlatformTracing
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/scout_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module ScoutTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/scout_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
class ScoutTracing < PlatformTracing
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/sentry_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module SentryTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/statsd_trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_trace"

module GraphQL
module Tracing
module StatsdTrace
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/tracing/statsd_tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing/platform_tracing"

module GraphQL
module Tracing
class StatsdTracing < PlatformTracing
Expand Down
3 changes: 3 additions & 0 deletions lib/graphql/tracing/trace.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

require "graphql/tracing"

module GraphQL
module Tracing
# This is the base class for a `trace` instance whose methods are called during query execution.
Expand Down
Loading

0 comments on commit 6f0f721

Please sign in to comment.