ContextService.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. const BaseService = require("../../services/BaseService");
  20. const { Context } = require("../../util/context");
  21. /**
  22. * ContextService provides a way for other services to register a hook to be
  23. * called when a context/subcontext is created.
  24. *
  25. * Contexts are used to provide contextual information in the execution
  26. * context (dynamic scope). They can also be used to identify a "span";
  27. * a span is a labelled frame of execution that can be used to track
  28. * performance, errors, and other metrics.
  29. */
  30. class ContextService extends BaseService {
  31. register_context_hook (event, hook) {
  32. Context.context_hooks_[event].push(hook);
  33. }
  34. }
  35. module.exports = {
  36. ContextService,
  37. };