-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Provide ability to specify client info in traces #1631
Changes from 4 commits
b43cdd3
fd3f5de
adae6f7
a6328b9
843fd64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,3 +350,13 @@ addMockFunctionsToSchema({ | |
* `maskErrorDetails`: boolean | ||
|
||
Set to true to remove error details from the traces sent to Apollo's servers. Defaults to false. | ||
|
||
* generateClientInfo?: (o: { context: any, extensions?: Record<string, any>}) => ClientInfo; | ||
|
||
Creates the client information that is attached to the traces sent to the | ||
Apollo backend. The context field is the execution context passed to the | ||
resolvers and the extensions field is the field provided in the request's | ||
query, operationName, and variables. `ClientInfo` contains fields for | ||
`clientName` and `clientVersion`, which can both be optional. The default | ||
value copies the respective fields from the `extensions`'s `clientInfo` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it clear enough to just say "the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like POST body's |
||
field. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import { | |
} from 'graphql-extensions'; | ||
import { Trace, google } from 'apollo-engine-reporting-protobuf'; | ||
|
||
import { EngineReportingOptions } from './agent'; | ||
import { EngineReportingOptions, ClientInfo } from './agent'; | ||
import { defaultSignature } from './signature'; | ||
|
||
// EngineReportingExtension is the per-request GraphQLExtension which creates a | ||
|
@@ -38,6 +38,12 @@ export class EngineReportingExtension<TContext = any> | |
operationName: string, | ||
trace: Trace, | ||
) => void; | ||
private generateClientInfo: ( | ||
o: { | ||
context: any; | ||
extensions?: Record<string, any>; | ||
}, | ||
) => ClientInfo; | ||
|
||
public constructor( | ||
options: EngineReportingOptions, | ||
|
@@ -51,6 +57,10 @@ export class EngineReportingExtension<TContext = any> | |
const root = new Trace.Node(); | ||
this.trace.root = root; | ||
this.nodes.set(responsePathAsString(undefined), root); | ||
this.generateClientInfo = | ||
options.generateClientInfo || | ||
// Default to using the clientInfo field of the request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clientInfo extensions field |
||
(({ extensions }) => (extensions && extensions.clientInfo) || {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public requestDidStart(o: { | ||
|
@@ -60,6 +70,8 @@ export class EngineReportingExtension<TContext = any> | |
variables?: Record<string, any>; | ||
persistedQueryHit?: boolean; | ||
persistedQueryRegister?: boolean; | ||
context: any; | ||
extensions?: Record<string, any>; | ||
}): EndHandler { | ||
this.trace.startTime = dateToTimestamp(new Date()); | ||
this.startHrTime = process.hrtime(); | ||
|
@@ -154,6 +166,16 @@ export class EngineReportingExtension<TContext = any> | |
}); | ||
} | ||
|
||
// While clientAddress could be a part of the protobuf, we'll ignore it for | ||
// now, since the backend does not group by it and Engine frontend will not | ||
// support it in the short term | ||
const { clientName, clientVersion } = this.generateClientInfo({ | ||
context: o.context, | ||
extensions: o.extensions, | ||
}); | ||
this.trace.clientName = clientName || ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do empty string for unrecognized clients or have a designated enum, like "UNKNOWN"? Either way, we should think about what happens with clients that specify their client information as the default we use for unknown clients -- is that OK? |
||
this.trace.clientVersion = clientVersion || ''; | ||
|
||
return () => { | ||
this.trace.durationNs = durationHrTimeToNanos( | ||
process.hrtime(this.startHrTime), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can both be null?