graphql.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { _optionalChain } from '@sentry/utils';
  2. import { loadModule, logger, fill, isThenable } from '@sentry/utils';
  3. import { DEBUG_BUILD } from '../../common/debug-build.js';
  4. import { shouldDisableAutoInstrumentation } from './utils/node-utils.js';
  5. /** Tracing integration for graphql package */
  6. class GraphQL {
  7. /**
  8. * @inheritDoc
  9. */
  10. static __initStatic() {this.id = 'GraphQL';}
  11. /**
  12. * @inheritDoc
  13. */
  14. constructor() {
  15. this.name = GraphQL.id;
  16. }
  17. /** @inheritdoc */
  18. loadDependency() {
  19. return (this._module = this._module || loadModule('graphql/execution/execute.js'));
  20. }
  21. /**
  22. * @inheritDoc
  23. */
  24. setupOnce(_, getCurrentHub) {
  25. if (shouldDisableAutoInstrumentation(getCurrentHub)) {
  26. DEBUG_BUILD && logger.log('GraphQL Integration is skipped because of instrumenter configuration.');
  27. return;
  28. }
  29. const pkg = this.loadDependency();
  30. if (!pkg) {
  31. DEBUG_BUILD && logger.error('GraphQL Integration was unable to require graphql/execution package.');
  32. return;
  33. }
  34. fill(pkg, 'execute', function (orig) {
  35. return function ( ...args) {
  36. // eslint-disable-next-line deprecation/deprecation
  37. const scope = getCurrentHub().getScope();
  38. // eslint-disable-next-line deprecation/deprecation
  39. const parentSpan = scope.getSpan();
  40. // eslint-disable-next-line deprecation/deprecation
  41. const span = _optionalChain([parentSpan, 'optionalAccess', _2 => _2.startChild, 'call', _3 => _3({
  42. description: 'execute',
  43. op: 'graphql.execute',
  44. origin: 'auto.graphql.graphql',
  45. })]);
  46. // eslint-disable-next-line deprecation/deprecation
  47. _optionalChain([scope, 'optionalAccess', _4 => _4.setSpan, 'call', _5 => _5(span)]);
  48. const rv = orig.call(this, ...args);
  49. if (isThenable(rv)) {
  50. return rv.then((res) => {
  51. _optionalChain([span, 'optionalAccess', _6 => _6.end, 'call', _7 => _7()]);
  52. // eslint-disable-next-line deprecation/deprecation
  53. _optionalChain([scope, 'optionalAccess', _8 => _8.setSpan, 'call', _9 => _9(parentSpan)]);
  54. return res;
  55. });
  56. }
  57. _optionalChain([span, 'optionalAccess', _10 => _10.end, 'call', _11 => _11()]);
  58. // eslint-disable-next-line deprecation/deprecation
  59. _optionalChain([scope, 'optionalAccess', _12 => _12.setSpan, 'call', _13 => _13(parentSpan)]);
  60. return rv;
  61. };
  62. });
  63. }
  64. }GraphQL.__initStatic();
  65. export { GraphQL };
  66. //# sourceMappingURL=graphql.js.map