Module: GraphQL::Tracing::DataDogTrace
- Includes:
- PlatformTrace
- Defined in:
- lib/graphql/tracing/data_dog_trace.rb
Instance Method Summary collapse
- #authorized(query:, type:, object:) ⇒ Object
- #authorized_lazy(object:, type:, query:) ⇒ Object
- #authorized_span(span_key, object, type, query) ⇒ Object
- #execute_field(query:, field:, ast_node:, arguments:, object:) ⇒ Object
- #execute_field_lazy(query:, field:, ast_node:, arguments:, object:) ⇒ Object
- #execute_field_span(span_key, query, field, ast_node, arguments, object) ⇒ Object
- #initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest) ⇒ Object
- #platform_authorized_key(type) ⇒ Object
-
#platform_field_key(field) ⇒ Object
Implement this method in a subclass to apply custom tags to datadog spans def prepare_span(key, data, span) end.
- #platform_resolve_type_key(type) ⇒ Object
- #resolve_type(object:, type:, query:) ⇒ Object
- #resolve_type_lazy(object:, type:, query:) ⇒ Object
- #resolve_type_span(span_key, object, type, query) ⇒ Object
Methods included from PlatformTrace
#platform_authorized_lazy, #platform_execute_field_lazy, #platform_resolve_type_lazy
Instance Method Details
#authorized(query:, type:, object:) ⇒ Object
113 114 115 116 117 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 113 def (query:, type:, object:) ("authorized", object, type, query) do super(query: query, type: type, object: object) end end |
#authorized_lazy(object:, type:, query:) ⇒ Object
132 133 134 135 136 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 132 def (object:, type:, query:) ("authorized_lazy", object, type, query) do super(query: query, type: type, object: object) end end |
#authorized_span(span_key, object, type, query) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 119 def (span_key, object, type, query) platform_key = @platform_key_cache[DataDogTrace].[type] @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span| span.set_tag('component', 'graphql') span.set_tag('operation', span_key) if @has_prepare_span prepare_span(span_key, {object: object, type: type, query: query}, span) end yield end end |
#execute_field(query:, field:, ast_node:, arguments:, object:) ⇒ Object
101 102 103 104 105 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 101 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 |
#execute_field_lazy(query:, field:, ast_node:, arguments:, object:) ⇒ Object
107 108 109 110 111 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 107 def execute_field_lazy(query:, field:, ast_node:, arguments:, 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 |
#execute_field_span(span_key, query, field, ast_node, arguments, object) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 74 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 else true end platform_key = if trace_field @platform_key_cache[DataDogTrace].platform_field_key_cache[field] else nil end if platform_key && trace_field @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span| span.set_tag('component', 'graphql') span.set_tag('operation', span_key) if @has_prepare_span prepare_span_data = { query: query, field: field, ast_node: ast_node, arguments: arguments, object: object } prepare_span(span_key, prepare_span_data, span) end yield end else yield end end |
#initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 11 def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest) if tracer.nil? tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer end @tracer = tracer @analytics_enabled = analytics_enabled @analytics_sample_rate = analytics_sample_rate @service_name = service @has_prepare_span = respond_to?(:prepare_span) super end |
#platform_authorized_key(type) ⇒ Object
176 177 178 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 176 def (type) "#{type.graphql_name}.authorized" end |
#platform_field_key(field) ⇒ Object
Implement this method in a subclass to apply custom tags to datadog spans def prepare_span(key, data, span) end
172 173 174 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 172 def platform_field_key(field) field.path end |
#platform_resolve_type_key(type) ⇒ Object
180 181 182 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 180 def platform_resolve_type_key(type) "#{type.graphql_name}.resolve_type" end |
#resolve_type(object:, type:, query:) ⇒ Object
138 139 140 141 142 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 138 def resolve_type(object:, type:, query:) resolve_type_span("resolve_type", object, type, query) do super(object: object, query: query, type: type) end end |
#resolve_type_lazy(object:, type:, query:) ⇒ Object
144 145 146 147 148 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 144 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 |
#resolve_type_span(span_key, object, type, query) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 150 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, type: 'custom') do |span| span.set_tag('component', 'graphql') span.set_tag('operation', span_key) if @has_prepare_span prepare_span(span_key, {object: object, type: type, query: query}, span) end yield end end |