types.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Type } from '@vendure/common/lib/shared-types';
  2. import { OtelLoggerOptions } from './config/otel-logger';
  3. import { MethodHooksForType } from './service/method-hooks.service';
  4. export interface MethodHookConfig<T> {
  5. target: Type<T>;
  6. hooks: MethodHooksForType<T>;
  7. }
  8. /**
  9. * @description
  10. * Configuration options for the TelemetryPlugin.
  11. *
  12. * @since 3.3.0
  13. * @docsCategory core plugins/TelemetryPlugin
  14. */
  15. export interface TelemetryPluginOptions {
  16. /**
  17. * @description
  18. * The options for the OtelLogger.
  19. *
  20. * For example, to also include logging to the console, you can use the following:
  21. * ```ts
  22. * import { LogLevel } from '\@vendure/core';
  23. * import { TelemetryPlugin } from '\@vendure/telemetry-plugin';
  24. *
  25. * TelemetryPlugin.init({
  26. * loggerOptions: {
  27. * console: LogLevel.Verbose,
  28. * },
  29. * });
  30. * ```
  31. */
  32. loggerOptions?: OtelLoggerOptions;
  33. /**
  34. * @description
  35. * **Status: Developer Preview**
  36. *
  37. * This API may change in a future release.
  38. *
  39. * Method hooks allow you to add extra telemetry actions to specific methods.
  40. * To define hooks on a method, use the {@link registerMethodHooks} function.
  41. *
  42. * @example
  43. * ```ts
  44. * import { TelemetryPlugin, registerMethodHooks } from '\@vendure/telemetry-plugin';
  45. *
  46. * TelemetryPlugin.init({
  47. * methodHooks: [
  48. * registerMethodHooks(ProductService, {
  49. *
  50. * // Define some hooks for the `findOne` method
  51. * findOne: {
  52. * // This will be called before the method is executed
  53. * pre: ({ args: [ctx, productId], span }) => {
  54. * span.setAttribute('productId', productId);
  55. * },
  56. * // This will be called after the method is executed
  57. * post: ({ result, span }) => {
  58. * span.setAttribute('found', !!result);
  59. * },
  60. * },
  61. * }),
  62. * ],
  63. * });
  64. * ```
  65. *
  66. * @experimental
  67. */
  68. methodHooks?: Array<MethodHookConfig<any>>;
  69. }