@embrace-io/web-sdk
Version:
101 lines (100 loc) • 3.31 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
let _opentelemetry_api = require("@opentelemetry/api");
let _opentelemetry_api_logs = require("@opentelemetry/api-logs");
//#region src/instrumentations/InstrumentationAbstract/InstrumentationAbstract.ts
var InstrumentationAbstract = class {
instrumentationName;
instrumentationVersion;
_config = {};
_diag;
constructor(instrumentationName, instrumentationVersion, config) {
this.instrumentationName = instrumentationName;
this.instrumentationVersion = instrumentationVersion;
this.setConfig(config);
this._diag = _opentelemetry_api.diag.createComponentLogger({ namespace: instrumentationName });
this._tracer = _opentelemetry_api.trace.getTracer(instrumentationName, instrumentationVersion);
this._meter = _opentelemetry_api.metrics.getMeter(instrumentationName, instrumentationVersion);
this._logger = _opentelemetry_api_logs.logs.getLogger(instrumentationName, instrumentationVersion);
this._updateMetricInstruments();
}
_tracer;
get tracer() {
return this._tracer;
}
_meter;
get meter() {
return this._meter;
}
_logger;
get logger() {
return this._logger;
}
/**
* @experimental
*
* Get module definitions defined by {@link init}.
* This can be used for experimental compile-time instrumentation.
*
* @returns an array of {@link InstrumentationModuleDefinition}
*/
getModuleDefinitions() {
const initResult = this.init() ?? [];
if (!Array.isArray(initResult)) return [initResult];
return initResult;
}
getConfig() {
return this._config;
}
/**
* Sets InstrumentationConfig to this plugin
* @param config
*/
setConfig(config) {
this._config = {
enabled: true,
...config
};
}
/**
* Sets LoggerProvider to this plugin
* @param loggerProvider
*/
setLoggerProvider(loggerProvider) {
this._logger = loggerProvider.getLogger(this.instrumentationName, this.instrumentationVersion);
}
/**
* Sets MeterProvider to this plugin
* @param meterProvider
*/
setMeterProvider(meterProvider) {
this._meter = meterProvider.getMeter(this.instrumentationName, this.instrumentationVersion);
this._updateMetricInstruments();
}
/**
* Sets TraceProvider to this plugin
* @param tracerProvider
*/
setTracerProvider(tracerProvider) {
this._tracer = tracerProvider.getTracer(this.instrumentationName, this.instrumentationVersion);
}
_updateMetricInstruments() {}
/**
* Execute span customization hook, if configured, and log any errors.
* Any semantics of the trigger and info are defined by the specific instrumentation.
* @param hookHandler The optional hook handler which the user has configured via instrumentation config
* @param triggerName The name of the trigger for executing the hook for logging purposes
* @param span The span to which the hook should be applied
* @param info The info object to be passed to the hook, with useful data the hook may use
*/
_runSpanCustomizationHook(hookHandler, triggerName, span, info) {
if (!hookHandler) return;
try {
hookHandler(span, info);
} catch (e) {
this._diag.error(`Error running span customization hook due to exception in handler`, { triggerName }, e);
}
}
};
//#endregion
exports.InstrumentationAbstract = InstrumentationAbstract;
//# sourceMappingURL=InstrumentationAbstract.cjs.map