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

chore: fixing parent span for graphql #299

Merged
merged 2 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/graphql/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
# Collector
collector:
# image: otel/opentelemetry-collector:latest
image: otel/opentelemetry-collector:0.13.0
image: otel/opentelemetry-collector:0.16.0
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
volumes:
- ./collector-config.yaml:/conf/collector-config.yaml
Expand Down
27 changes: 4 additions & 23 deletions plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Maybe } from 'graphql/jsutils/Maybe';
import type * as graphqlTypes from 'graphql';
import { GraphQLFieldResolver } from 'graphql/type/definition';
import { SpanAttributes, SpanNames } from './enum';
import { OTEL_GRAPHQL_DATA_SYMBOL, OTEL_SPAN_SYMBOL } from './symbols';
import { OTEL_GRAPHQL_DATA_SYMBOL } from './symbols';

import {
executeFunctionWithObj,
Expand All @@ -38,7 +38,6 @@ import {
GraphQLInstrumentationParsedConfig,
OtelExecutionArgs,
ObjectWithGraphQLData,
ObjectWithOtelSpan,
OPERATION_NOT_SUPPORTED,
} from './types';
import {
Expand Down Expand Up @@ -283,7 +282,6 @@ export class GraphQLInstrumentation extends InstrumentationBase {
},
(err, result) => {
if (result) {
(result as ObjectWithOtelSpan)[OTEL_SPAN_SYMBOL] = span;
const operation = getOperation(result);
if (!operation) {
span.updateName(SpanNames.SCHEMA_PARSE);
Expand All @@ -306,16 +304,7 @@ export class GraphQLInstrumentation extends InstrumentationBase {
typeInfo?: graphqlTypes.TypeInfo,
options?: { maxErrors?: number }
): ReadonlyArray<graphqlTypes.GraphQLError> {
const document = documentAST as ObjectWithOtelSpan;
const parentSpan = document[OTEL_SPAN_SYMBOL];
const span = this.tracer.startSpan(
SpanNames.VALIDATE,
{},
parentSpan
? api.setActiveSpan(api.context.active(), parentSpan)
: undefined
);
document[OTEL_SPAN_SYMBOL] = span;
const span = this.tracer.startSpan(SpanNames.VALIDATE, {});

return this.tracer.withSpan(span, () => {
return safeExecuteInTheMiddle<ReadonlyArray<graphqlTypes.GraphQLError>>(
Expand Down Expand Up @@ -350,16 +339,8 @@ export class GraphQLInstrumentation extends InstrumentationBase {
processedArgs: graphqlTypes.ExecutionArgs
): api.Span {
const config = this._getConfig();
const document = processedArgs.document as ObjectWithOtelSpan;

const parentSpan = document[OTEL_SPAN_SYMBOL];
const span = this.tracer.startSpan(
SpanNames.EXECUTE,
{},
parentSpan
? api.setActiveSpan(api.context.active(), parentSpan)
: undefined
);

const span = this.tracer.startSpan(SpanNames.EXECUTE, {});
if (operation) {
const name = (operation as graphqlTypes.OperationDefinitionNode)
.operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ export const OTEL_PATCHED_SYMBOL = Symbol.for('opentelemetry.patched');
export const OTEL_GRAPHQL_DATA_SYMBOL = Symbol.for(
'opentelemetry.graphql_data'
);

export const OTEL_SPAN_SYMBOL = Symbol.for('opentelemetry.span');
10 changes: 1 addition & 9 deletions plugins/node/opentelemetry-instrumentation-graphql/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ import {
GraphQLTypeResolver,
} from 'graphql/type/definition';
import { GraphQLSchema } from 'graphql/type/schema';
import {
OTEL_GRAPHQL_DATA_SYMBOL,
OTEL_PATCHED_SYMBOL,
OTEL_SPAN_SYMBOL,
} from './symbols';
import { OTEL_GRAPHQL_DATA_SYMBOL, OTEL_PATCHED_SYMBOL } from './symbols';

export const OPERATION_NOT_SUPPORTED =
'Operation$operationName$not' + ' supported';
Expand Down Expand Up @@ -130,10 +126,6 @@ interface OtelGraphQLData {
fields: { [key: string]: GraphQLField };
}

export interface ObjectWithOtelSpan {
[OTEL_SPAN_SYMBOL]?: api.Span;
}

export interface ObjectWithGraphQLData {
[OTEL_GRAPHQL_DATA_SYMBOL]?: OtelGraphQLData;
}
Expand Down
Loading