11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html lang="en">
31cb0ef41Sopenharmony_ci<head>
41cb0ef41Sopenharmony_ci  <meta charset="utf-8">
51cb0ef41Sopenharmony_ci  <meta name="viewport" content="width=device-width">
61cb0ef41Sopenharmony_ci  <meta name="nodejs.org:node-version" content="v18.20.1">
71cb0ef41Sopenharmony_ci  <title>Diagnostics Channel | Node.js v18.20.1 Documentation</title>
81cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
91cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/style.css">
101cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/hljs.css">
111cb0ef41Sopenharmony_ci  <link rel="canonical" href="https://nodejs.org/api/diagnostics_channel.html">
121cb0ef41Sopenharmony_ci  <script async defer src="assets/api.js" type="text/javascript"></script>
131cb0ef41Sopenharmony_ci  <style>@media(max-width:734px){.with-64-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}</style>
141cb0ef41Sopenharmony_ci</head>
151cb0ef41Sopenharmony_ci<body class="alt apidoc" id="api-section-diagnostics_channel">
161cb0ef41Sopenharmony_ci  <div id="content" class="clearfix">
171cb0ef41Sopenharmony_ci    <div id="column2" class="interior">
181cb0ef41Sopenharmony_ci      <div id="intro" class="interior">
191cb0ef41Sopenharmony_ci        <a href="/" title="Go back to the home page">
201cb0ef41Sopenharmony_ci          Node.js
211cb0ef41Sopenharmony_ci        </a>
221cb0ef41Sopenharmony_ci      </div>
231cb0ef41Sopenharmony_ci      <ul>
241cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
251cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
261cb0ef41Sopenharmony_ci</ul>
271cb0ef41Sopenharmony_ci<hr class="line">
281cb0ef41Sopenharmony_ci<ul>
291cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
301cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
311cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
321cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
331cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
341cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
351cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
361cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
371cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
381cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
391cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
401cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
411cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
421cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
431cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
441cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel active">Diagnostics Channel</a></li>
451cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
461cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
471cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
481cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
491cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
501cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
511cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
521cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
531cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
541cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
551cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
561cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
571cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
581cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
591cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
601cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
611cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
621cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
631cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
641cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
651cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
661cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
671cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
681cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
691cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
701cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
711cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
721cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
731cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
741cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
751cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
761cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
771cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
781cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
791cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
801cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
811cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
821cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
831cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
841cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
851cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
861cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
871cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
881cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
891cb0ef41Sopenharmony_ci</ul>
901cb0ef41Sopenharmony_ci<hr class="line">
911cb0ef41Sopenharmony_ci<ul>
921cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
931cb0ef41Sopenharmony_ci</ul>
941cb0ef41Sopenharmony_ci    </div>
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci    <div id="column1" data-id="diagnostics_channel" class="interior">
971cb0ef41Sopenharmony_ci      <header class="header">
981cb0ef41Sopenharmony_ci        <div class="header-container">
991cb0ef41Sopenharmony_ci          <h1>Node.js v18.20.1 documentation</h1>
1001cb0ef41Sopenharmony_ci          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
1011cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
1021cb0ef41Sopenharmony_ci              <path fill="none" d="M0 0h24v24H0z" />
1031cb0ef41Sopenharmony_ci              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
1041cb0ef41Sopenharmony_ci              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
1051cb0ef41Sopenharmony_ci            </svg>
1061cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
1071cb0ef41Sopenharmony_ci              <path d="M0 0h24v24H0z" fill="none" />
1081cb0ef41Sopenharmony_ci              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
1091cb0ef41Sopenharmony_ci            </svg>
1101cb0ef41Sopenharmony_ci          </button>
1111cb0ef41Sopenharmony_ci        </div>
1121cb0ef41Sopenharmony_ci        <div id="gtoc">
1131cb0ef41Sopenharmony_ci          <ul>
1141cb0ef41Sopenharmony_ci            <li class="pinned-header">Node.js v18.20.1</li>
1151cb0ef41Sopenharmony_ci            
1161cb0ef41Sopenharmony_ci    <li class="picker-header">
1171cb0ef41Sopenharmony_ci      <a href="#">
1181cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1191cb0ef41Sopenharmony_ci        Table of contents
1201cb0ef41Sopenharmony_ci      </a>
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci      <div class="picker"><div class="toc"><ul>
1231cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#diagnostics-channel">Diagnostics Channel</a></span>
1241cb0ef41Sopenharmony_ci<ul>
1251cb0ef41Sopenharmony_ci<li><a href="#public-api">Public API</a>
1261cb0ef41Sopenharmony_ci<ul>
1271cb0ef41Sopenharmony_ci<li><a href="#overview">Overview</a>
1281cb0ef41Sopenharmony_ci<ul>
1291cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelhassubscribersname"><code>diagnostics_channel.hasSubscribers(name)</code></a></li>
1301cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelchannelname"><code>diagnostics_channel.channel(name)</code></a></li>
1311cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelsubscribename-onmessage"><code>diagnostics_channel.subscribe(name, onMessage)</code></a></li>
1321cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelunsubscribename-onmessage"><code>diagnostics_channel.unsubscribe(name, onMessage)</code></a></li>
1331cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#diagnostics_channeltracingchannelnameorchannels"><code>diagnostics_channel.tracingChannel(nameOrChannels)</code></a></span></li>
1341cb0ef41Sopenharmony_ci</ul>
1351cb0ef41Sopenharmony_ci</li>
1361cb0ef41Sopenharmony_ci<li><a href="#class-channel">Class: <code>Channel</code></a>
1371cb0ef41Sopenharmony_ci<ul>
1381cb0ef41Sopenharmony_ci<li><a href="#channelhassubscribers"><code>channel.hasSubscribers</code></a></li>
1391cb0ef41Sopenharmony_ci<li><a href="#channelpublishmessage"><code>channel.publish(message)</code></a></li>
1401cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#channelsubscribeonmessage"><code>channel.subscribe(onMessage)</code></a></span></li>
1411cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#channelunsubscribeonmessage"><code>channel.unsubscribe(onMessage)</code></a></span></li>
1421cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#channelbindstorestore-transform"><code>channel.bindStore(store[, transform])</code></a></span></li>
1431cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#channelunbindstorestore"><code>channel.unbindStore(store)</code></a></span></li>
1441cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, fn[, thisArg[, ...args]])</code></a></span></li>
1451cb0ef41Sopenharmony_ci</ul>
1461cb0ef41Sopenharmony_ci</li>
1471cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#class-tracingchannel">Class: <code>TracingChannel</code></a></span>
1481cb0ef41Sopenharmony_ci<ul>
1491cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchannelsubscribesubscribers"><code>tracingChannel.subscribe(subscribers)</code></a></span></li>
1501cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchannelunsubscribesubscribers"><code>tracingChannel.unsubscribe(subscribers)</code></a></span></li>
1511cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchanneltracesyncfn-context-thisarg-args"><code>tracingChannel.traceSync(fn[, context[, thisArg[, ...args]]])</code></a></span></li>
1521cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchanneltracepromisefn-context-thisarg-args"><code>tracingChannel.tracePromise(fn[, context[, thisArg[, ...args]]])</code></a></span></li>
1531cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchanneltracecallbackfn-position-context-thisarg-args"><code>tracingChannel.traceCallback(fn[, position[, context[, thisArg[, ...args]]]])</code></a></span></li>
1541cb0ef41Sopenharmony_ci</ul>
1551cb0ef41Sopenharmony_ci</li>
1561cb0ef41Sopenharmony_ci<li><a href="#tracingchannel-channels">TracingChannel Channels</a>
1571cb0ef41Sopenharmony_ci<ul>
1581cb0ef41Sopenharmony_ci<li><a href="#startevent"><code>start(event)</code></a></li>
1591cb0ef41Sopenharmony_ci<li><a href="#endevent"><code>end(event)</code></a></li>
1601cb0ef41Sopenharmony_ci<li><a href="#asyncstartevent"><code>asyncStart(event)</code></a></li>
1611cb0ef41Sopenharmony_ci<li><a href="#asyncendevent"><code>asyncEnd(event)</code></a></li>
1621cb0ef41Sopenharmony_ci<li><a href="#errorevent"><code>error(event)</code></a></li>
1631cb0ef41Sopenharmony_ci</ul>
1641cb0ef41Sopenharmony_ci</li>
1651cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#built-in-channels">Built-in Channels</a></span>
1661cb0ef41Sopenharmony_ci<ul>
1671cb0ef41Sopenharmony_ci<li><a href="#http">HTTP</a></li>
1681cb0ef41Sopenharmony_ci</ul>
1691cb0ef41Sopenharmony_ci</li>
1701cb0ef41Sopenharmony_ci</ul>
1711cb0ef41Sopenharmony_ci</li>
1721cb0ef41Sopenharmony_ci</ul>
1731cb0ef41Sopenharmony_ci</li>
1741cb0ef41Sopenharmony_ci</ul></div></div>
1751cb0ef41Sopenharmony_ci    </li>
1761cb0ef41Sopenharmony_ci  
1771cb0ef41Sopenharmony_ci            
1781cb0ef41Sopenharmony_ci    <li class="picker-header">
1791cb0ef41Sopenharmony_ci      <a href="#">
1801cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1811cb0ef41Sopenharmony_ci        Index
1821cb0ef41Sopenharmony_ci      </a>
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci      <div class="picker"><ul>
1851cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
1861cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci      <li>
1891cb0ef41Sopenharmony_ci        <a href="index.html">Index</a>
1901cb0ef41Sopenharmony_ci      </li>
1911cb0ef41Sopenharmony_ci    </ul>
1921cb0ef41Sopenharmony_ci  
1931cb0ef41Sopenharmony_ci<hr class="line">
1941cb0ef41Sopenharmony_ci<ul>
1951cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
1961cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
1971cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
1981cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
1991cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
2001cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
2011cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
2021cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
2031cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
2041cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
2051cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
2061cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
2071cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
2081cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
2091cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
2101cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel active">Diagnostics Channel</a></li>
2111cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
2121cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
2131cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
2141cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
2151cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
2161cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
2171cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
2181cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
2191cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
2201cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
2211cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
2221cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
2231cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
2241cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
2251cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
2261cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
2271cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
2281cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
2291cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
2301cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
2311cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
2321cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
2331cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
2341cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
2351cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
2361cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
2371cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
2381cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
2391cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
2401cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
2411cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
2421cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
2431cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
2441cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
2451cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
2461cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
2471cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
2481cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
2491cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
2501cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
2511cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
2521cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
2531cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
2541cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
2551cb0ef41Sopenharmony_ci</ul>
2561cb0ef41Sopenharmony_ci<hr class="line">
2571cb0ef41Sopenharmony_ci<ul>
2581cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
2591cb0ef41Sopenharmony_ci</ul></div>
2601cb0ef41Sopenharmony_ci    </li>
2611cb0ef41Sopenharmony_ci  
2621cb0ef41Sopenharmony_ci            
2631cb0ef41Sopenharmony_ci    <li class="picker-header">
2641cb0ef41Sopenharmony_ci      <a href="#">
2651cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2661cb0ef41Sopenharmony_ci        Other versions
2671cb0ef41Sopenharmony_ci      </a>
2681cb0ef41Sopenharmony_ci      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/diagnostics_channel.html">21.x</a></li>
2691cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v20.x/api/diagnostics_channel.html">20.x <b>LTS</b></a></li>
2701cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v19.x/api/diagnostics_channel.html">19.x</a></li>
2711cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v18.x/api/diagnostics_channel.html">18.x <b>LTS</b></a></li>
2721cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v17.x/api/diagnostics_channel.html">17.x</a></li>
2731cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v16.x/api/diagnostics_channel.html">16.x</a></li>
2741cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v15.x/api/diagnostics_channel.html">15.x</a></li></ol></div>
2751cb0ef41Sopenharmony_ci    </li>
2761cb0ef41Sopenharmony_ci  
2771cb0ef41Sopenharmony_ci            <li class="picker-header">
2781cb0ef41Sopenharmony_ci              <a href="#">
2791cb0ef41Sopenharmony_ci                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2801cb0ef41Sopenharmony_ci                Options
2811cb0ef41Sopenharmony_ci              </a>
2821cb0ef41Sopenharmony_ci        
2831cb0ef41Sopenharmony_ci              <div class="picker">
2841cb0ef41Sopenharmony_ci                <ul>
2851cb0ef41Sopenharmony_ci                  <li>
2861cb0ef41Sopenharmony_ci                    <a href="all.html">View on single page</a>
2871cb0ef41Sopenharmony_ci                  </li>
2881cb0ef41Sopenharmony_ci                  <li>
2891cb0ef41Sopenharmony_ci                    <a href="diagnostics_channel.json">View as JSON</a>
2901cb0ef41Sopenharmony_ci                  </li>
2911cb0ef41Sopenharmony_ci                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/diagnostics_channel.md">Edit on GitHub</a></li>    
2921cb0ef41Sopenharmony_ci                </ul>
2931cb0ef41Sopenharmony_ci              </div>
2941cb0ef41Sopenharmony_ci            </li>
2951cb0ef41Sopenharmony_ci          </ul>
2961cb0ef41Sopenharmony_ci        </div>
2971cb0ef41Sopenharmony_ci        <hr>
2981cb0ef41Sopenharmony_ci      </header>
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci      <details id="toc" open><summary>Table of contents</summary><ul>
3011cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#diagnostics-channel">Diagnostics Channel</a></span>
3021cb0ef41Sopenharmony_ci<ul>
3031cb0ef41Sopenharmony_ci<li><a href="#public-api">Public API</a>
3041cb0ef41Sopenharmony_ci<ul>
3051cb0ef41Sopenharmony_ci<li><a href="#overview">Overview</a>
3061cb0ef41Sopenharmony_ci<ul>
3071cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelhassubscribersname"><code>diagnostics_channel.hasSubscribers(name)</code></a></li>
3081cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelchannelname"><code>diagnostics_channel.channel(name)</code></a></li>
3091cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelsubscribename-onmessage"><code>diagnostics_channel.subscribe(name, onMessage)</code></a></li>
3101cb0ef41Sopenharmony_ci<li><a href="#diagnostics_channelunsubscribename-onmessage"><code>diagnostics_channel.unsubscribe(name, onMessage)</code></a></li>
3111cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#diagnostics_channeltracingchannelnameorchannels"><code>diagnostics_channel.tracingChannel(nameOrChannels)</code></a></span></li>
3121cb0ef41Sopenharmony_ci</ul>
3131cb0ef41Sopenharmony_ci</li>
3141cb0ef41Sopenharmony_ci<li><a href="#class-channel">Class: <code>Channel</code></a>
3151cb0ef41Sopenharmony_ci<ul>
3161cb0ef41Sopenharmony_ci<li><a href="#channelhassubscribers"><code>channel.hasSubscribers</code></a></li>
3171cb0ef41Sopenharmony_ci<li><a href="#channelpublishmessage"><code>channel.publish(message)</code></a></li>
3181cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#channelsubscribeonmessage"><code>channel.subscribe(onMessage)</code></a></span></li>
3191cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#channelunsubscribeonmessage"><code>channel.unsubscribe(onMessage)</code></a></span></li>
3201cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#channelbindstorestore-transform"><code>channel.bindStore(store[, transform])</code></a></span></li>
3211cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#channelunbindstorestore"><code>channel.unbindStore(store)</code></a></span></li>
3221cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, fn[, thisArg[, ...args]])</code></a></span></li>
3231cb0ef41Sopenharmony_ci</ul>
3241cb0ef41Sopenharmony_ci</li>
3251cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#class-tracingchannel">Class: <code>TracingChannel</code></a></span>
3261cb0ef41Sopenharmony_ci<ul>
3271cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchannelsubscribesubscribers"><code>tracingChannel.subscribe(subscribers)</code></a></span></li>
3281cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchannelunsubscribesubscribers"><code>tracingChannel.unsubscribe(subscribers)</code></a></span></li>
3291cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchanneltracesyncfn-context-thisarg-args"><code>tracingChannel.traceSync(fn[, context[, thisArg[, ...args]]])</code></a></span></li>
3301cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchanneltracepromisefn-context-thisarg-args"><code>tracingChannel.tracePromise(fn[, context[, thisArg[, ...args]]])</code></a></span></li>
3311cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#tracingchanneltracecallbackfn-position-context-thisarg-args"><code>tracingChannel.traceCallback(fn[, position[, context[, thisArg[, ...args]]]])</code></a></span></li>
3321cb0ef41Sopenharmony_ci</ul>
3331cb0ef41Sopenharmony_ci</li>
3341cb0ef41Sopenharmony_ci<li><a href="#tracingchannel-channels">TracingChannel Channels</a>
3351cb0ef41Sopenharmony_ci<ul>
3361cb0ef41Sopenharmony_ci<li><a href="#startevent"><code>start(event)</code></a></li>
3371cb0ef41Sopenharmony_ci<li><a href="#endevent"><code>end(event)</code></a></li>
3381cb0ef41Sopenharmony_ci<li><a href="#asyncstartevent"><code>asyncStart(event)</code></a></li>
3391cb0ef41Sopenharmony_ci<li><a href="#asyncendevent"><code>asyncEnd(event)</code></a></li>
3401cb0ef41Sopenharmony_ci<li><a href="#errorevent"><code>error(event)</code></a></li>
3411cb0ef41Sopenharmony_ci</ul>
3421cb0ef41Sopenharmony_ci</li>
3431cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#built-in-channels">Built-in Channels</a></span>
3441cb0ef41Sopenharmony_ci<ul>
3451cb0ef41Sopenharmony_ci<li><a href="#http">HTTP</a></li>
3461cb0ef41Sopenharmony_ci</ul>
3471cb0ef41Sopenharmony_ci</li>
3481cb0ef41Sopenharmony_ci</ul>
3491cb0ef41Sopenharmony_ci</li>
3501cb0ef41Sopenharmony_ci</ul>
3511cb0ef41Sopenharmony_ci</li>
3521cb0ef41Sopenharmony_ci</ul></details>
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci      <div id="apicontent">
3551cb0ef41Sopenharmony_ci        <h2>Diagnostics Channel<span><a class="mark" href="#diagnostics-channel" id="diagnostics-channel">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_diagnostics_channel"></a></h2>
3561cb0ef41Sopenharmony_ci<div class="api_metadata">
3571cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
3581cb0ef41Sopenharmony_ci<table>
3591cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
3601cb0ef41Sopenharmony_ci<tr><td>v18.13.0</td>
3611cb0ef41Sopenharmony_ci<td><p>diagnostics_channel is now Stable.</p></td></tr>
3621cb0ef41Sopenharmony_ci<tr><td>v15.1.0, v14.17.0</td>
3631cb0ef41Sopenharmony_ci<td><p><span>Added in: v15.1.0, v14.17.0</span></p></td></tr>
3641cb0ef41Sopenharmony_ci</tbody></table>
3651cb0ef41Sopenharmony_ci</details>
3661cb0ef41Sopenharmony_ci</div>
3671cb0ef41Sopenharmony_ci
3681cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</div><p></p>
3691cb0ef41Sopenharmony_ci<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/diagnostics_channel.js">lib/diagnostics_channel.js</a></p>
3701cb0ef41Sopenharmony_ci<p>The <code>node:diagnostics_channel</code> module provides an API to create named channels
3711cb0ef41Sopenharmony_cito report arbitrary message data for diagnostics purposes.</p>
3721cb0ef41Sopenharmony_ci<p>It can be accessed using:</p>
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);</code><button class="copy-button">copy</button></pre>
3751cb0ef41Sopenharmony_ci<p>It is intended that a module writer wanting to report diagnostics messages
3761cb0ef41Sopenharmony_ciwill create one or many top-level channels to report messages through.
3771cb0ef41Sopenharmony_ciChannels may also be acquired at runtime but it is not encouraged
3781cb0ef41Sopenharmony_cidue to the additional overhead of doing so. Channels may be exported for
3791cb0ef41Sopenharmony_ciconvenience, but as long as the name is known it can be acquired anywhere.</p>
3801cb0ef41Sopenharmony_ci<p>If you intend for your module to produce diagnostics data for others to
3811cb0ef41Sopenharmony_ciconsume it is recommended that you include documentation of what named
3821cb0ef41Sopenharmony_cichannels are used along with the shape of the message data. Channel names
3831cb0ef41Sopenharmony_cishould generally include the module name to avoid collisions with data from
3841cb0ef41Sopenharmony_ciother modules.</p>
3851cb0ef41Sopenharmony_ci<section><h3>Public API<span><a class="mark" href="#public-api" id="public-api">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_public_api"></a></h3>
3861cb0ef41Sopenharmony_ci<h4>Overview<span><a class="mark" href="#overview" id="overview">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_overview"></a></h4>
3871cb0ef41Sopenharmony_ci<p>Following is a simple overview of the public API.</p>
3881cb0ef41Sopenharmony_ci
3891cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_ci<span class="hljs-comment">// Get a reusable channel object</span>
3921cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
3931cb0ef41Sopenharmony_ci
3941cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">onMessage</span>(<span class="hljs-params">message, name</span>) {
3951cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
3961cb0ef41Sopenharmony_ci}
3971cb0ef41Sopenharmony_ci
3981cb0ef41Sopenharmony_ci<span class="hljs-comment">// Subscribe to the channel</span>
3991cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ci<span class="hljs-comment">// Check if the channel has an active subscriber</span>
4021cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (channel.<span class="hljs-property">hasSubscribers</span>) {
4031cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Publish data to the channel</span>
4041cb0ef41Sopenharmony_ci  channel.<span class="hljs-title function_">publish</span>({
4051cb0ef41Sopenharmony_ci    <span class="hljs-attr">some</span>: <span class="hljs-string">'data'</span>,
4061cb0ef41Sopenharmony_ci  });
4071cb0ef41Sopenharmony_ci}
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ci<span class="hljs-comment">// Unsubscribe from the channel</span>
4101cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">unsubscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_ci<span class="hljs-comment">// Get a reusable channel object</span>
4131cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
4141cb0ef41Sopenharmony_ci
4151cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">onMessage</span>(<span class="hljs-params">message, name</span>) {
4161cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
4171cb0ef41Sopenharmony_ci}
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ci<span class="hljs-comment">// Subscribe to the channel</span>
4201cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);
4211cb0ef41Sopenharmony_ci
4221cb0ef41Sopenharmony_ci<span class="hljs-comment">// Check if the channel has an active subscriber</span>
4231cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (channel.<span class="hljs-property">hasSubscribers</span>) {
4241cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Publish data to the channel</span>
4251cb0ef41Sopenharmony_ci  channel.<span class="hljs-title function_">publish</span>({
4261cb0ef41Sopenharmony_ci    <span class="hljs-attr">some</span>: <span class="hljs-string">'data'</span>,
4271cb0ef41Sopenharmony_ci  });
4281cb0ef41Sopenharmony_ci}
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ci<span class="hljs-comment">// Unsubscribe from the channel</span>
4311cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">unsubscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);</code><button class="copy-button">copy</button></pre>
4321cb0ef41Sopenharmony_ci<h5><code>diagnostics_channel.hasSubscribers(name)</code><span><a class="mark" href="#diagnostics_channelhassubscribersname" id="diagnostics_channelhassubscribersname">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_diagnostics_channel_hassubscribers_name"></a></h5>
4331cb0ef41Sopenharmony_ci<div class="api_metadata">
4341cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span>
4351cb0ef41Sopenharmony_ci</div>
4361cb0ef41Sopenharmony_ci<ul>
4371cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> The channel name</li>
4381cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If there are active subscribers</li>
4391cb0ef41Sopenharmony_ci</ul>
4401cb0ef41Sopenharmony_ci<p>Check if there are active subscribers to the named channel. This is helpful if
4411cb0ef41Sopenharmony_cithe message you want to send might be expensive to prepare.</p>
4421cb0ef41Sopenharmony_ci<p>This API is optional but helpful when trying to publish messages from very
4431cb0ef41Sopenharmony_ciperformance-sensitive code.</p>
4441cb0ef41Sopenharmony_ci
4451cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
4461cb0ef41Sopenharmony_ci
4471cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (diagnostics_channel.<span class="hljs-title function_">hasSubscribers</span>(<span class="hljs-string">'my-channel'</span>)) {
4481cb0ef41Sopenharmony_ci  <span class="hljs-comment">// There are subscribers, prepare and publish message</span>
4491cb0ef41Sopenharmony_ci}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
4501cb0ef41Sopenharmony_ci
4511cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (diagnostics_channel.<span class="hljs-title function_">hasSubscribers</span>(<span class="hljs-string">'my-channel'</span>)) {
4521cb0ef41Sopenharmony_ci  <span class="hljs-comment">// There are subscribers, prepare and publish message</span>
4531cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
4541cb0ef41Sopenharmony_ci<h5><code>diagnostics_channel.channel(name)</code><span><a class="mark" href="#diagnostics_channelchannelname" id="diagnostics_channelchannelname">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_diagnostics_channel_channel_name"></a></h5>
4551cb0ef41Sopenharmony_ci<div class="api_metadata">
4561cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span>
4571cb0ef41Sopenharmony_ci</div>
4581cb0ef41Sopenharmony_ci<ul>
4591cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> The channel name</li>
4601cb0ef41Sopenharmony_ci<li>Returns: <a href="diagnostics_channel.html#class-channel" class="type">&#x3C;Channel></a> The named channel object</li>
4611cb0ef41Sopenharmony_ci</ul>
4621cb0ef41Sopenharmony_ci<p>This is the primary entry-point for anyone wanting to publish to a named
4631cb0ef41Sopenharmony_cichannel. It produces a channel object which is optimized to reduce overhead at
4641cb0ef41Sopenharmony_cipublish time as much as possible.</p>
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
4671cb0ef41Sopenharmony_ci
4681cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);</code><button class="copy-button">copy</button></pre>
4711cb0ef41Sopenharmony_ci<h5><code>diagnostics_channel.subscribe(name, onMessage)</code><span><a class="mark" href="#diagnostics_channelsubscribename-onmessage" id="diagnostics_channelsubscribename-onmessage">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_diagnostics_channel_subscribe_name_onmessage"></a></h5>
4721cb0ef41Sopenharmony_ci<div class="api_metadata">
4731cb0ef41Sopenharmony_ci<span>Added in: v18.7.0</span>
4741cb0ef41Sopenharmony_ci</div>
4751cb0ef41Sopenharmony_ci<ul>
4761cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> The channel name</li>
4771cb0ef41Sopenharmony_ci<li><code>onMessage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The handler to receive channel messages
4781cb0ef41Sopenharmony_ci<ul>
4791cb0ef41Sopenharmony_ci<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The message data</li>
4801cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> The name of the channel</li>
4811cb0ef41Sopenharmony_ci</ul>
4821cb0ef41Sopenharmony_ci</li>
4831cb0ef41Sopenharmony_ci</ul>
4841cb0ef41Sopenharmony_ci<p>Register a message handler to subscribe to this channel. This message handler
4851cb0ef41Sopenharmony_ciwill be run synchronously whenever a message is published to the channel. Any
4861cb0ef41Sopenharmony_cierrors thrown in the message handler will trigger an <a href="process.html#event-uncaughtexception"><code>'uncaughtException'</code></a>.</p>
4871cb0ef41Sopenharmony_ci
4881cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
4891cb0ef41Sopenharmony_ci
4901cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">'my-channel'</span>, <span class="hljs-function">(<span class="hljs-params">message, name</span>) =></span> {
4911cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
4921cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
4931cb0ef41Sopenharmony_ci
4941cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">'my-channel'</span>, <span class="hljs-function">(<span class="hljs-params">message, name</span>) =></span> {
4951cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
4961cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
4971cb0ef41Sopenharmony_ci<h5><code>diagnostics_channel.unsubscribe(name, onMessage)</code><span><a class="mark" href="#diagnostics_channelunsubscribename-onmessage" id="diagnostics_channelunsubscribename-onmessage">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_diagnostics_channel_unsubscribe_name_onmessage"></a></h5>
4981cb0ef41Sopenharmony_ci<div class="api_metadata">
4991cb0ef41Sopenharmony_ci<span>Added in: v18.7.0</span>
5001cb0ef41Sopenharmony_ci</div>
5011cb0ef41Sopenharmony_ci<ul>
5021cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> The channel name</li>
5031cb0ef41Sopenharmony_ci<li><code>onMessage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The previous subscribed handler to remove</li>
5041cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if the handler was found, <code>false</code> otherwise.</li>
5051cb0ef41Sopenharmony_ci</ul>
5061cb0ef41Sopenharmony_ci<p>Remove a message handler previously registered to this channel with
5071cb0ef41Sopenharmony_ci<a href="#diagnostics_channelsubscribename-onmessage"><code>diagnostics_channel.subscribe(name, onMessage)</code></a>.</p>
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
5101cb0ef41Sopenharmony_ci
5111cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">onMessage</span>(<span class="hljs-params">message, name</span>) {
5121cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
5131cb0ef41Sopenharmony_ci}
5141cb0ef41Sopenharmony_ci
5151cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);
5161cb0ef41Sopenharmony_ci
5171cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">unsubscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
5181cb0ef41Sopenharmony_ci
5191cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">onMessage</span>(<span class="hljs-params">message, name</span>) {
5201cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
5211cb0ef41Sopenharmony_ci}
5221cb0ef41Sopenharmony_ci
5231cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);
5241cb0ef41Sopenharmony_ci
5251cb0ef41Sopenharmony_cidiagnostics_channel.<span class="hljs-title function_">unsubscribe</span>(<span class="hljs-string">'my-channel'</span>, onMessage);</code><button class="copy-button">copy</button></pre>
5261cb0ef41Sopenharmony_ci<h5><code>diagnostics_channel.tracingChannel(nameOrChannels)</code><span><a class="mark" href="#diagnostics_channeltracingchannelnameorchannels" id="diagnostics_channeltracingchannelnameorchannels">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_diagnostics_channel_tracingchannel_nameorchannels"></a></h5>
5271cb0ef41Sopenharmony_ci<div class="api_metadata">
5281cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
5291cb0ef41Sopenharmony_ci</div>
5301cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
5311cb0ef41Sopenharmony_ci<ul>
5321cb0ef41Sopenharmony_ci<li><code>nameOrChannels</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="diagnostics_channel.html#class-tracingchannel" class="type">&#x3C;TracingChannel></a> Channel name or
5331cb0ef41Sopenharmony_ciobject containing all the <a href="#tracingchannel-channels">TracingChannel Channels</a></li>
5341cb0ef41Sopenharmony_ci<li>Returns: <a href="diagnostics_channel.html#class-tracingchannel" class="type">&#x3C;TracingChannel></a> Collection of channels to trace with</li>
5351cb0ef41Sopenharmony_ci</ul>
5361cb0ef41Sopenharmony_ci<p>Creates a <a href="#class-tracingchannel"><code>TracingChannel</code></a> wrapper for the given
5371cb0ef41Sopenharmony_ci<a href="#tracingchannel-channels">TracingChannel Channels</a>. If a name is given, the corresponding tracing
5381cb0ef41Sopenharmony_cichannels will be created in the form of <code>tracing:${name}:${eventType}</code> where
5391cb0ef41Sopenharmony_ci<code>eventType</code> corresponds to the types of <a href="#tracingchannel-channels">TracingChannel Channels</a>.</p>
5401cb0ef41Sopenharmony_ci
5411cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channelsByName = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
5441cb0ef41Sopenharmony_ci
5451cb0ef41Sopenharmony_ci<span class="hljs-comment">// or...</span>
5461cb0ef41Sopenharmony_ci
5471cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channelsByCollection = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>({
5481cb0ef41Sopenharmony_ci  <span class="hljs-attr">start</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:start'</span>),
5491cb0ef41Sopenharmony_ci  <span class="hljs-attr">end</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:end'</span>),
5501cb0ef41Sopenharmony_ci  <span class="hljs-attr">asyncStart</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:asyncStart'</span>),
5511cb0ef41Sopenharmony_ci  <span class="hljs-attr">asyncEnd</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:asyncEnd'</span>),
5521cb0ef41Sopenharmony_ci  <span class="hljs-attr">error</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:error'</span>),
5531cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channelsByName = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
5561cb0ef41Sopenharmony_ci
5571cb0ef41Sopenharmony_ci<span class="hljs-comment">// or...</span>
5581cb0ef41Sopenharmony_ci
5591cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channelsByCollection = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>({
5601cb0ef41Sopenharmony_ci  <span class="hljs-attr">start</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:start'</span>),
5611cb0ef41Sopenharmony_ci  <span class="hljs-attr">end</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:end'</span>),
5621cb0ef41Sopenharmony_ci  <span class="hljs-attr">asyncStart</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:asyncStart'</span>),
5631cb0ef41Sopenharmony_ci  <span class="hljs-attr">asyncEnd</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:asyncEnd'</span>),
5641cb0ef41Sopenharmony_ci  <span class="hljs-attr">error</span>: diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'tracing:my-channel:error'</span>),
5651cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
5661cb0ef41Sopenharmony_ci<h4>Class: <code>Channel</code><span><a class="mark" href="#class-channel" id="class-channel">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_class_channel"></a></h4>
5671cb0ef41Sopenharmony_ci<div class="api_metadata">
5681cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span>
5691cb0ef41Sopenharmony_ci</div>
5701cb0ef41Sopenharmony_ci<p>The class <code>Channel</code> represents an individual named channel within the data
5711cb0ef41Sopenharmony_cipipeline. It is used to track subscribers and to publish messages when there
5721cb0ef41Sopenharmony_ciare subscribers present. It exists as a separate object to avoid channel
5731cb0ef41Sopenharmony_cilookups at publish time, enabling very fast publish speeds and allowing
5741cb0ef41Sopenharmony_cifor heavy use while incurring very minimal cost. Channels are created with
5751cb0ef41Sopenharmony_ci<a href="#diagnostics_channelchannelname"><code>diagnostics_channel.channel(name)</code></a>, constructing a channel directly
5761cb0ef41Sopenharmony_ciwith <code>new Channel(name)</code> is not supported.</p>
5771cb0ef41Sopenharmony_ci<h5><code>channel.hasSubscribers</code><span><a class="mark" href="#channelhassubscribers" id="channelhassubscribers">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_hassubscribers"></a></h5>
5781cb0ef41Sopenharmony_ci<div class="api_metadata">
5791cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span>
5801cb0ef41Sopenharmony_ci</div>
5811cb0ef41Sopenharmony_ci<ul>
5821cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If there are active subscribers</li>
5831cb0ef41Sopenharmony_ci</ul>
5841cb0ef41Sopenharmony_ci<p>Check if there are active subscribers to this channel. This is helpful if
5851cb0ef41Sopenharmony_cithe message you want to send might be expensive to prepare.</p>
5861cb0ef41Sopenharmony_ci<p>This API is optional but helpful when trying to publish messages from very
5871cb0ef41Sopenharmony_ciperformance-sensitive code.</p>
5881cb0ef41Sopenharmony_ci
5891cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
5901cb0ef41Sopenharmony_ci
5911cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
5921cb0ef41Sopenharmony_ci
5931cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (channel.<span class="hljs-property">hasSubscribers</span>) {
5941cb0ef41Sopenharmony_ci  <span class="hljs-comment">// There are subscribers, prepare and publish message</span>
5951cb0ef41Sopenharmony_ci}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
5961cb0ef41Sopenharmony_ci
5971cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
5981cb0ef41Sopenharmony_ci
5991cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (channel.<span class="hljs-property">hasSubscribers</span>) {
6001cb0ef41Sopenharmony_ci  <span class="hljs-comment">// There are subscribers, prepare and publish message</span>
6011cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
6021cb0ef41Sopenharmony_ci<h5><code>channel.publish(message)</code><span><a class="mark" href="#channelpublishmessage" id="channelpublishmessage">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_publish_message"></a></h5>
6031cb0ef41Sopenharmony_ci<div class="api_metadata">
6041cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span>
6051cb0ef41Sopenharmony_ci</div>
6061cb0ef41Sopenharmony_ci<ul>
6071cb0ef41Sopenharmony_ci<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The message to send to the channel subscribers</li>
6081cb0ef41Sopenharmony_ci</ul>
6091cb0ef41Sopenharmony_ci<p>Publish a message to any subscribers to the channel. This will trigger
6101cb0ef41Sopenharmony_cimessage handlers synchronously so they will execute within the same context.</p>
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
6131cb0ef41Sopenharmony_ci
6141cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
6151cb0ef41Sopenharmony_ci
6161cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">publish</span>({
6171cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'message'</span>,
6181cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
6191cb0ef41Sopenharmony_ci
6201cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
6211cb0ef41Sopenharmony_ci
6221cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">publish</span>({
6231cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'message'</span>,
6241cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
6251cb0ef41Sopenharmony_ci<h5><code>channel.subscribe(onMessage)</code><span><a class="mark" href="#channelsubscribeonmessage" id="channelsubscribeonmessage">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_subscribe_onmessage"></a></h5>
6261cb0ef41Sopenharmony_ci<div class="api_metadata">
6271cb0ef41Sopenharmony_ci<span>Added in: v15.1.0, v14.17.0</span><span>Deprecated since: v18.7.0</span>
6281cb0ef41Sopenharmony_ci</div>
6291cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="#diagnostics_channelsubscribename-onmessage"><code>diagnostics_channel.subscribe(name, onMessage)</code></a></div><p></p>
6301cb0ef41Sopenharmony_ci<ul>
6311cb0ef41Sopenharmony_ci<li><code>onMessage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The handler to receive channel messages
6321cb0ef41Sopenharmony_ci<ul>
6331cb0ef41Sopenharmony_ci<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The message data</li>
6341cb0ef41Sopenharmony_ci<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&#x3C;symbol></a> The name of the channel</li>
6351cb0ef41Sopenharmony_ci</ul>
6361cb0ef41Sopenharmony_ci</li>
6371cb0ef41Sopenharmony_ci</ul>
6381cb0ef41Sopenharmony_ci<p>Register a message handler to subscribe to this channel. This message handler
6391cb0ef41Sopenharmony_ciwill be run synchronously whenever a message is published to the channel. Any
6401cb0ef41Sopenharmony_cierrors thrown in the message handler will trigger an <a href="process.html#event-uncaughtexception"><code>'uncaughtException'</code></a>.</p>
6411cb0ef41Sopenharmony_ci
6421cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
6431cb0ef41Sopenharmony_ci
6441cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
6451cb0ef41Sopenharmony_ci
6461cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-function">(<span class="hljs-params">message, name</span>) =></span> {
6471cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
6481cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
6491cb0ef41Sopenharmony_ci
6501cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
6511cb0ef41Sopenharmony_ci
6521cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">subscribe</span>(<span class="hljs-function">(<span class="hljs-params">message, name</span>) =></span> {
6531cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
6541cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
6551cb0ef41Sopenharmony_ci<h5><code>channel.unsubscribe(onMessage)</code><span><a class="mark" href="#channelunsubscribeonmessage" id="channelunsubscribeonmessage">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_unsubscribe_onmessage"></a></h5>
6561cb0ef41Sopenharmony_ci<div class="api_metadata">
6571cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
6581cb0ef41Sopenharmony_ci<table>
6591cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
6601cb0ef41Sopenharmony_ci<tr><td>v18.7.0</td>
6611cb0ef41Sopenharmony_ci<td><p><span>Deprecated since: v18.7.0</span></p></td></tr>
6621cb0ef41Sopenharmony_ci<tr><td>v17.1.0, v16.14.0, v14.19.0</td>
6631cb0ef41Sopenharmony_ci<td><p>Added return value. Added to channels without subscribers.</p></td></tr>
6641cb0ef41Sopenharmony_ci<tr><td>v15.1.0, v14.17.0</td>
6651cb0ef41Sopenharmony_ci<td><p><span>Added in: v15.1.0, v14.17.0</span></p></td></tr>
6661cb0ef41Sopenharmony_ci</tbody></table>
6671cb0ef41Sopenharmony_ci</details>
6681cb0ef41Sopenharmony_ci</div>
6691cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="#diagnostics_channelunsubscribename-onmessage"><code>diagnostics_channel.unsubscribe(name, onMessage)</code></a></div><p></p>
6701cb0ef41Sopenharmony_ci<ul>
6711cb0ef41Sopenharmony_ci<li><code>onMessage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The previous subscribed handler to remove</li>
6721cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if the handler was found, <code>false</code> otherwise.</li>
6731cb0ef41Sopenharmony_ci</ul>
6741cb0ef41Sopenharmony_ci<p>Remove a message handler previously registered to this channel with
6751cb0ef41Sopenharmony_ci<a href="#channelsubscribeonmessage"><code>channel.subscribe(onMessage)</code></a>.</p>
6761cb0ef41Sopenharmony_ci
6771cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
6781cb0ef41Sopenharmony_ci
6791cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">onMessage</span>(<span class="hljs-params">message, name</span>) {
6821cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
6831cb0ef41Sopenharmony_ci}
6841cb0ef41Sopenharmony_ci
6851cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">subscribe</span>(onMessage);
6861cb0ef41Sopenharmony_ci
6871cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">unsubscribe</span>(onMessage);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
6881cb0ef41Sopenharmony_ci
6891cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
6901cb0ef41Sopenharmony_ci
6911cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">onMessage</span>(<span class="hljs-params">message, name</span>) {
6921cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Received data</span>
6931cb0ef41Sopenharmony_ci}
6941cb0ef41Sopenharmony_ci
6951cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">subscribe</span>(onMessage);
6961cb0ef41Sopenharmony_ci
6971cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">unsubscribe</span>(onMessage);</code><button class="copy-button">copy</button></pre>
6981cb0ef41Sopenharmony_ci<h5><code>channel.bindStore(store[, transform])</code><span><a class="mark" href="#channelbindstorestore-transform" id="channelbindstorestore-transform">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_bindstore_store_transform"></a></h5>
6991cb0ef41Sopenharmony_ci<div class="api_metadata">
7001cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
7011cb0ef41Sopenharmony_ci</div>
7021cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
7031cb0ef41Sopenharmony_ci<ul>
7041cb0ef41Sopenharmony_ci<li><code>store</code> <a href="async_context.html#class-asynclocalstorage" class="type">&#x3C;AsyncLocalStorage></a> The store to which to bind the context data</li>
7051cb0ef41Sopenharmony_ci<li><code>transform</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> Transform context data before setting the store context</li>
7061cb0ef41Sopenharmony_ci</ul>
7071cb0ef41Sopenharmony_ci<p>When <a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, ...)</code></a> is called, the given context data
7081cb0ef41Sopenharmony_ciwill be applied to any store bound to the channel. If the store has already been
7091cb0ef41Sopenharmony_cibound the previous <code>transform</code> function will be replaced with the new one.
7101cb0ef41Sopenharmony_ciThe <code>transform</code> function may be omitted to set the given context data as the
7111cb0ef41Sopenharmony_cicontext directly.</p>
7121cb0ef41Sopenharmony_ci
7131cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
7141cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:async_hooks'</span>;
7151cb0ef41Sopenharmony_ci
7161cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
7171cb0ef41Sopenharmony_ci
7181cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
7191cb0ef41Sopenharmony_ci
7201cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">bindStore</span>(store, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
7211cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> { data };
7221cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
7231cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:async_hooks'</span>);
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
7261cb0ef41Sopenharmony_ci
7271cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
7281cb0ef41Sopenharmony_ci
7291cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">bindStore</span>(store, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
7301cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> { data };
7311cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
7321cb0ef41Sopenharmony_ci<h5><code>channel.unbindStore(store)</code><span><a class="mark" href="#channelunbindstorestore" id="channelunbindstorestore">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_unbindstore_store"></a></h5>
7331cb0ef41Sopenharmony_ci<div class="api_metadata">
7341cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
7351cb0ef41Sopenharmony_ci</div>
7361cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
7371cb0ef41Sopenharmony_ci<ul>
7381cb0ef41Sopenharmony_ci<li><code>store</code> <a href="async_context.html#class-asynclocalstorage" class="type">&#x3C;AsyncLocalStorage></a> The store to unbind from the channel.</li>
7391cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if the store was found, <code>false</code> otherwise.</li>
7401cb0ef41Sopenharmony_ci</ul>
7411cb0ef41Sopenharmony_ci<p>Remove a message handler previously registered to this channel with
7421cb0ef41Sopenharmony_ci<a href="#channelbindstorestore-transform"><code>channel.bindStore(store)</code></a>.</p>
7431cb0ef41Sopenharmony_ci
7441cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
7451cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:async_hooks'</span>;
7461cb0ef41Sopenharmony_ci
7471cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
7501cb0ef41Sopenharmony_ci
7511cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">bindStore</span>(store);
7521cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">unbindStore</span>(store);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
7531cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:async_hooks'</span>);
7541cb0ef41Sopenharmony_ci
7551cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
7561cb0ef41Sopenharmony_ci
7571cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
7581cb0ef41Sopenharmony_ci
7591cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">bindStore</span>(store);
7601cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">unbindStore</span>(store);</code><button class="copy-button">copy</button></pre>
7611cb0ef41Sopenharmony_ci<h5><code>channel.runStores(context, fn[, thisArg[, ...args]])</code><span><a class="mark" href="#channelrunstorescontext-fn-thisarg-args" id="channelrunstorescontext-fn-thisarg-args">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_channel_runstores_context_fn_thisarg_args"></a></h5>
7621cb0ef41Sopenharmony_ci<div class="api_metadata">
7631cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
7641cb0ef41Sopenharmony_ci</div>
7651cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
7661cb0ef41Sopenharmony_ci<ul>
7671cb0ef41Sopenharmony_ci<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Message to send to subscribers and bind to stores</li>
7681cb0ef41Sopenharmony_ci<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> Handler to run within the entered storage context</li>
7691cb0ef41Sopenharmony_ci<li><code>thisArg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The receiver to be used for the function call.</li>
7701cb0ef41Sopenharmony_ci<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Optional arguments to pass to the function.</li>
7711cb0ef41Sopenharmony_ci</ul>
7721cb0ef41Sopenharmony_ci<p>Applies the given data to any AsyncLocalStorage instances bound to the channel
7731cb0ef41Sopenharmony_cifor the duration of the given function, then publishes to the channel within
7741cb0ef41Sopenharmony_cithe scope of that data is applied to the stores.</p>
7751cb0ef41Sopenharmony_ci<p>If a transform function was given to <a href="#channelbindstorestore-transform"><code>channel.bindStore(store)</code></a> it will be
7761cb0ef41Sopenharmony_ciapplied to transform the message data before it becomes the context value for
7771cb0ef41Sopenharmony_cithe store. The prior storage context is accessible from within the transform
7781cb0ef41Sopenharmony_cifunction in cases where context linking is required.</p>
7791cb0ef41Sopenharmony_ci<p>The context applied to the store should be accesible in any async code which
7801cb0ef41Sopenharmony_cicontinues from execution which began during the given function, however
7811cb0ef41Sopenharmony_cithere are some situations in which <a href="async_context.html#troubleshooting-context-loss">context loss</a> may occur.</p>
7821cb0ef41Sopenharmony_ci
7831cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
7841cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:async_hooks'</span>;
7851cb0ef41Sopenharmony_ci
7861cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
7871cb0ef41Sopenharmony_ci
7881cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
7891cb0ef41Sopenharmony_ci
7901cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">bindStore</span>(store, <span class="hljs-function">(<span class="hljs-params">message</span>) =></span> {
7911cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> parent = store.<span class="hljs-title function_">getStore</span>();
7921cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Span</span>(message, parent);
7931cb0ef41Sopenharmony_ci});
7941cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">runStores</span>({ <span class="hljs-attr">some</span>: <span class="hljs-string">'message'</span> }, <span class="hljs-function">() =></span> {
7951cb0ef41Sopenharmony_ci  store.<span class="hljs-title function_">getStore</span>(); <span class="hljs-comment">// Span({ some: 'message' })</span>
7961cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
7971cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:async_hooks'</span>);
7981cb0ef41Sopenharmony_ci
7991cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channel = diagnostics_channel.<span class="hljs-title function_">channel</span>(<span class="hljs-string">'my-channel'</span>);
8021cb0ef41Sopenharmony_ci
8031cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">bindStore</span>(store, <span class="hljs-function">(<span class="hljs-params">message</span>) =></span> {
8041cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> parent = store.<span class="hljs-title function_">getStore</span>();
8051cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Span</span>(message, parent);
8061cb0ef41Sopenharmony_ci});
8071cb0ef41Sopenharmony_cichannel.<span class="hljs-title function_">runStores</span>({ <span class="hljs-attr">some</span>: <span class="hljs-string">'message'</span> }, <span class="hljs-function">() =></span> {
8081cb0ef41Sopenharmony_ci  store.<span class="hljs-title function_">getStore</span>(); <span class="hljs-comment">// Span({ some: 'message' })</span>
8091cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
8101cb0ef41Sopenharmony_ci<h4>Class: <code>TracingChannel</code><span><a class="mark" href="#class-tracingchannel" id="class-tracingchannel">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_class_tracingchannel"></a></h4>
8111cb0ef41Sopenharmony_ci<div class="api_metadata">
8121cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
8131cb0ef41Sopenharmony_ci</div>
8141cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
8151cb0ef41Sopenharmony_ci<p>The class <code>TracingChannel</code> is a collection of <a href="#tracingchannel-channels">TracingChannel Channels</a> which
8161cb0ef41Sopenharmony_citogether express a single traceable action. It is used to formalize and
8171cb0ef41Sopenharmony_cisimplify the process of producing events for tracing application flow.
8181cb0ef41Sopenharmony_ci<a href="#diagnostics_channeltracingchannelnameorchannels"><code>diagnostics_channel.tracingChannel()</code></a> is used to construct a
8191cb0ef41Sopenharmony_ci<code>TracingChannel</code>. As with <code>Channel</code> it is recommended to create and reuse a
8201cb0ef41Sopenharmony_cisingle <code>TracingChannel</code> at the top-level of the file rather than creating them
8211cb0ef41Sopenharmony_cidynamically.</p>
8221cb0ef41Sopenharmony_ci<h5><code>tracingChannel.subscribe(subscribers)</code><span><a class="mark" href="#tracingchannelsubscribesubscribers" id="tracingchannelsubscribesubscribers">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_tracingchannel_subscribe_subscribers"></a></h5>
8231cb0ef41Sopenharmony_ci<div class="api_metadata">
8241cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
8251cb0ef41Sopenharmony_ci</div>
8261cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
8271cb0ef41Sopenharmony_ci<ul>
8281cb0ef41Sopenharmony_ci<li><code>subscribers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Set of <a href="#tracingchannel-channels">TracingChannel Channels</a> subscribers
8291cb0ef41Sopenharmony_ci<ul>
8301cb0ef41Sopenharmony_ci<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#startevent"><code>start</code> event</a> subscriber</li>
8311cb0ef41Sopenharmony_ci<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#endevent"><code>end</code> event</a> subscriber</li>
8321cb0ef41Sopenharmony_ci<li><code>asyncStart</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#asyncstartevent"><code>asyncStart</code> event</a> subscriber</li>
8331cb0ef41Sopenharmony_ci<li><code>asyncEnd</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#asyncendevent"><code>asyncEnd</code> event</a> subscriber</li>
8341cb0ef41Sopenharmony_ci<li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#errorevent"><code>error</code> event</a> subscriber</li>
8351cb0ef41Sopenharmony_ci</ul>
8361cb0ef41Sopenharmony_ci</li>
8371cb0ef41Sopenharmony_ci</ul>
8381cb0ef41Sopenharmony_ci<p>Helper to subscribe a collection of functions to the corresponding channels.
8391cb0ef41Sopenharmony_ciThis is the same as calling <a href="#channelsubscribeonmessage"><code>channel.subscribe(onMessage)</code></a> on each channel
8401cb0ef41Sopenharmony_ciindividually.</p>
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
8431cb0ef41Sopenharmony_ci
8441cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
8451cb0ef41Sopenharmony_ci
8461cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">subscribe</span>({
8471cb0ef41Sopenharmony_ci  <span class="hljs-title function_">start</span>(<span class="hljs-params">message</span>) {
8481cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle start message</span>
8491cb0ef41Sopenharmony_ci  },
8501cb0ef41Sopenharmony_ci  <span class="hljs-title function_">end</span>(<span class="hljs-params">message</span>) {
8511cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle end message</span>
8521cb0ef41Sopenharmony_ci  },
8531cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncStart</span>(<span class="hljs-params">message</span>) {
8541cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncStart message</span>
8551cb0ef41Sopenharmony_ci  },
8561cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncEnd</span>(<span class="hljs-params">message</span>) {
8571cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncEnd message</span>
8581cb0ef41Sopenharmony_ci  },
8591cb0ef41Sopenharmony_ci  <span class="hljs-title function_">error</span>(<span class="hljs-params">message</span>) {
8601cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle error message</span>
8611cb0ef41Sopenharmony_ci  },
8621cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
8631cb0ef41Sopenharmony_ci
8641cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
8651cb0ef41Sopenharmony_ci
8661cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">subscribe</span>({
8671cb0ef41Sopenharmony_ci  <span class="hljs-title function_">start</span>(<span class="hljs-params">message</span>) {
8681cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle start message</span>
8691cb0ef41Sopenharmony_ci  },
8701cb0ef41Sopenharmony_ci  <span class="hljs-title function_">end</span>(<span class="hljs-params">message</span>) {
8711cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle end message</span>
8721cb0ef41Sopenharmony_ci  },
8731cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncStart</span>(<span class="hljs-params">message</span>) {
8741cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncStart message</span>
8751cb0ef41Sopenharmony_ci  },
8761cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncEnd</span>(<span class="hljs-params">message</span>) {
8771cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncEnd message</span>
8781cb0ef41Sopenharmony_ci  },
8791cb0ef41Sopenharmony_ci  <span class="hljs-title function_">error</span>(<span class="hljs-params">message</span>) {
8801cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle error message</span>
8811cb0ef41Sopenharmony_ci  },
8821cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
8831cb0ef41Sopenharmony_ci<h5><code>tracingChannel.unsubscribe(subscribers)</code><span><a class="mark" href="#tracingchannelunsubscribesubscribers" id="tracingchannelunsubscribesubscribers">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_tracingchannel_unsubscribe_subscribers"></a></h5>
8841cb0ef41Sopenharmony_ci<div class="api_metadata">
8851cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
8861cb0ef41Sopenharmony_ci</div>
8871cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
8881cb0ef41Sopenharmony_ci<ul>
8891cb0ef41Sopenharmony_ci<li><code>subscribers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Set of <a href="#tracingchannel-channels">TracingChannel Channels</a> subscribers
8901cb0ef41Sopenharmony_ci<ul>
8911cb0ef41Sopenharmony_ci<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#startevent"><code>start</code> event</a> subscriber</li>
8921cb0ef41Sopenharmony_ci<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#endevent"><code>end</code> event</a> subscriber</li>
8931cb0ef41Sopenharmony_ci<li><code>asyncStart</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#asyncstartevent"><code>asyncStart</code> event</a> subscriber</li>
8941cb0ef41Sopenharmony_ci<li><code>asyncEnd</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#asyncendevent"><code>asyncEnd</code> event</a> subscriber</li>
8951cb0ef41Sopenharmony_ci<li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> The <a href="#errorevent"><code>error</code> event</a> subscriber</li>
8961cb0ef41Sopenharmony_ci</ul>
8971cb0ef41Sopenharmony_ci</li>
8981cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if all handlers were successfully unsubscribed,
8991cb0ef41Sopenharmony_ciand <code>false</code> otherwise.</li>
9001cb0ef41Sopenharmony_ci</ul>
9011cb0ef41Sopenharmony_ci<p>Helper to unsubscribe a collection of functions from the corresponding channels.
9021cb0ef41Sopenharmony_ciThis is the same as calling <a href="#channelunsubscribeonmessage"><code>channel.unsubscribe(onMessage)</code></a> on each channel
9031cb0ef41Sopenharmony_ciindividually.</p>
9041cb0ef41Sopenharmony_ci
9051cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
9061cb0ef41Sopenharmony_ci
9071cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
9081cb0ef41Sopenharmony_ci
9091cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">unsubscribe</span>({
9101cb0ef41Sopenharmony_ci  <span class="hljs-title function_">start</span>(<span class="hljs-params">message</span>) {
9111cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle start message</span>
9121cb0ef41Sopenharmony_ci  },
9131cb0ef41Sopenharmony_ci  <span class="hljs-title function_">end</span>(<span class="hljs-params">message</span>) {
9141cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle end message</span>
9151cb0ef41Sopenharmony_ci  },
9161cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncStart</span>(<span class="hljs-params">message</span>) {
9171cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncStart message</span>
9181cb0ef41Sopenharmony_ci  },
9191cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncEnd</span>(<span class="hljs-params">message</span>) {
9201cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncEnd message</span>
9211cb0ef41Sopenharmony_ci  },
9221cb0ef41Sopenharmony_ci  <span class="hljs-title function_">error</span>(<span class="hljs-params">message</span>) {
9231cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle error message</span>
9241cb0ef41Sopenharmony_ci  },
9251cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
9261cb0ef41Sopenharmony_ci
9271cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
9281cb0ef41Sopenharmony_ci
9291cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">unsubscribe</span>({
9301cb0ef41Sopenharmony_ci  <span class="hljs-title function_">start</span>(<span class="hljs-params">message</span>) {
9311cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle start message</span>
9321cb0ef41Sopenharmony_ci  },
9331cb0ef41Sopenharmony_ci  <span class="hljs-title function_">end</span>(<span class="hljs-params">message</span>) {
9341cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle end message</span>
9351cb0ef41Sopenharmony_ci  },
9361cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncStart</span>(<span class="hljs-params">message</span>) {
9371cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncStart message</span>
9381cb0ef41Sopenharmony_ci  },
9391cb0ef41Sopenharmony_ci  <span class="hljs-title function_">asyncEnd</span>(<span class="hljs-params">message</span>) {
9401cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle asyncEnd message</span>
9411cb0ef41Sopenharmony_ci  },
9421cb0ef41Sopenharmony_ci  <span class="hljs-title function_">error</span>(<span class="hljs-params">message</span>) {
9431cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Handle error message</span>
9441cb0ef41Sopenharmony_ci  },
9451cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
9461cb0ef41Sopenharmony_ci<h5><code>tracingChannel.traceSync(fn[, context[, thisArg[, ...args]]])</code><span><a class="mark" href="#tracingchanneltracesyncfn-context-thisarg-args" id="tracingchanneltracesyncfn-context-thisarg-args">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_tracingchannel_tracesync_fn_context_thisarg_args"></a></h5>
9471cb0ef41Sopenharmony_ci<div class="api_metadata">
9481cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
9491cb0ef41Sopenharmony_ci</div>
9501cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
9511cb0ef41Sopenharmony_ci<ul>
9521cb0ef41Sopenharmony_ci<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> Function to wrap a trace around</li>
9531cb0ef41Sopenharmony_ci<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Shared object to correlate events through</li>
9541cb0ef41Sopenharmony_ci<li><code>thisArg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The receiver to be used for the function call</li>
9551cb0ef41Sopenharmony_ci<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Optional arguments to pass to the function</li>
9561cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The return value of the given function</li>
9571cb0ef41Sopenharmony_ci</ul>
9581cb0ef41Sopenharmony_ci<p>Trace a synchronous function call. This will always produce a <a href="#startevent"><code>start</code> event</a>
9591cb0ef41Sopenharmony_ciand <a href="#endevent"><code>end</code> event</a> around the execution and may produce an <a href="#errorevent"><code>error</code> event</a>
9601cb0ef41Sopenharmony_ciif the given function throws an error. This will run the given function using
9611cb0ef41Sopenharmony_ci<a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, ...)</code></a> on the <code>start</code> channel which ensures all
9621cb0ef41Sopenharmony_cievents should have any bound stores set to match this trace context.</p>
9631cb0ef41Sopenharmony_ci
9641cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
9651cb0ef41Sopenharmony_ci
9661cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
9671cb0ef41Sopenharmony_ci
9681cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">traceSync</span>(<span class="hljs-function">() =></span> {
9691cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something</span>
9701cb0ef41Sopenharmony_ci}, {
9711cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'thing'</span>,
9721cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
9731cb0ef41Sopenharmony_ci
9741cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
9751cb0ef41Sopenharmony_ci
9761cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">traceSync</span>(<span class="hljs-function">() =></span> {
9771cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something</span>
9781cb0ef41Sopenharmony_ci}, {
9791cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'thing'</span>,
9801cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
9811cb0ef41Sopenharmony_ci<h5><code>tracingChannel.tracePromise(fn[, context[, thisArg[, ...args]]])</code><span><a class="mark" href="#tracingchanneltracepromisefn-context-thisarg-args" id="tracingchanneltracepromisefn-context-thisarg-args">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_tracingchannel_tracepromise_fn_context_thisarg_args"></a></h5>
9821cb0ef41Sopenharmony_ci<div class="api_metadata">
9831cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
9841cb0ef41Sopenharmony_ci</div>
9851cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
9861cb0ef41Sopenharmony_ci<ul>
9871cb0ef41Sopenharmony_ci<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> Promise-returning function to wrap a trace around</li>
9881cb0ef41Sopenharmony_ci<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Shared object to correlate trace events through</li>
9891cb0ef41Sopenharmony_ci<li><code>thisArg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The receiver to be used for the function call</li>
9901cb0ef41Sopenharmony_ci<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Optional arguments to pass to the function</li>
9911cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Chained from promise returned by the given function</li>
9921cb0ef41Sopenharmony_ci</ul>
9931cb0ef41Sopenharmony_ci<p>Trace a promise-returning function call. This will always produce a
9941cb0ef41Sopenharmony_ci<a href="#startevent"><code>start</code> event</a> and <a href="#endevent"><code>end</code> event</a> around the synchronous portion of the
9951cb0ef41Sopenharmony_cifunction execution, and will produce an <a href="#asyncstartevent"><code>asyncStart</code> event</a> and
9961cb0ef41Sopenharmony_ci<a href="#asyncendevent"><code>asyncEnd</code> event</a> when a promise continuation is reached. It may also
9971cb0ef41Sopenharmony_ciproduce an <a href="#errorevent"><code>error</code> event</a> if the given function throws an error or the
9981cb0ef41Sopenharmony_cireturned promise rejects. This will run the given function using
9991cb0ef41Sopenharmony_ci<a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, ...)</code></a> on the <code>start</code> channel which ensures all
10001cb0ef41Sopenharmony_cievents should have any bound stores set to match this trace context.</p>
10011cb0ef41Sopenharmony_ci
10021cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
10031cb0ef41Sopenharmony_ci
10041cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
10051cb0ef41Sopenharmony_ci
10061cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">tracePromise</span>(<span class="hljs-keyword">async</span> () => {
10071cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something</span>
10081cb0ef41Sopenharmony_ci}, {
10091cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'thing'</span>,
10101cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
10111cb0ef41Sopenharmony_ci
10121cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
10131cb0ef41Sopenharmony_ci
10141cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">tracePromise</span>(<span class="hljs-keyword">async</span> () => {
10151cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something</span>
10161cb0ef41Sopenharmony_ci}, {
10171cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'thing'</span>,
10181cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
10191cb0ef41Sopenharmony_ci<h5><code>tracingChannel.traceCallback(fn[, position[, context[, thisArg[, ...args]]]])</code><span><a class="mark" href="#tracingchanneltracecallbackfn-position-context-thisarg-args" id="tracingchanneltracecallbackfn-position-context-thisarg-args">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_tracingchannel_tracecallback_fn_position_context_thisarg_args"></a></h5>
10201cb0ef41Sopenharmony_ci<div class="api_metadata">
10211cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
10221cb0ef41Sopenharmony_ci</div>
10231cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
10241cb0ef41Sopenharmony_ci<ul>
10251cb0ef41Sopenharmony_ci<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> callback using function to wrap a trace around</li>
10261cb0ef41Sopenharmony_ci<li><code>position</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Zero-indexed argument position of expected callback</li>
10271cb0ef41Sopenharmony_ci<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Shared object to correlate trace events through</li>
10281cb0ef41Sopenharmony_ci<li><code>thisArg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The receiver to be used for the function call</li>
10291cb0ef41Sopenharmony_ci<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Optional arguments to pass to the function</li>
10301cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The return value of the given function</li>
10311cb0ef41Sopenharmony_ci</ul>
10321cb0ef41Sopenharmony_ci<p>Trace a callback-receiving function call. This will always produce a
10331cb0ef41Sopenharmony_ci<a href="#startevent"><code>start</code> event</a> and <a href="#endevent"><code>end</code> event</a> around the synchronous portion of the
10341cb0ef41Sopenharmony_cifunction execution, and will produce a <a href="#asyncstartevent"><code>asyncStart</code> event</a> and
10351cb0ef41Sopenharmony_ci<a href="#asyncendevent"><code>asyncEnd</code> event</a> around the callback execution. It may also produce an
10361cb0ef41Sopenharmony_ci<a href="#errorevent"><code>error</code> event</a> if the given function throws an error or the returned
10371cb0ef41Sopenharmony_cipromise rejects. This will run the given function using
10381cb0ef41Sopenharmony_ci<a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, ...)</code></a> on the <code>start</code> channel which ensures all
10391cb0ef41Sopenharmony_cievents should have any bound stores set to match this trace context.</p>
10401cb0ef41Sopenharmony_ci<p>The <code>position</code> will be -1 by default to indicate the final argument should
10411cb0ef41Sopenharmony_cibe used as the callback.</p>
10421cb0ef41Sopenharmony_ci
10431cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
10441cb0ef41Sopenharmony_ci
10451cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
10461cb0ef41Sopenharmony_ci
10471cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">traceCallback</span>(<span class="hljs-function">(<span class="hljs-params">arg1, callback</span>) =></span> {
10481cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something</span>
10491cb0ef41Sopenharmony_ci  <span class="hljs-title function_">callback</span>(<span class="hljs-literal">null</span>, <span class="hljs-string">'result'</span>);
10501cb0ef41Sopenharmony_ci}, <span class="hljs-number">1</span>, {
10511cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'thing'</span>,
10521cb0ef41Sopenharmony_ci}, thisArg, arg1, callback);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
10531cb0ef41Sopenharmony_ci
10541cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
10551cb0ef41Sopenharmony_ci
10561cb0ef41Sopenharmony_cichannels.<span class="hljs-title function_">traceCallback</span>(<span class="hljs-function">(<span class="hljs-params">arg1, callback</span>) =></span> {
10571cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Do something</span>
10581cb0ef41Sopenharmony_ci  <span class="hljs-title function_">callback</span>(<span class="hljs-literal">null</span>, <span class="hljs-string">'result'</span>);
10591cb0ef41Sopenharmony_ci}, {
10601cb0ef41Sopenharmony_ci  <span class="hljs-attr">some</span>: <span class="hljs-string">'thing'</span>,
10611cb0ef41Sopenharmony_ci}, thisArg, arg1, callback);</code><button class="copy-button">copy</button></pre>
10621cb0ef41Sopenharmony_ci<p>The callback will also be run with <a href="#channelrunstorescontext-fn-thisarg-args"><code>channel.runStores(context, ...)</code></a> which
10631cb0ef41Sopenharmony_cienables context loss recovery in some cases.</p>
10641cb0ef41Sopenharmony_ci
10651cb0ef41Sopenharmony_ci<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> diagnostics_channel <span class="hljs-keyword">from</span> <span class="hljs-string">'node:diagnostics_channel'</span>;
10661cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:async_hooks'</span>;
10671cb0ef41Sopenharmony_ci
10681cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
10691cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myStore = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
10701cb0ef41Sopenharmony_ci
10711cb0ef41Sopenharmony_ci<span class="hljs-comment">// The start channel sets the initial store data to something</span>
10721cb0ef41Sopenharmony_ci<span class="hljs-comment">// and stores that store data value on the trace context object</span>
10731cb0ef41Sopenharmony_cichannels.<span class="hljs-property">start</span>.<span class="hljs-title function_">bindStore</span>(myStore, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
10741cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> span = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Span</span>(data);
10751cb0ef41Sopenharmony_ci  data.<span class="hljs-property">span</span> = span;
10761cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> span;
10771cb0ef41Sopenharmony_ci});
10781cb0ef41Sopenharmony_ci
10791cb0ef41Sopenharmony_ci<span class="hljs-comment">// Then asyncStart can restore from that data it stored previously</span>
10801cb0ef41Sopenharmony_cichannels.<span class="hljs-property">asyncStart</span>.<span class="hljs-title function_">bindStore</span>(myStore, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
10811cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> data.<span class="hljs-property">span</span>;
10821cb0ef41Sopenharmony_ci});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> diagnostics_channel = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:diagnostics_channel'</span>);
10831cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">AsyncLocalStorage</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:async_hooks'</span>);
10841cb0ef41Sopenharmony_ci
10851cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> channels = diagnostics_channel.<span class="hljs-title function_">tracingChannel</span>(<span class="hljs-string">'my-channel'</span>);
10861cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> myStore = <span class="hljs-keyword">new</span> <span class="hljs-title class_">AsyncLocalStorage</span>();
10871cb0ef41Sopenharmony_ci
10881cb0ef41Sopenharmony_ci<span class="hljs-comment">// The start channel sets the initial store data to something</span>
10891cb0ef41Sopenharmony_ci<span class="hljs-comment">// and stores that store data value on the trace context object</span>
10901cb0ef41Sopenharmony_cichannels.<span class="hljs-property">start</span>.<span class="hljs-title function_">bindStore</span>(myStore, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
10911cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> span = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Span</span>(data);
10921cb0ef41Sopenharmony_ci  data.<span class="hljs-property">span</span> = span;
10931cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> span;
10941cb0ef41Sopenharmony_ci});
10951cb0ef41Sopenharmony_ci
10961cb0ef41Sopenharmony_ci<span class="hljs-comment">// Then asyncStart can restore from that data it stored previously</span>
10971cb0ef41Sopenharmony_cichannels.<span class="hljs-property">asyncStart</span>.<span class="hljs-title function_">bindStore</span>(myStore, <span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
10981cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> data.<span class="hljs-property">span</span>;
10991cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
11001cb0ef41Sopenharmony_ci<h4>TracingChannel Channels<span><a class="mark" href="#tracingchannel-channels" id="tracingchannel-channels">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_tracingchannel_channels"></a></h4>
11011cb0ef41Sopenharmony_ci<p>A TracingChannel is a collection of several diagnostics_channels representing
11021cb0ef41Sopenharmony_cispecific points in the execution lifecycle of a single traceable action. The
11031cb0ef41Sopenharmony_cibehaviour is split into five diagnostics_channels consisting of <code>start</code>,
11041cb0ef41Sopenharmony_ci<code>end</code>, <code>asyncStart</code>, <code>asyncEnd</code>, and <code>error</code>. A single traceable action will
11051cb0ef41Sopenharmony_cishare the same event object between all events, this can be helpful for
11061cb0ef41Sopenharmony_cimanaging correlation through a weakmap.</p>
11071cb0ef41Sopenharmony_ci<p>These event objects will be extended with <code>result</code> or <code>error</code> values when
11081cb0ef41Sopenharmony_cithe task "completes". In the case of a synchronous task the <code>result</code> will be
11091cb0ef41Sopenharmony_cithe return value and the <code>error</code> will be anything thrown from the function.
11101cb0ef41Sopenharmony_ciWith callback-based async functions the <code>result</code> will be the second argument
11111cb0ef41Sopenharmony_ciof the callback while the <code>error</code> will either be a thrown error visible in the
11121cb0ef41Sopenharmony_ci<code>end</code> event or the first callback argument in either of the <code>asyncStart</code> or
11131cb0ef41Sopenharmony_ci<code>asyncEnd</code> events.</p>
11141cb0ef41Sopenharmony_ci<p>Tracing channels should follow a naming pattern of:</p>
11151cb0ef41Sopenharmony_ci<ul>
11161cb0ef41Sopenharmony_ci<li><code>tracing:module.class.method:start</code> or <code>tracing:module.function:start</code></li>
11171cb0ef41Sopenharmony_ci<li><code>tracing:module.class.method:end</code> or <code>tracing:module.function:end</code></li>
11181cb0ef41Sopenharmony_ci<li><code>tracing:module.class.method:asyncStart</code> or <code>tracing:module.function:asyncStart</code></li>
11191cb0ef41Sopenharmony_ci<li><code>tracing:module.class.method:asyncEnd</code> or <code>tracing:module.function:asyncEnd</code></li>
11201cb0ef41Sopenharmony_ci<li><code>tracing:module.class.method:error</code> or <code>tracing:module.function:error</code></li>
11211cb0ef41Sopenharmony_ci</ul>
11221cb0ef41Sopenharmony_ci<h5><code>start(event)</code><span><a class="mark" href="#startevent" id="startevent">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_start_event"></a></h5>
11231cb0ef41Sopenharmony_ci<ul>
11241cb0ef41Sopenharmony_ci<li>Name: <code>tracing:${name}:start</code></li>
11251cb0ef41Sopenharmony_ci</ul>
11261cb0ef41Sopenharmony_ci<p>The <code>start</code> event represents the point at which a function is called. At this
11271cb0ef41Sopenharmony_cipoint the event data may contain function arguments or anything else available
11281cb0ef41Sopenharmony_ciat the very start of the execution of the function.</p>
11291cb0ef41Sopenharmony_ci<h5><code>end(event)</code><span><a class="mark" href="#endevent" id="endevent">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_end_event"></a></h5>
11301cb0ef41Sopenharmony_ci<ul>
11311cb0ef41Sopenharmony_ci<li>Name: <code>tracing:${name}:end</code></li>
11321cb0ef41Sopenharmony_ci</ul>
11331cb0ef41Sopenharmony_ci<p>The <code>end</code> event represents the point at which a function call returns a value.
11341cb0ef41Sopenharmony_ciIn the case of an async function this is when the promise returned not when the
11351cb0ef41Sopenharmony_cifunction itself makes a return statement internally. At this point, if the
11361cb0ef41Sopenharmony_citraced function was synchronous the <code>result</code> field will be set to the return
11371cb0ef41Sopenharmony_civalue of the function. Alternatively, the <code>error</code> field may be present to
11381cb0ef41Sopenharmony_cirepresent any thrown errors.</p>
11391cb0ef41Sopenharmony_ci<p>It is recommended to listen specifically to the <code>error</code> event to track errors
11401cb0ef41Sopenharmony_cias it may be possible for a traceable action to produce multiple errors. For
11411cb0ef41Sopenharmony_ciexample, an async task which fails may be started internally before the sync
11421cb0ef41Sopenharmony_cipart of the task then throws an error.</p>
11431cb0ef41Sopenharmony_ci<h5><code>asyncStart(event)</code><span><a class="mark" href="#asyncstartevent" id="asyncstartevent">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_asyncstart_event"></a></h5>
11441cb0ef41Sopenharmony_ci<ul>
11451cb0ef41Sopenharmony_ci<li>Name: <code>tracing:${name}:asyncStart</code></li>
11461cb0ef41Sopenharmony_ci</ul>
11471cb0ef41Sopenharmony_ci<p>The <code>asyncStart</code> event represents the callback or continuation of a traceable
11481cb0ef41Sopenharmony_cifunction being reached. At this point things like callback arguments may be
11491cb0ef41Sopenharmony_ciavailable, or anything else expressing the "result" of the action.</p>
11501cb0ef41Sopenharmony_ci<p>For callbacks-based functions, the first argument of the callback will be
11511cb0ef41Sopenharmony_ciassigned to the <code>error</code> field, if not <code>undefined</code> or <code>null</code>, and the second
11521cb0ef41Sopenharmony_ciargument will be assigned to the <code>result</code> field.</p>
11531cb0ef41Sopenharmony_ci<p>For promises, the argument to the <code>resolve</code> path will be assigned to <code>result</code>
11541cb0ef41Sopenharmony_cior the argument to the <code>reject</code> path will be assign to <code>error</code>.</p>
11551cb0ef41Sopenharmony_ci<p>It is recommended to listen specifically to the <code>error</code> event to track errors
11561cb0ef41Sopenharmony_cias it may be possible for a traceable action to produce multiple errors. For
11571cb0ef41Sopenharmony_ciexample, an async task which fails may be started internally before the sync
11581cb0ef41Sopenharmony_cipart of the task then throws an error.</p>
11591cb0ef41Sopenharmony_ci<h5><code>asyncEnd(event)</code><span><a class="mark" href="#asyncendevent" id="asyncendevent">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_asyncend_event"></a></h5>
11601cb0ef41Sopenharmony_ci<ul>
11611cb0ef41Sopenharmony_ci<li>Name: <code>tracing:${name}:asyncEnd</code></li>
11621cb0ef41Sopenharmony_ci</ul>
11631cb0ef41Sopenharmony_ci<p>The <code>asyncEnd</code> event represents the callback of an asynchronous function
11641cb0ef41Sopenharmony_cireturning. It's not likely event data will change after the <code>asyncStart</code> event,
11651cb0ef41Sopenharmony_cihowever it may be useful to see the point where the callback completes.</p>
11661cb0ef41Sopenharmony_ci<h5><code>error(event)</code><span><a class="mark" href="#errorevent" id="errorevent">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_error_event"></a></h5>
11671cb0ef41Sopenharmony_ci<ul>
11681cb0ef41Sopenharmony_ci<li>Name: <code>tracing:${name}:error</code></li>
11691cb0ef41Sopenharmony_ci</ul>
11701cb0ef41Sopenharmony_ci<p>The <code>error</code> event represents any error produced by the traceable function
11711cb0ef41Sopenharmony_cieither synchronously or asynchronously. If an error is thrown in the
11721cb0ef41Sopenharmony_cisynchronous portion of the traced function the error will be assigned to the
11731cb0ef41Sopenharmony_ci<code>error</code> field of the event and the <code>error</code> event will be triggered. If an error
11741cb0ef41Sopenharmony_ciis received asynchronously through a callback or promise rejection it will also
11751cb0ef41Sopenharmony_cibe assigned to the <code>error</code> field of the event and trigger the <code>error</code> event.</p>
11761cb0ef41Sopenharmony_ci<p>It is possible for a single traceable function call to produce errors multiple
11771cb0ef41Sopenharmony_citimes so this should be considered when consuming this event. For example, if
11781cb0ef41Sopenharmony_cianother async task is triggered internally which fails and then the sync part
11791cb0ef41Sopenharmony_ciof the function then throws and error two <code>error</code> events will be emitted, one
11801cb0ef41Sopenharmony_cifor the sync error and one for the async error.</p>
11811cb0ef41Sopenharmony_ci<h4>Built-in Channels<span><a class="mark" href="#built-in-channels" id="built-in-channels">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_built_in_channels"></a></h4>
11821cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
11831cb0ef41Sopenharmony_ci<p>While the diagnostics_channel API is now considered stable, the built-in
11841cb0ef41Sopenharmony_cichannels currently available are not. Each channel must be declared stable
11851cb0ef41Sopenharmony_ciindependently.</p>
11861cb0ef41Sopenharmony_ci<h5>HTTP<span><a class="mark" href="#http" id="http">#</a></span><a aria-hidden="true" class="legacy" id="diagnostics_channel_http"></a></h5>
11871cb0ef41Sopenharmony_ci<p><code>http.client.request.start</code></p>
11881cb0ef41Sopenharmony_ci<ul>
11891cb0ef41Sopenharmony_ci<li><code>request</code> <a href="http.html#class-httpclientrequest" class="type">&#x3C;http.ClientRequest></a></li>
11901cb0ef41Sopenharmony_ci</ul>
11911cb0ef41Sopenharmony_ci<p>Emitted when client starts a request.</p>
11921cb0ef41Sopenharmony_ci<p><code>http.client.response.finish</code></p>
11931cb0ef41Sopenharmony_ci<ul>
11941cb0ef41Sopenharmony_ci<li><code>request</code> <a href="http.html#class-httpclientrequest" class="type">&#x3C;http.ClientRequest></a></li>
11951cb0ef41Sopenharmony_ci<li><code>response</code> <a href="http.html#class-httpincomingmessage" class="type">&#x3C;http.IncomingMessage></a></li>
11961cb0ef41Sopenharmony_ci</ul>
11971cb0ef41Sopenharmony_ci<p>Emitted when client receives a response.</p>
11981cb0ef41Sopenharmony_ci<p><code>http.server.request.start</code></p>
11991cb0ef41Sopenharmony_ci<ul>
12001cb0ef41Sopenharmony_ci<li><code>request</code> <a href="http.html#class-httpincomingmessage" class="type">&#x3C;http.IncomingMessage></a></li>
12011cb0ef41Sopenharmony_ci<li><code>response</code> <a href="http.html#class-httpserverresponse" class="type">&#x3C;http.ServerResponse></a></li>
12021cb0ef41Sopenharmony_ci<li><code>socket</code> <a href="net.html#class-netsocket" class="type">&#x3C;net.Socket></a></li>
12031cb0ef41Sopenharmony_ci<li><code>server</code> <a href="http.html#class-httpserver" class="type">&#x3C;http.Server></a></li>
12041cb0ef41Sopenharmony_ci</ul>
12051cb0ef41Sopenharmony_ci<p>Emitted when server receives a request.</p>
12061cb0ef41Sopenharmony_ci<p><code>http.server.response.finish</code></p>
12071cb0ef41Sopenharmony_ci<ul>
12081cb0ef41Sopenharmony_ci<li><code>request</code> <a href="http.html#class-httpincomingmessage" class="type">&#x3C;http.IncomingMessage></a></li>
12091cb0ef41Sopenharmony_ci<li><code>response</code> <a href="http.html#class-httpserverresponse" class="type">&#x3C;http.ServerResponse></a></li>
12101cb0ef41Sopenharmony_ci<li><code>socket</code> <a href="net.html#class-netsocket" class="type">&#x3C;net.Socket></a></li>
12111cb0ef41Sopenharmony_ci<li><code>server</code> <a href="http.html#class-httpserver" class="type">&#x3C;http.Server></a></li>
12121cb0ef41Sopenharmony_ci</ul>
12131cb0ef41Sopenharmony_ci<p>Emitted when server sends a response.</p>
12141cb0ef41Sopenharmony_ci<p><code>net.client.socket</code></p>
12151cb0ef41Sopenharmony_ci<ul>
12161cb0ef41Sopenharmony_ci<li><code>socket</code> <a href="net.html#class-netsocket" class="type">&#x3C;net.Socket></a></li>
12171cb0ef41Sopenharmony_ci</ul>
12181cb0ef41Sopenharmony_ci<p>Emitted when a new TCP or pipe client socket is created.</p>
12191cb0ef41Sopenharmony_ci<p><code>net.server.socket</code></p>
12201cb0ef41Sopenharmony_ci<ul>
12211cb0ef41Sopenharmony_ci<li><code>socket</code> <a href="net.html#class-netsocket" class="type">&#x3C;net.Socket></a></li>
12221cb0ef41Sopenharmony_ci</ul>
12231cb0ef41Sopenharmony_ci<p>Emitted when a new TCP or pipe connection is received.</p>
12241cb0ef41Sopenharmony_ci<p><code>udp.socket</code></p>
12251cb0ef41Sopenharmony_ci<ul>
12261cb0ef41Sopenharmony_ci<li><code>socket</code> <a href="dgram.html#class-dgramsocket" class="type">&#x3C;dgram.Socket></a></li>
12271cb0ef41Sopenharmony_ci</ul>
12281cb0ef41Sopenharmony_ci<p>Emitted when a new UDP socket is created.</p></section>
12291cb0ef41Sopenharmony_ci        <!-- API END -->
12301cb0ef41Sopenharmony_ci      </div>
12311cb0ef41Sopenharmony_ci    </div>
12321cb0ef41Sopenharmony_ci  </div>
12331cb0ef41Sopenharmony_ci</body>
12341cb0ef41Sopenharmony_ci</html>
1235