Class: GraphQL::Tracing::DataDogTracing
- Inherits:
-
PlatformTracing
- Object
- PlatformTracing
- GraphQL::Tracing::DataDogTracing
- Defined in:
- lib/graphql/tracing/data_dog_tracing.rb
Instance Method Summary collapse
-
#analytics_available? ⇒ Boolean
-
#analytics_enabled? ⇒ Boolean
-
#analytics_sample_rate ⇒ Object
-
#platform_authorized_key(type) ⇒ Object
-
#platform_field_key(type, field) ⇒ Object
-
#platform_resolve_type_key(type) ⇒ Object
-
#platform_trace(platform_key, key, data) ⇒ Object
-
#prepare_span(key, data, span) ⇒ Object
Implement this method in a subclass to apply custom tags to datadog spans.
-
#service_name ⇒ Object
-
#tracer ⇒ Object
Methods inherited from PlatformTracing
Constructor Details
This class inherits a constructor from GraphQL::Tracing::PlatformTracing
Instance Method Details
#analytics_available? ⇒ Boolean
71 72 73 74 75 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 71 def analytics_available? defined?(Datadog::Contrib::Analytics) \ && Datadog::Contrib::Analytics.respond_to?(:enabled?) \ && Datadog::Contrib::Analytics.respond_to?(:set_sample_rate) end |
#analytics_enabled? ⇒ Boolean
77 78 79 80 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 77 def analytics_enabled? # [Deprecated] options[:analytics_enabled] will be removed in the future analytics_available? && Datadog::Contrib::Analytics.enabled?(.fetch(:analytics_enabled, false)) end |
#analytics_sample_rate ⇒ Object
82 83 84 85 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 82 def analytics_sample_rate # [Deprecated] options[:analytics_sample_rate] will be removed in the future .fetch(:analytics_sample_rate, 1.0) end |
#platform_authorized_key(type) ⇒ Object
91 92 93 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 91 def (type) "#{type.graphql_name}.authorized" end |
#platform_field_key(type, field) ⇒ Object
87 88 89 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 87 def platform_field_key(type, field) "#{type.graphql_name}.#{field.graphql_name}" end |
#platform_resolve_type_key(type) ⇒ Object
95 96 97 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 95 def platform_resolve_type_key(type) "#{type.graphql_name}.resolve_type" end |
#platform_trace(platform_key, key, data) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 17 def platform_trace(platform_key, key, data) 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, key) end if key == 'execute_multiplex' operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ') resource = if operations.empty? first_query = data[:multiplex].queries.first fallback_transaction_name(first_query && first_query.context) else operations end span.resource = resource if resource # For top span of query, set the analytics sample rate tag, if available. if analytics_enabled? Datadog::Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) end end if key == 'execute_query' span.set_tag(:selected_operation_name, data[:query].selected_operation_name) span.set_tag(:selected_operation_type, data[:query].selected_operation.operation_type) span.set_tag(:query_string, data[:query].query_string) end prepare_span(key, data, span) yield end end |
#prepare_span(key, data, span) ⇒ Object
Implement this method in a subclass to apply custom tags to datadog spans
62 63 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 62 def prepare_span(key, data, span) end |
#service_name ⇒ Object
54 55 56 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 54 def service_name .fetch(:service, 'ruby-graphql') end |
#tracer ⇒ Object
65 66 67 68 69 |
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 65 def tracer default_tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer .fetch(:tracer, default_tracer) end |