Skip to content

Commit

Permalink
Completed typing for new tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
vpellan committed Jun 20, 2024
1 parent a564e4b commit e22728b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
1 change: 1 addition & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ target :datadog do
library 'opentelemetry-api'
library 'passenger'
library 'webmock'
library 'graphql'

# TODO: gem 'libddwaf'
library 'libddwaf'
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/graphql/unified_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module Contrib
module GraphQL
# These methods will be called by the GraphQL runtime to trace the execution of queries
module UnifiedTrace
# @param tracer [#trace] Deprecated
# @param analytics_enabled [Boolean] Deprecated
# @param analytics_sample_rate [Float] Deprecated
def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest)
# @param service [String|nil] The service name to be set on the spans
def initialize(analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest)
@analytics_enabled = analytics_enabled
@analytics_sample_rate = analytics_sample_rate

Expand Down
66 changes: 39 additions & 27 deletions sig/datadog/tracing/contrib/graphql/unified_trace.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,72 @@ module Datadog
module Contrib
module GraphQL
module UnifiedTrace
@analytics_enabled: untyped
@analytics_enabled: bool

@analytics_sample_rate: untyped
@analytics_sample_rate: Float

@service_name: untyped
@service_name: String?

@has_prepare_span: untyped
def initialize: (?tracer: untyped?, ?analytics_enabled: bool, ?analytics_sample_rate: ::Float, ?service: untyped?, **untyped rest) -> void
@has_prepare_span: bool
def initialize: (?analytics_enabled: bool, ?analytics_sample_rate: Float, ?service: String?, **Hash[Symbol, Object] rest) -> self

type lexerArray = Array[Integer | Symbol | String | nil | lexerArray]

def lex: (query_string: untyped) -> untyped
def lex: (query_string: String) -> lexerArray

def parse: (query_string: untyped) -> untyped
def parse: (query_string: String) -> GraphQL::Language::Nodes::Document

def validate: (query: untyped, validate: untyped) -> untyped
def validate: (query: GraphQL::Query, validate: bool) -> { remaining_timeout: Float?, error: Array[StandardError] }

def analyze_multiplex: (multiplex: untyped) -> untyped
def analyze_multiplex: (multiplex: GraphQL::Execution::Multiplex) -> Array[Object]

def analyze_query: (query: untyped) -> untyped
def analyze_query: (query: GraphQL::Query) -> Array[Object]

def execute_multiplex: (multiplex: untyped) -> untyped
def execute_multiplex: (multiplex: GraphQL::Execution::Multiplex) -> Array[GraphQL::Query::Result]

def execute_query: (query: untyped) -> untyped
def execute_query: (query: GraphQL::Query) -> GraphQL::Query::Result

def execute_query_lazy: (query: untyped, multiplex: untyped) -> untyped
def execute_query_lazy: (query: GraphQL::Query, multiplex: GraphQL::Execution::Multiplex) -> GraphQL::Query::Result

type executeFieldKwargs = {query: GraphQL::Query, field: GraphQL::Schema::Field, ast_node: GraphQL::Language::Nodes::Field, arguments: Hash[Symbol, String], object: GraphQL::Schema::Object?}

def execute_field_span: (untyped callable, untyped span_key, **untyped kwargs) -> untyped
def execute_field_span: (Proc callable, String span_key, **executeFieldKwargs kwargs) -> Array[Object]

def execute_field: (**untyped kwargs) -> untyped
def execute_field: (**executeFieldKwargs kwargs) -> Array[Object]

def execute_field_lazy: (**untyped kwargs) -> untyped
def execute_field_lazy: (**executeFieldKwargs kwargs) -> Array[Object]

type authorizedKwargs = {query: GraphQL::Query, type: GraphQL::Schema::Object, object: GraphQL::Schema::Object?}

def authorized_span: (untyped callable, untyped span_key, **untyped kwargs) -> untyped
def authorized_span: (Proc callable, String span_key, **authorizedKwargs kwargs) -> GraphQL::Schema::Object?

def authorized: (**untyped kwargs) -> untyped
def authorized: (**authorizedKwargs kwargs) -> GraphQL::Schema::Object?

def authorized_lazy: (**untyped kwargs) -> untyped
def authorized_lazy: (**authorizedKwargs kwargs) -> GraphQL::Schema::Object?

type resolveTypeKwargs = {query: GraphQL::Query, type: GraphQL::Schema::Union, object: GraphQL::Schema::Object?}

def resolve_type_span: (untyped callable, untyped span_key, **untyped kwargs) -> untyped
def resolve_type_span: (Proc callable, String span_key, **resolveTypeKwargs kwargs) -> [GraphQL::Schema::Object, nil]

def resolve_type: (**untyped kwargs) -> untyped
def resolve_type: (**resolveTypeKwargs kwargs) -> [GraphQL::Schema::Object, nil]

def resolve_type_lazy: (**untyped kwargs) -> untyped
def resolve_type_lazy: (**resolveTypeKwargs kwargs) -> [GraphQL::Schema::Object, nil]

def platform_field_key: (untyped field) -> untyped
def platform_field_key: (GraphQL::Schema::Field field) -> String

def platform_authorized_key: (untyped type) -> ::String
def platform_authorized_key: (GraphQL::Schema::Object type) -> String

def platform_resolve_type_key: (untyped type) -> ::String
def platform_resolve_type_key: (GraphQL::Schema::Union type) -> String

private

def trace: (untyped callable, untyped trace_key, untyped resource, **untyped kwargs) ?{ (untyped) -> untyped } -> untyped
type traceKwargsValues = GraphQL::Query | GraphQL::Schema::Union | GraphQL::Schema::Object | GraphQL::Schema::Field | GraphQL::Execution::Multiplex | GraphQL::Language::Nodes::Field | Hash[Symbol, String] | String | bool | nil

def multiplex_resource: (untyped multiplex) -> (nil | untyped)
type traceResult = lexerArray | GraphQL::Language::Nodes::Document | { remaining_timeout: Float?, error: Array[StandardError] } | Array[Object] | GraphQL::Schema::Object? | [GraphQL::Schema::Object, nil]

def trace: (Proc callable, String trace_key, String resource, **Hash[Symbol, traceKwargsValues ] kwargs) ?{ (Datadog::Tracing::SpanOperation) -> void } -> traceResult

def multiplex_resource: (GraphQL::Execution::Multiplex multiplex) -> String?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Datadog
module Contrib
module GraphQL
module UnifiedTracePatcher
def self?.patch!: (::Array[untyped] schemas, ::Hash[Symbol, untyped] options) -> untyped
def self?.patch!: (Array[GraphQL::Schema] schemas, Hash[Symbol, bool | Float | String | nil] options) -> void
end
end
end
Expand Down
37 changes: 37 additions & 0 deletions vendor/rbs/graphql/0/graphql.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module GraphQL
class Schema
class Field
end

class Object
end

class Union
end
end

module Tracing
class Trace
end
end

module Language
module Nodes
class Document
end

class Field
end
end
end

class Query
class Result
end
end

module Execution
class Multiplex
end
end
end

0 comments on commit e22728b

Please sign in to comment.