Module: GraphQL::Tracing::DataDogTrace
- Includes:
- PlatformTrace
- Defined in:
- lib/graphql/tracing/data_dog_trace.rb
Overview
A tracer for reporting to DataDog
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
rubocop:enable Development/NoEvalCop.
-
#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
122 123 124 125 126 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 122 def (query:, type:, object:) ("authorized", object, type, query) do super(query: query, type: type, object: object) end end |
#authorized_lazy(object:, type:, query:) ⇒ Object
141 142 143 144 145 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 141 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
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 128 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
110 111 112 113 114 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 110 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
116 117 118 119 120 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 116 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
rubocop:enable Development/NoEvalCop
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 83 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
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 16 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
185 186 187 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 185 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
181 182 183 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 181 def platform_field_key(field) field.path end |
#platform_resolve_type_key(type) ⇒ Object
189 190 191 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 189 def platform_resolve_type_key(type) "#{type.graphql_name}.resolve_type" end |
#resolve_type(object:, type:, query:) ⇒ Object
147 148 149 150 151 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 147 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
153 154 155 156 157 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 153 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
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 159 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 |