dev: update use of spans in extensions

This commit is contained in:
KernelDeimos
2025-12-07 22:04:31 -05:00
committed by Eric Dubé
parent 64b0ba89cc
commit d0ea063d0f
3 changed files with 26 additions and 1 deletions

View File

@@ -1,5 +1,8 @@
const { kv } = extension.import('data');
const spanify = extension.import('core').spanify;
const svc_trace = extension.import('service:traceService');
/**
* Here we create an interface called 'hello-world'. This interface
* specifies that any implementation of 'hello-world' should implement
@@ -64,6 +67,15 @@ extension.on('create.drivers', event => {
});
});
extension.on('create.drivers', event => {
event.createDriver('hello-world', 'slow-hello', {
greet: spanify('slow-hello:greet', async ({ subject }) => {
await new Promise(rslv => setTimeout(rslv, 1000));
return `Hello, ${subject ?? 'World'}!`;
}),
});
});
extension.on('create.drivers', event => {
event.createDriver('hello-world', 'extension-examples', {
greet ({ subject }) {
@@ -113,5 +125,6 @@ extension.on('create.drivers', event => {
*/
extension.on('create.permissions', event => {
event.grant_to_everyone('service:no-frills:ii:hello-world');
event.grant_to_everyone('service:slow-hello:ii:hello-world');
event.grant_to_everyone('service:extension-examples:ii:hello-world');
});

View File

@@ -78,6 +78,10 @@ const install = async ({ context, services, app, useapi, modapi }) => {
def('core.database', require('./services/database/consts.js'));
// Add otelutil functions to `core.`
def('core.spanify', require('./util/otelutil').spanify);
def('core.abtest', require('./util/otelutil').abtest);
// Extension compatibility
const runtimeModule = new RuntimeModule({ name: 'core' });
context.get('runtime-modules').register(runtimeModule);

View File

@@ -52,7 +52,7 @@ class TraceService extends BaseService {
* @param {opentelemetry.SpanOptions} [options] - The opentelemetry options object
* @returns {Promise} - A promise that resolves to the return value of `fn`.
*/
async spanify (name, fn, options) {
async span (name, fn, options) {
const args = [name];
if ( options !== null && typeof options === 'object' ) {
args.push(options);
@@ -72,6 +72,14 @@ class TraceService extends BaseService {
});
return await this.tracer.startActiveSpan(...args);
}
/**
* @deprecated use `span` instead to avoid confusion with the spanify
* function from otelutil.
*/
async spanify (name, fn, options) {
return await this.span(name, fn, options);
}
}
module.exports = {