-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
continueTrace
with startInactiveSpan
does not work correctly with Sentry v8
#13126
Comments
Hey, do you actually need to manually continue the trace at all in v8? I would have thought that this should be automatically continued anyhow? Looking at the issue you linked, I do see the span you started there connected to the frontend - If you click "View full trace" at the top of the issue, the trace contains a Generally speaking, could you share your |
Sorry, I didn't provide enough links to refer to. |
The following is the log Log
|
Can you show us your
I wonder why this is printed at all, given we're starting spans afterwards
So this suggests to me that a span was actually started and sent but it's not connected to the error that was thrown in between. Also, would you mind letting us know why you need to call |
The following is Code Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.APP_ENV,
enabled: true,
debug: true,
release: process.env.SENTRY_RELEASE,
serverName: 'app',
sampleRate: 1.0,
tracesSampleRate: 1.0,
normalizeDepth: 10,
beforeSend(event, hint) {
event.fingerprint = [
'{{ default }}',
event.exception?.values?.[0]?.type ?? '',
event.exception?.values?.[0]?.value ?? '',
];
return event;
},
});
const server = new ApolloServer({
context: async ({ req }): Promise<Context> => {
const sentryTraceHeaders = req.headers['sentry-trace'];
const sentryTrace = Array.isArray(sentryTraceHeaders) ? sentryTraceHeaders.join(',') : sentryTraceHeaders;
const baggage = req.headers['baggage'];
const sentrySpan = Sentry.continueTrace({ sentryTrace, baggage }, () => {
return Sentry.startInactiveSpan({
op: 'gql',
name: req.body.operationName,
});
});
return { sentrySpan };
},
plugins: [
ApolloServerSentryPlugin,
],
);
const ApolloServerSentryPlugin: ApolloServerPlugin<Context> = {
requestDidStart: async () => ({
didEncounterErrors: async ({ contextValue, errors, request }) => {
errors.forEach((error) => {
reportError(error, { cloudTraceId: contextValue.cloudTraceId, user: contextValue.user, request });
});
},
willSendResponse: async ({ contextValue }) => {
contextValue.sentrySpan?.end();
},
}),
};
export const reportError = (
err: Error | GraphQLError,
{ cloudTraceId, request, user }: { cloudTraceId?: string; request?: GraphQLRequest; user?: Context['user'] },
) => {
Sentry.withScope((scope) => {
scope.setTag('cloud_trace_id', cloudTraceId);
scope.setExtra('error', err);
if (request) {
const { operationName, query, variables } = request;
scope.setTag('operationName', operationName);
scope.setContext('Apollo Error', {
operationName,
query,
variables,
});
}
if (err instanceof GraphQLError && err.path) {
scope.addBreadcrumb({
category: 'query-path',
message: err.path.join(' > '),
level: 'debug',
});
}
if (user) {
scope.setUser({
id: user.userId?.toString(),
uid: user.uid,
email: user.email,
});
}
Sentry.captureException(err);
});
}; |
@mikan3rd Did you try running your Apollo server without manually continuing the trace, or is there a specific reason for the code inside your |
I removed the code and the code about continueTrace, but the frontend and backend trace IDs remained different.
Log
|
Could you paste the logs from application startup? The ones that show e.g. "Integration added...." plus everything until the app has settled/fully started up? |
The following is the logs from application startup. Logs
|
@mikan3rd looking at your |
Thanks for the reply.
|
Hello @mikan3rd, We are currently on company-wide hackweek and thus on limited support. We'll take a look at this next week. |
@mikan3rd I believe this error can just be ignored. It may be something that your application swallowed up until now but since the SDK hooks in at quite a low level it surfaces it through a debug log. We don't have reason to believe the SDK causes a socket hangup. |
My problem seems to be solved, thank you very much! |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.20.0
Framework Version
No response
Link to Sentry event
https://bizforward.sentry.io/issues/5659614696/events/e33fe93c614b41779919285369087372/
Reproduction Example/SDK Setup
No response
Steps to Reproduce
In Sentry v7, continueTrace is used as follows, and checking the Sentry Issue confirms that the traceId used in the frontend is successfully passed on to the backend.
In Sentry v8, the transactionContext argument of the continueTrace callback has been removed, so I changed the code as follows.
However, when I did so, the traceId displayed in Sentry's Issue was different for frontend and backend.
I would like to know the cause and countermeasures.
Do I have to use startSpan, and if I use ApolloServer, how do I use startSpan?
Expected Result
The trace ID in the Issue must match the sentryTrace in the request header.
Actual Result
The trace ID listed in the Issue does not match the sentryTrace in the request header.
The text was updated successfully, but these errors were encountered: