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: "ruby-graphql", **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
120 121 122 123 124 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 120 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
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 126 def (span_key, object, type, query) platform_key = @platform_key_cache[DataDogTrace].[type] @tracer.trace(platform_key, service: @service_name) do |span| span.span_type = 'custom' if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0 span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql') span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key) end 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
108 109 110 111 112 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 108 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
114 115 116 117 118 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 114 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
79 80 81 82 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 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 79 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) do |span| span.span_type = 'custom' if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0 span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql') span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key) end 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: "ruby-graphql", **rest) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 8 def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: "ruby-graphql", **rest) if tracer.nil? tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer end @tracer = tracer analytics_available = defined?(Datadog::Contrib::Analytics) \ && Datadog::Contrib::Analytics.respond_to?(:enabled?) \ && Datadog::Contrib::Analytics.respond_to?(:set_sample_rate) @analytics_enabled = analytics_available && Datadog::Contrib::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
187 188 189 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 187 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
183 184 185 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 183 def platform_field_key(field) field.path end |
#platform_resolve_type_key(type) ⇒ Object
191 192 193 |
# File 'lib/graphql/tracing/data_dog_trace.rb', line 191 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 171 172 |
# 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) do |span| span.span_type = 'custom' if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0 span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql') span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key) end if @has_prepare_span prepare_span(span_key, {object: object, type: type, query: query}, span) end yield end end |