mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-18 14:16:48 +00:00
feat(graphql): log query name if operation name is not provided (#10420)
This commit is contained in:
parent
34233deb51
commit
4ebc31c8c2
@ -119,14 +119,15 @@ public class GraphQLController {
|
|||||||
true, authentication, _authorizerChain, systemOperationContext, query, variables);
|
true, authentication, _authorizerChain, systemOperationContext, query, variables);
|
||||||
Span.current().setAttribute("actor.urn", context.getActorUrn());
|
Span.current().setAttribute("actor.urn", context.getActorUrn());
|
||||||
|
|
||||||
|
// operationName is an optional field only required if multiple operations are present
|
||||||
|
final String queryName = operationName != null ? operationName : context.getQueryName();
|
||||||
final String threadName = Thread.currentThread().getName();
|
final String threadName = Thread.currentThread().getName();
|
||||||
log.info(
|
log.info("Processing request, operation: {}, actor urn: {}", queryName, context.getActorUrn());
|
||||||
"Processing request, operation: {}, actor urn: {}", operationName, context.getActorUrn());
|
|
||||||
log.debug("Query: {}, variables: {}", query, variables);
|
log.debug("Query: {}, variables: {}", query, variables);
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(
|
return CompletableFuture.supplyAsync(
|
||||||
() -> {
|
() -> {
|
||||||
log.info("Executing operation {} for {}", operationName, threadName);
|
log.info("Executing operation {} for {}", queryName, threadName);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Execute GraphQL Query
|
* Execute GraphQL Query
|
||||||
@ -149,13 +150,12 @@ public class GraphQLController {
|
|||||||
try {
|
try {
|
||||||
long totalDuration = submitMetrics(executionResult);
|
long totalDuration = submitMetrics(executionResult);
|
||||||
String executionTook = totalDuration > 0 ? " in " + totalDuration + " ms" : "";
|
String executionTook = totalDuration > 0 ? " in " + totalDuration + " ms" : "";
|
||||||
log.info("Executed operation {}" + executionTook, operationName);
|
log.info("Executed operation {}" + executionTook, queryName);
|
||||||
// Remove tracing from response to reduce bulk, not used by the frontend
|
// Remove tracing from response to reduce bulk, not used by the frontend
|
||||||
executionResult.getExtensions().remove("tracing");
|
executionResult.getExtensions().remove("tracing");
|
||||||
String responseBodyStr =
|
String responseBodyStr =
|
||||||
new ObjectMapper().writeValueAsString(executionResult.toSpecification());
|
new ObjectMapper().writeValueAsString(executionResult.toSpecification());
|
||||||
log.info(
|
log.info("Operation {} execution result size: {}", queryName, responseBodyStr.length());
|
||||||
"Operation {} execution result size: {}", operationName, responseBodyStr.length());
|
|
||||||
log.trace("Execution result: {}", responseBodyStr);
|
log.trace("Execution result: {}", responseBodyStr);
|
||||||
return new ResponseEntity<>(responseBodyStr, HttpStatus.OK);
|
return new ResponseEntity<>(responseBodyStr, HttpStatus.OK);
|
||||||
} catch (IllegalArgumentException | JsonProcessingException e) {
|
} catch (IllegalArgumentException | JsonProcessingException e) {
|
||||||
|
@ -17,6 +17,7 @@ public class SpringQueryContext implements QueryContext {
|
|||||||
private final boolean isAuthenticated;
|
private final boolean isAuthenticated;
|
||||||
private final Authentication authentication;
|
private final Authentication authentication;
|
||||||
private final Authorizer authorizer;
|
private final Authorizer authorizer;
|
||||||
|
@Getter private final String queryName;
|
||||||
@Nonnull private final OperationContext operationContext;
|
@Nonnull private final OperationContext operationContext;
|
||||||
|
|
||||||
public SpringQueryContext(
|
public SpringQueryContext(
|
||||||
@ -30,7 +31,7 @@ public class SpringQueryContext implements QueryContext {
|
|||||||
this.authentication = authentication;
|
this.authentication = authentication;
|
||||||
this.authorizer = authorizer;
|
this.authorizer = authorizer;
|
||||||
|
|
||||||
String queryName =
|
this.queryName =
|
||||||
new Parser()
|
new Parser()
|
||||||
.parseDocument(jsonQuery).getDefinitions().stream()
|
.parseDocument(jsonQuery).getDefinitions().stream()
|
||||||
.filter(def -> def instanceof OperationDefinition)
|
.filter(def -> def instanceof OperationDefinition)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user