Skip to content

SamplingContext.request.query_string became object, but still has type 'string' #3714

@derom

Description

@derom

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

6.7.1

Description

It started after update from 6.6.0 to 6.7.1. I get error TypeError: samplingCtx.request.query_string.includes is not a function when trying to use SamplingContext.request.query_string as string. This is the code to reproduce the issue:

import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import express from 'express';

const app = express();
Sentry.init({
      integrations: [
          new Sentry.Integrations.Http({ tracing: true }),
          new Tracing.Integrations.Express({
              app,
          }),
      ],
      tracesSampler: (samplingCtx) => {
          console.log(samplingCtx.request?.query_string); // prints object { some_param: '1' }
          // typehint says it's still string
          if (samplingCtx.request?.query_string?.includes("some_param=1")) {
              return 1.0;
          }
          return 0;
      },
  });
app.use(Sentry.Handlers.requestHandler() as express.RequestHandler);
app.use(Sentry.Handlers.tracingHandler());
app.get('/healthz', (_: express.Request, res: express.Response) => {
    return res.json({ok: 1});
});

I guess it's related to this commit f546d0f
and this is the type of query_string from SamplingContext

query_string?: string;

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions