@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
52 lines (51 loc) • 1.72 kB
JavaScript
import { context, trace } from '@opentelemetry/api';
import { Tracer as InternalTracer } from '../empty/diagnostics-tracer-empty';
export class Tracer extends InternalTracer {
static startTrace(key, fn) {
if (typeof (window) !== 'undefined') {
return fn(null);
}
const tracer = trace.getTracer('next-app');
return tracer.startActiveSpan(key, (span) => {
return fn(span);
});
}
static startSpan(key, createContext = false, currentContext) {
if (typeof (window) !== 'undefined') {
return { span: null };
}
const tracer = trace.getTracer('next-app');
let ctx;
const span = tracer.startSpan(`SF ${key}`, undefined, currentContext || context.active());
if (createContext) {
ctx = trace.setSpan(context.active(), span);
}
else {
ctx = context.active();
}
return { span, ctx };
}
static traceWidget(widgetContext, createContext = false) {
return this.startSpan(`Render widget: ${widgetContext.model.Caption || widgetContext.model.Name}`, createContext, widgetContext.traceContext);
}
static endSpan(span) {
span?.end();
return null;
}
static withContext(fn, ctx) {
if (typeof (window) !== 'undefined') {
return fn();
}
if (ctx) {
return context.with(ctx, fn);
}
return fn();
}
static logEvent(name, attributes, span) {
if (typeof (window) !== 'undefined') {
return;
}
const activeSpan = span || trace.getActiveSpan();
activeSpan?.addEvent(name, attributes);
}
}