@azure/functions-opentelemetry-instrumentation
Version:
OpenTelemetry Azure Functions automatic instrumentation package.
183 lines (160 loc) • 6.78 kB
JavaScript
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/constants.ts":
/*!**************************!*\
!*** ./src/constants.ts ***!
\**************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.version = void 0;
exports.version = '0.1.0';
/***/ }),
/***/ "./src/instrumentation.ts":
/*!********************************!*\
!*** ./src/instrumentation.ts ***!
\********************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.AzureFunctionsInstrumentation = void 0;
const api_1 = __webpack_require__(/*! @opentelemetry/api */ "@opentelemetry/api");
const api_logs_1 = __webpack_require__(/*! @opentelemetry/api-logs */ "@opentelemetry/api-logs");
const instrumentation_1 = __webpack_require__(/*! @opentelemetry/instrumentation */ "@opentelemetry/instrumentation");
const constants_1 = __webpack_require__(/*! ./constants */ "./src/constants.ts");
class AzureFunctionsInstrumentation extends instrumentation_1.InstrumentationBase {
constructor(config = {}) {
super('@azure/functions-opentelemetry-instrumentation', constants_1.version, config);
}
init() {
return new instrumentation_1.InstrumentationNodeModuleDefinition('@azure/functions', ['^4.5.0'], (moduleExports) => this._patch(moduleExports), (moduleExports) => this._unPatch(moduleExports));
}
_patch(azFunc) {
const disposables = [];
// Tell the Azure Functions Host that we will send logs directly from Node.js
// (so that the host doesn't duplicate)
azFunc.app.setup({
capabilities: {
WorkerOpenTelemetryEnabled: true,
},
});
// Send logs directly from Node.js
disposables.push(azFunc.app.hook.log((context) => {
this.logger.emit({
body: context.message,
severityNumber: toOtelSeverityNumber(context.level),
severityText: context.level,
});
}));
// Ensure Azure Functions Host trace context is propagated onto the user's Node.js function handler
disposables.push(azFunc.app.hook.preInvocation((context) => {
const traceContext = context.invocationContext.traceContext;
if (traceContext) {
context.functionHandler = api_1.context.bind(api_1.propagation.extract(api_1.context.active(), {
traceparent: traceContext.traceParent,
tracestate: traceContext.traceState,
}), context.functionHandler);
}
}));
this._azFuncDisposable = azFunc.Disposable.from(...disposables);
return azFunc;
}
_unPatch(azFunc) {
var _a;
(_a = this._azFuncDisposable) === null || _a === void 0 ? void 0 : _a.dispose();
azFunc.app.setup({
capabilities: {
WorkerOpenTelemetryEnabled: false,
},
});
}
}
exports.AzureFunctionsInstrumentation = AzureFunctionsInstrumentation;
function toOtelSeverityNumber(level) {
switch (level) {
case 'information':
return api_logs_1.SeverityNumber.INFO;
case 'debug':
return api_logs_1.SeverityNumber.DEBUG;
case 'error':
return api_logs_1.SeverityNumber.ERROR;
case 'trace':
return api_logs_1.SeverityNumber.TRACE;
case 'warning':
return api_logs_1.SeverityNumber.WARN;
case 'critical':
return api_logs_1.SeverityNumber.FATAL;
default:
return api_logs_1.SeverityNumber.UNSPECIFIED;
}
}
/***/ }),
/***/ "@opentelemetry/api":
/*!*************************************!*\
!*** external "@opentelemetry/api" ***!
\*************************************/
/***/ ((module) => {
module.exports = require("@opentelemetry/api");
/***/ }),
/***/ "@opentelemetry/api-logs":
/*!******************************************!*\
!*** external "@opentelemetry/api-logs" ***!
\******************************************/
/***/ ((module) => {
module.exports = require("@opentelemetry/api-logs");
/***/ }),
/***/ "@opentelemetry/instrumentation":
/*!*************************************************!*\
!*** external "@opentelemetry/instrumentation" ***!
\*************************************************/
/***/ ((module) => {
module.exports = require("@opentelemetry/instrumentation");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
(() => {
var exports = __webpack_exports__;
/*!**********************!*\
!*** ./src/index.ts ***!
\**********************/
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.AzureFunctionsInstrumentation = void 0;
var instrumentation_1 = __webpack_require__(/*! ./instrumentation */ "./src/instrumentation.ts");
Object.defineProperty(exports, "AzureFunctionsInstrumentation", ({ enumerable: true, get: function () { return instrumentation_1.AzureFunctionsInstrumentation; } }));
})();
module.exports = __webpack_exports__;
/******/ })()
;
//# sourceMappingURL=azure-functions-instrumentation.js.map