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

GraphQL java instrumentation #5583

Merged
merged 11 commits into from
Mar 17, 2022
Merged

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Mar 15, 2022

Resolves #4270
Unlike #4337, that attempted to generate the same kind of telemetry as js instrumentation, the instrumentation in this pr generates only a single span for each graphql request. I chose not to follow js implementation as in my opinion it didn't really align with our existing instrumentations. To understand what kind of spans are generated by js implementation it is easiest to look at their test.

@laurit laurit requested a review from a team as a code owner March 15, 2022 15:21
return !draftVersion
}

companion object {
private val GIT_SHA_PATTERN = Regex("^.*-[0-9a-f]{7,}$")
private val DATETIME_PATTERN = Regex("^\\d{4}-\\d{2}-\\d{2}t\\d{2}-\\d{2}-\\d{2}.*$")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

graphql-java has a ton of weird versions https://repo1.maven.org/maven2/com/graphql-java/graphql-java/

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
namedOneOf("checkInstrumentationDefaultState", "checkInstrumentation")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These methods add default instrumentations. By applying our instrumentation after these our instrumentation will end up surrounding all other instrumentation.

public class ExperimentalAttributesExtractor
implements AttributesExtractor<InstrumentationExecutionParameters, ExecutionResult> {
// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts
private static final AttributeKey<String> OPERATION_NAME =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these attributes are the same as in js instrumentation

import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;

@SuppressWarnings("AbbreviationAsWordInName")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed on slack, for library instrumentation I used GraphQL which isn't allowed by our checkstyle rules


Span span = Span.fromContext(context);
for (GraphQLError error : result.getErrors()) {
AttributesBuilder attributes = Attributes.builder();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Record errors (validation and parse errors etc) as exceptions. I don't know whether this is ok.

Copy link
Member

Choose a reason for hiding this comment

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

I re-read the exceptions spec and it seems ok. Is this what JS implementation does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

void validationError() {
ExecutionResult result =
graphql.execute(
"" //
Copy link
Contributor Author

Choose a reason for hiding this comment

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

// prevents spotless from moving these to a single line. Alternatively could use // spotless:off which would need to be enabled with toggleOffOn()

Copy link
Member

Choose a reason for hiding this comment

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

Out of these two I think I'd probably prefer using // spotless:off for such use cases (though this one works too, I don't have a very strong opinion on that)

Copy link
Member

Choose a reason for hiding this comment

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

// spotless:off leaves less doubt about what the strange trailing slashes are for 👍


Span span = Span.fromContext(context);
for (GraphQLError error : result.getErrors()) {
AttributesBuilder attributes = Attributes.builder();
Copy link
Member

Choose a reason for hiding this comment

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

I re-read the exceptions spec and it seems ok. Is this what JS implementation does?

void validationError() {
ExecutionResult result =
graphql.execute(
"" //
Copy link
Member

Choose a reason for hiding this comment

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

Out of these two I think I'd probably prefer using // spotless:off for such use cases (though this one works too, I don't have a very strong opinion on that)

laurit and others added 3 commits March 16, 2022 14:30
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
void validationError() {
ExecutionResult result =
graphql.execute(
"" //
Copy link
Member

Choose a reason for hiding this comment

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

// spotless:off leaves less doubt about what the strange trailing slashes are for 👍

laurit and others added 3 commits March 16, 2022 19:18
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@trask trask merged commit 2ebe912 into open-telemetry:main Mar 17, 2022
@trask
Copy link
Member

trask commented Mar 17, 2022

🥳

@jord1e
Copy link
Contributor

jord1e commented Mar 17, 2022

haha cool!

@laurit laurit deleted the graphql-java-support branch March 17, 2022 19:51
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* GraphQL Java Initial Commit

* [WIP] First steps for GraphQL instrumentation, totally not ready

[skip ci]

* GraphQL Java instrumentation

* address review comments

* Apply suggestions from code review

Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>

* review feedback

* scope handling

* Apply suggestions from code review

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

* use spotless:off

* trigger build

* review comments

Co-authored-by: Jordie <xd@jrdie.nl>
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
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.

Add GraphQL Java Instrumentation
4 participants