Skip to content

refactor: remove graphql variables, result, context attributes #289

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

Merged
merged 4 commits into from
Apr 27, 2024
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
3 changes: 0 additions & 3 deletions apps/collector-proxy/src/workers/foreign-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export function foreignTracesWorker({ client }: { client: DebuggerClient }) {
errorMessage: span.errorMessage,
errorStack: span.errorStack,
graphqlDocument: span.graphqlDocument,
graphqlVariables: span.graphqlVariables,
graphqlResult: span.graphqlResult,
graphqlContext: span.graphqlContext,
isForeign: span.isForeign,
attributes: JSON.stringify(span.attributes),
},
Expand Down
3 changes: 0 additions & 3 deletions apps/collector-proxy/src/workers/post-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export function postTracesWorker({
errorMessage: span.errorMessage,
errorStack: span.errorStack,
graphqlDocument: span.graphqlDocument,
graphqlVariables: span.graphqlVariables,
graphqlResult: span.graphqlResult,
graphqlContext: span.graphqlContext,
graphqlSchemaHash: span.graphqlSchemaHash,
graphqlOperationName: span.graphqlOperationName,
graphqlOperationType: span.graphqlOperationType,
Expand Down
15 changes: 0 additions & 15 deletions apps/ui/src/demo/create-post-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ createPost.spans.push({
[AttributeNames.DOCUMENT]: postsdQueryStr,
}),
graphqlDocument: postsdQueryStr,
graphqlContext: JSON.stringify({
"X-Forwarded-For": "http://localhost:3000",
"secret-token-123": "Bearer token",
}),
graphqlVariables: JSON.stringify({
title: "First post",
content: "This is the first post",
}),
graphqlResult: JSON.stringify({
data: {
id: "1",
title: "First post",
content: "This is the first post",
},
}),
});

// Child spans simulating ORM and SQL queries, and post attributes processing
Expand Down
7 changes: 0 additions & 7 deletions apps/ui/src/demo/fail-create-post-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ failCreatePost.spans.push({
[AttributeNames.DOCUMENT]: postsdQueryStr,
}),
graphqlDocument: postsdQueryStr,
graphqlContext: JSON.stringify({
"X-Forwarded-For": "http://localhost:3000",
}),
graphqlVariables: JSON.stringify({
title: "First post",
content: "This is the first post",
}),
errorMessage: "Token Missing",
errorStack: "Error: Token Missing\n at login (index.js:1:1)",
});
21 changes: 0 additions & 21 deletions apps/ui/src/demo/login-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ successfullLogin.spans.push({
[AttributeNames.DOCUMENT]: loginMutation,
}),
graphqlDocument: loginMutation,
graphqlVariables: JSON.stringify({
username: "test",
password: "test",
}),
graphqlContext: JSON.stringify({
"X-Forwarded-For": "http://localhost:3000",
"secret-token-123": "Bearer token",
}),
graphqlResult: JSON.stringify({
data: {
login: "Bearer token",
},
}),
});

// ORM CALL and SQL Query for successful login
Expand Down Expand Up @@ -168,14 +155,6 @@ failedLogin.spans.push({
graphqlDocument: loginMutation,
errorMessage: "Invalid credentials",
errorStack: "Error: Invalid credentials\n at login (index.js:1:1)",
graphqlVariables: JSON.stringify({
username: "test",
password: "test",
}),
graphqlContext: JSON.stringify({
"X-Forwarded-For": "http://localhost:3000",
"secret-token-123": "Bearer token",
}),
});

// ORM CALL and SQL Query for failed login
Expand Down
24 changes: 0 additions & 24 deletions apps/ui/src/demo/me-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@ meQueryTrace.spans.push({
[AttributeNames.DOCUMENT]: meQuery,
}),
graphqlDocument: meQuery,
graphqlContext: JSON.stringify({
"X-Forwarded-For": "http://localhost:3000",
"secret-token-123": "Bearer token",
}),
graphqlResult: JSON.stringify({
data: {
me: {
id: "user_id",
username: "test",
posts: [
{
id: "1",
title: "First post",
content: "This is the first post",
},
{
id: "2",
title: "Second post",
content: "This is the second post",
},
],
},
},
}),
});

meQueryTrace.spans.push({
Expand Down
20 changes: 0 additions & 20 deletions apps/ui/src/demo/posts-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,6 @@ postQuery.spans.push({
[AttributeNames.DOCUMENT]: postsdQueryStr,
}),
graphqlDocument: postsdQueryStr,
graphqlContext: JSON.stringify({
"X-Forwarded-For": "http://localhost:3000",
"secret-token-123": "Bearer token",
}),
graphqlResult: JSON.stringify({
data: {
posts: [
{
id: "1",
title: "First post",
content: "This is the first post",
},
{
id: "2",
title: "Second post",
content: "This is the second post",
},
],
},
}),
});

// Child spans simulating ORM and SQL queries, and post attributes processing
Expand Down
5 changes: 0 additions & 5 deletions apps/ui/src/utils/__tests__/trace-name-includes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const trace: Trace = {
durationNano: "19395200",
graphqlDocument:
"query ($where: ListTraceGroupsWhere, $includeSpans: Boolean = false, $includeRootSpan: Boolean = false) {\n listTraceGroups(where: $where) {\n traces {\n id\n traceId\n firstSpanErrorMessage\n firstSpanErrorStack\n spans @include(if: $includeSpans) {\n ...SpanObject\n }\n rootSpan @include(if: $includeRootSpan) {\n ...SpanObject\n }\n }\n }\n}",
graphqlVariables:
'{"args":{"where":{"rootSpanName":null,"schemaId":"9c47e081-44ec-4256-8a40-79c162df3a57"}}}',
graphqlResult: null,
graphqlContext:
'{"context":{"waitUntil":"Function","loaders":{"rootSpanLoader":{"_batchLoadFn":"Function","_maxBatchSize":null,"_batchScheduleFn":"Function","_cacheKeyFn":"Function","_cacheMap":{},"_batch":null,"name":null},"spanLoader":{"_batchLoadFn":"Function","_maxBatchSize":null,"_batchScheduleFn":"Function","_cacheKeyFn":"Function","_cacheMap":{},"_batch":null,"name":null}}}}',
graphqlOperationName: null,
graphqlOperationType: "query",
},
Expand Down
11 changes: 2 additions & 9 deletions apps/ui/src/utils/mappers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
export const metaMapper: Record<string, string> = {
variables: "JSON variables attached to the Query.",
result: "The result of the Query.",
context: "Safe JSON of the GraphQL context obj.",
errors: "Errors of each resolver",
};

export const jsonMapper: Record<string, string> = {
variables: "graphqlVariables",
result: "graphqlResult",
context: "graphqlContext",
};
export const jsonMapper: Record<string, string> = {};

export const variablesHeader = ["Variables", "Result", "Context", "Errors"];
export const variablesHeader = ["Errors"];

export const kindKeywordMapper: Record<string, string> = {
ObjectTypeDefinition: "type",
Expand Down
7 changes: 0 additions & 7 deletions e2e/tests/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ describe("trace", () => {
expect(print(parse(editorValues.query))).toEqual(
rootSpan?.graphqlDocument,
);
expect(JSON.parse(editorValues.variables as string)).toMatchObject(
JSON.parse(rootSpan?.graphqlVariables as string),
);

if (variant.shouldError) {
const sanitizedUIError = JSON.parse(
Expand All @@ -147,10 +144,6 @@ describe("trace", () => {
}),
),
);
} else {
expect(JSON.parse(editorValues.result as string)).toMatchObject(
JSON.parse(rootSpan?.graphqlResult as string),
);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ describe("Span", () => {
});

const graphqlDocument = faker.lorem.words();
const graphqlVariables = faker.lorem.words();
const graphqlResult = faker.lorem.words();
const graphqlContext = faker.lorem.words();
const graphqlOperationName = faker.lorem.words();
const graphqlOperationType = faker.lorem.words();

Expand All @@ -42,9 +39,6 @@ describe("Span", () => {
traceGroupId: createdTrace?.trace?.id,
isGraphQLRootSpan: true,
graphqlDocument,
graphqlVariables,
graphqlResult,
graphqlContext,
graphqlOperationName,
graphqlOperationType,
isForeign: false,
Expand Down
6 changes: 0 additions & 6 deletions packages/adapters/proxy/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export async function createFakeSpan({
const errorMessage = shouldError ? faker.lorem.words() : undefined;
const errorStack = shouldError ? faker.lorem.words() : undefined;
const graphqlDocument = faker.lorem.words();
const graphqlVariables = faker.lorem.words();
const graphqlResult = faker.lorem.words();
const graphqlContext = faker.lorem.words();
const graphqlSchemaHash = faker.lorem.words();
const graphqlOperationName = faker.lorem.words();
const graphqlOperationType = faker.lorem.words();
Expand All @@ -70,9 +67,6 @@ export async function createFakeSpan({
errorMessage: errorMessage,
errorStack: errorStack,
graphqlDocument: graphqlDocument,
graphqlVariables: graphqlVariables,
graphqlResult: graphqlResult,
graphqlContext: graphqlContext,
graphqlSchemaHash: graphqlSchemaHash,
graphqlOperationName: graphqlOperationName,
graphqlOperationType: graphqlOperationType,
Expand Down
3 changes: 0 additions & 3 deletions packages/adapters/sqlite/src/entities/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ export class SQLiteSpan extends BaseSpan {
errorMessage: input.errorMessage,
errorStack: input.errorStack,
graphqlDocument: input.graphqlDocument,
graphqlVariables: input.graphqlVariables,
graphqlResult: input.graphqlResult,
graphqlContext: input.graphqlContext,
graphqlSchemaHash: input.graphqlSchemaHash,
graphqlOperationName: input.graphqlOperationName,
graphqlOperationType: input.graphqlOperationType,
Expand Down
6 changes: 0 additions & 6 deletions packages/adapters/sqlite/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export async function createFakeSpan({
const errorMessage = shouldError ? faker.random.words() : undefined;
const errorStack = shouldError ? faker.random.words() : undefined;
const graphqlDocument = faker.random.words();
const graphqlVariables = faker.random.words();
const graphqlResult = faker.random.words();
const graphqlContext = faker.random.words();
const graphqlSchemaHash = faker.random.words();
const graphqlOperationName = faker.random.words();
const graphqlOperationType = faker.random.words();
Expand All @@ -64,9 +61,6 @@ export async function createFakeSpan({
errorMessage: errorMessage,
errorStack: errorStack,
graphqlDocument: graphqlDocument,
graphqlVariables: graphqlVariables,
graphqlResult: graphqlResult,
graphqlContext: graphqlContext,
graphqlSchemaHash: graphqlSchemaHash,
graphqlOperationName: graphqlOperationName,
durationNano: endTimeUnixNano - startTimeUnixNano,
Expand Down
3 changes: 0 additions & 3 deletions packages/data-access/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ model Span {
graphqlOperationName String?
graphqlOperationType String?
graphqlDocument String?
graphqlVariables String?
graphqlResult String?
graphqlContext String?
graphqlSchemaHash String?
attributes String?
errorMessage String?
Expand Down
3 changes: 0 additions & 3 deletions packages/graphql-fragments/src/SpanFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export const SpanFragment = gql`
startTimeUnixNano
durationNano
graphqlDocument
graphqlVariables
graphqlResult
graphqlContext
graphqlOperationName
graphqlOperationType
createdAt
Expand Down
9 changes: 0 additions & 9 deletions packages/graphql-schema/src/mutations/create-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ const CreateSpanInputObject: InputRef<CreateSpanInput> = builder.inputType(
graphqlDocument: t.string({
required: false,
}),
graphqlVariables: t.string({
required: false,
}),
graphqlResult: t.string({
required: false,
}),
graphqlContext: t.string({
required: false,
}),
graphqlSchemaHash: t.string({
required: false,
}),
Expand Down
3 changes: 0 additions & 3 deletions packages/graphql-schema/src/objects/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export const SpanObject: ObjectRef<Span> = builder.objectType("Span", {
startTimeUnixNano: t.exposeString("startTimeUnixNano"),
endTimeUnixNano: t.exposeString("endTimeUnixNano"),
graphqlDocument: t.exposeString("graphqlDocument", { nullable: true }),
graphqlVariables: t.exposeString("graphqlVariables", { nullable: true }),
graphqlResult: t.exposeString("graphqlResult", { nullable: true }),
graphqlContext: t.exposeString("graphqlContext", { nullable: true }),
graphqlOperationName: t.exposeString("graphqlOperationName", {
nullable: true,
}),
Expand Down
36 changes: 0 additions & 36 deletions packages/opentelemetry/src/extract-spans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export function extractSpans({
] as string | undefined;

let graphqlDocument: string | undefined;
let graphqlVariables: string | undefined;
let graphqlResult: string | undefined;
let graphqlContext: string | undefined;
let errorMessage: string | undefined;
let errorStack: string | undefined;

Expand All @@ -56,43 +53,13 @@ export function extractSpans({
debug("Error parsing document", error);
}
}

const variables = attributes[AttributeNames.OPERATION_ARGS];
if (variables) {
try {
graphqlVariables = JSON.stringify(JSON.parse(variables));
} catch (error) {
debug("Error parsing variables", error);
}
}

const result = attributes[AttributeNames.OPERATION_RESULT];
if (result) {
try {
graphqlResult = JSON.stringify(JSON.parse(result));
} catch (error) {
debug("Error parsing result", error);
}
}

const context = attributes[AttributeNames.OPERATION_CONTEXT];
if (context) {
try {
graphqlContext = JSON.stringify(JSON.parse(context));
} catch (error) {
debug("Error parsing context", error);
}
}
}

const remainingAttributes = Object.entries(attributes).reduce(
(acc, [key, value]) => {
if (
key !== AttributeNames.SCHEMA_HASH &&
key !== AttributeNames.DOCUMENT &&
key !== AttributeNames.OPERATION_ARGS &&
key !== AttributeNames.OPERATION_RESULT &&
key !== AttributeNames.OPERATION_CONTEXT &&
key !== AttributeNames.OPERATION_ROOT_NAME
) {
acc[key] = value;
Expand Down Expand Up @@ -132,9 +99,6 @@ export function extractSpans({
graphqlDocument,
graphqlOperationName,
graphqlOperationType,
graphqlVariables,
graphqlResult,
graphqlContext,
errorMessage,
errorStack,
};
Expand Down
Loading