Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to validation tracing #411

Merged

Conversation

dackroyd
Copy link
Contributor

@dackroyd dackroyd commented Oct 1, 2020

Context is needed for tracing to access the current span, in order to
add tags to it, or create child spans. As presently defined (without a
context), this cannot be done: new spans could be created, but they
would not be associated with the existing request trace.

OpenTracingTracer implements the new interface (it never implemented the
old one). Via this 'extension interface', the tracer configured (or the
default tracer) will be used as the validation tracer if:

  • The tracer implements the (optional) interface; and
  • A validation tracer isn't provided using the deprecated option

What this means is that the deprecated option is preferred as an
override. This allows users to migrate in a non-breaking, non-behaviour
changing way, until such time as they intentionally remove the use of
the deprecated option. For those who are currently using the default
tracer, and not supplying a validation tracer, validation will be traced
immediately with no change required to configuration options.

@dackroyd
Copy link
Contributor Author

dackroyd commented Oct 1, 2020

Open to adjusting the implementation here. As I've currently implemented it, I'm trying to avoid making this a breaking change for anyone that is actually using the validation tracer. As mentioned however, it's impossible for tracing to work properly without supplying the existing request context containing the current span, so it may be ok for this to be a 'breaking' change instead of trying to maintain backward compatibility...

The ValidationTracerContext interface does not return a context.Context in its current form, as the validation itself doesn't accept a context. I'm unsure whether maybe it should take a context in the future, in which case the ValidationTracerContext should make sure that it returns the context it creates so that it can be used with that call.

@pavelnikolov
Copy link
Member

@dackroyd There are merge conflicts. It seems that I have merged one of the other PRs first. Would you mind resolving these. I'm sorry for the inconvenience.

Context is needed for tracing to access the current span, in order to
 add tags to it, or create child spans. As presently defined (without a
 context), this cannot be done: new spans could be created, but they
 would not be associated with the existing request trace.

OpenTracingTracer implements the new interface (it never implemented the
 old one). Via this 'extension interface', the tracer configured (or the
 default tracer) will be used as the validation tracer if:

 * The tracer implements the (optional) interface; and
 * A validation tracer isn't provided using the deprecated option

What this means is that the deprecated option is _preferred_ as an
 override. This allows users to migrate in a non-breaking, non-behaviour
 changing way, until such time as they intentionally remove the use of
 the deprecated option. For those who are currently using the default
 tracer, and not supplying a validation tracer, validation will be traced
 immediately with no change required to configuration options.
@dackroyd dackroyd force-pushed the trace-validation-context branch from d19e0c3 to 1a55b96 Compare February 19, 2021 07:50
@dackroyd
Copy link
Contributor Author

dackroyd commented Mar 6, 2021

@pavelnikolov conflicts have been addressed

@@ -117,9 +124,10 @@ func Tracer(tracer trace.Tracer) SchemaOpt {
}

// ValidationTracer is used to trace validation errors. It defaults to trace.NoopValidationTracer.
// Deprecated: context is needed to support tracing correctly. Use a Tracer which implements trace.ValidationTracerContext.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect with the comment here.

span.SetTag("graphql.error", msg)
}
span.Finish()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -67,6 +67,22 @@ func (OpenTracingTracer) TraceField(ctx context.Context, label, typeName, fieldN
}
}

func (OpenTracingTracer) TraceValidation(ctx context.Context) TraceValidationFinishFunc {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is calling this new method? I can't see where the method is being called.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I just noticed it.

@@ -186,7 +194,7 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str
return &Response{Errors: []*errors.QueryError{qErr}}
}

validationFinish := s.validationTracer.TraceValidation()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how was this used before without a context 🤷

@pavelnikolov pavelnikolov merged commit bd703c2 into graph-gophers:master Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants