graphql.js 2.6 KB

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