Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions extensions/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Extension System Development Guide
TODO: Move extensions docs into here?
For now see [here](../doc/contributors/extensions/README.md)
# Extension System Development Guide]

## Specific Extension Logs
## Where to find documentation

### Here
Documentation for extensions is [here](src/backend/doc/extensions/README.md).

### Not Here

Outdated documentation for extensions is [here](../doc/contributors/extensions/README.md).
This documentation may include some topics that are missing from the current documentation. Eventually those topics should be updated and transferred to the current documentation so that this documentation may be removed.
13 changes: 13 additions & 0 deletions extensions/hellodriver/hellodriver.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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');
});
4 changes: 4 additions & 0 deletions src/backend/src/CoreModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion src/backend/src/services/TraceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = {
Expand Down
Loading