summaryrefslogtreecommitdiff
path: root/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
committerMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
commite9c24f4af7ed56760f6db7941827d09f6db9020b (patch)
tree62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace
parent58d5e7cfda4781d8a57ec52aefd02983835c301a (diff)
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace')
-rw-r--r--teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/trace.go96
-rw-r--r--teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/validation_trace.go25
2 files changed, 121 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/trace.go b/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/trace.go
new file mode 100644
index 0000000..8d5d8a7
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/trace.go
@@ -0,0 +1,96 @@
+package trace
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/graph-gophers/graphql-go/errors"
+ "github.com/graph-gophers/graphql-go/introspection"
+ opentracing "github.com/opentracing/opentracing-go"
+ "github.com/opentracing/opentracing-go/ext"
+ "github.com/opentracing/opentracing-go/log"
+)
+
+type TraceQueryFinishFunc func([]*errors.QueryError)
+type TraceFieldFinishFunc func(*errors.QueryError)
+
+type Tracer interface {
+ TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, TraceQueryFinishFunc)
+ TraceField(ctx context.Context, label, typeName, fieldName string, trivial bool, args map[string]interface{}) (context.Context, TraceFieldFinishFunc)
+}
+
+type OpenTracingTracer struct{}
+
+func (OpenTracingTracer) TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, TraceQueryFinishFunc) {
+ span, spanCtx := opentracing.StartSpanFromContext(ctx, "GraphQL request")
+ span.SetTag("graphql.query", queryString)
+
+ if operationName != "" {
+ span.SetTag("graphql.operationName", operationName)
+ }
+
+ if len(variables) != 0 {
+ span.LogFields(log.Object("graphql.variables", variables))
+ }
+
+ return spanCtx, func(errs []*errors.QueryError) {
+ if len(errs) > 0 {
+ msg := errs[0].Error()
+ if len(errs) > 1 {
+ msg += fmt.Sprintf(" (and %d more errors)", len(errs)-1)
+ }
+ ext.Error.Set(span, true)
+ span.SetTag("graphql.error", msg)
+ }
+ span.Finish()
+ }
+}
+
+func (OpenTracingTracer) TraceField(ctx context.Context, label, typeName, fieldName string, trivial bool, args map[string]interface{}) (context.Context, TraceFieldFinishFunc) {
+ if trivial {
+ return ctx, noop
+ }
+
+ span, spanCtx := opentracing.StartSpanFromContext(ctx, label)
+ span.SetTag("graphql.type", typeName)
+ span.SetTag("graphql.field", fieldName)
+ for name, value := range args {
+ span.SetTag("graphql.args."+name, value)
+ }
+
+ return spanCtx, func(err *errors.QueryError) {
+ if err != nil {
+ ext.Error.Set(span, true)
+ span.SetTag("graphql.error", err.Error())
+ }
+ span.Finish()
+ }
+}
+
+func (OpenTracingTracer) TraceValidation(ctx context.Context) TraceValidationFinishFunc {
+ span, _ := opentracing.StartSpanFromContext(ctx, "Validate Query")
+
+ return func(errs []*errors.QueryError) {
+ if len(errs) > 0 {
+ msg := errs[0].Error()
+ if len(errs) > 1 {
+ msg += fmt.Sprintf(" (and %d more errors)", len(errs)-1)
+ }
+ ext.Error.Set(span, true)
+ span.SetTag("graphql.error", msg)
+ }
+ span.Finish()
+ }
+}
+
+func noop(*errors.QueryError) {}
+
+type NoopTracer struct{}
+
+func (NoopTracer) TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, TraceQueryFinishFunc) {
+ return ctx, func(errs []*errors.QueryError) {}
+}
+
+func (NoopTracer) TraceField(ctx context.Context, label, typeName, fieldName string, trivial bool, args map[string]interface{}) (context.Context, TraceFieldFinishFunc) {
+ return ctx, func(err *errors.QueryError) {}
+}
diff --git a/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/validation_trace.go b/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/validation_trace.go
new file mode 100644
index 0000000..bce7a9a
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/graph-gophers/graphql-go/trace/validation_trace.go
@@ -0,0 +1,25 @@
+package trace
+
+import (
+ "context"
+
+ "github.com/graph-gophers/graphql-go/errors"
+)
+
+type TraceValidationFinishFunc = TraceQueryFinishFunc
+
+// Deprecated: use ValidationTracerContext.
+type ValidationTracer interface {
+ TraceValidation() TraceValidationFinishFunc
+}
+
+type ValidationTracerContext interface {
+ TraceValidation(ctx context.Context) TraceValidationFinishFunc
+}
+
+type NoopValidationTracer struct{}
+
+// Deprecated: use a Tracer which implements ValidationTracerContext.
+func (NoopValidationTracer) TraceValidation() TraceValidationFinishFunc {
+ return func(errs []*errors.QueryError) {}
+}