dev: update TelemetryService

This commit is contained in:
KernelDeimos
2024-12-11 16:36:20 -05:00
parent 08dbef7b8c
commit cbe15a42bd
2 changed files with 27 additions and 3 deletions
@@ -165,7 +165,7 @@ class LLCopy extends LLFilesystemOperation {
this.checkpoint('before parallel tasks');
const tasks = new ParallelTasks({ tracer, max: 4 });
await tracer.startActiveSpan(`fs:cp:parallel-portion`, async span => {
await Context.arun(`fs:cp:parallel-portion`, async () => {
this.checkpoint('starting parallel tasks');
// Add child copy tasks if this is a directory
if ( source.entry.is_dir ) {
@@ -216,8 +216,6 @@ class LLCopy extends LLFilesystemOperation {
this.checkpoint('waiting for parallel tasks');
await tasks.awaitAll();
this.checkpoint('finishing up');
span.end();
});
node = node || await fs.node(new NodeUIDSelector(uuid));
@@ -16,6 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const opentelemetry = require("@opentelemetry/api");
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { PeriodicExportingMetricReader, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics');
@@ -59,6 +60,31 @@ class TelemetryService extends BaseService {
this.sdk = sdk;
this.sdk.start();
this.tracer_ = opentelemetry.trace.getTracer(
'puter-tracer'
);
}
_init () {
const svc_context = this.services.get('context');
svc_context.register_context_hook('pre_arun', ({ hints, trace_name, callback, replace_callback }) => {
if ( ! trace_name ) return;
if ( ! hints.trace ) return;
console.log('APPLYING TRACE NAME', trace_name);
replace_callback(async () => {
return await this.tracer_.startActiveSpan(trace_name, async span => {
try {
return await callback();
} catch (error) {
span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR, message: error.message });
throw error;
} finally {
span.end();
}
});
});
});
}
getConfiguredExporter_() {