Skip to content

Commit 245548f

Browse files
authored
[Azure Monitor OpenTelemetry] Add support for Azure Functions programming model v4 (Azure#27161)
### Packages impacted by this PR @azure/monitor-opentelemetry Related to microsoft/ApplicationInsights-node.js#1181
1 parent 5a617a5 commit 245548f

File tree

3 files changed

+1
-36
lines changed

3 files changed

+1
-36
lines changed

sdk/monitor/monitor-opentelemetry/src/traces/azureFnHook.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@ export class AzureFunctionsHook {
1818
try {
1919
// TODO: Add types files when publicly available
2020
this._functionsCoreModule = require("@azure/functions-core");
21-
// Only v3 of Azure Functions library is supported right now. See matrix of versions here:
22-
// https://github.com/Azure/azure-functions-nodejs-library
23-
const funcProgModel = this._functionsCoreModule.getProgrammingModel();
24-
if (funcProgModel.name === "@azure/functions" && funcProgModel.version.startsWith("3.")) {
25-
this._addPreInvocationHook();
26-
} else {
27-
Logger.getInstance().debug(
28-
`AzureFunctionsHook does not support model "${funcProgModel.name}" version "${funcProgModel.version}"`
29-
);
30-
}
21+
this._addPreInvocationHook();
3122
} catch (error) {
3223
Logger.getInstance().debug(
3324
"@azure/functions-core failed to load, not running in Azure Functions"

sdk/monitor/monitor-opentelemetry/test/internal/unit/traces/azureFnHook.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,6 @@ describe("Library/AzureFunctionsHook", () => {
5555
Module.prototype.require = originalRequire;
5656
});
5757

58-
it("Hook not added if using not supported programming model", () => {
59-
var Module = require("module");
60-
var preInvocationCalled = false;
61-
Module.prototype.require = function () {
62-
if (arguments[0] === "@azure/functions-core") {
63-
return {
64-
registerHook(name: string) {
65-
if (name === "preInvocation") {
66-
preInvocationCalled = true;
67-
}
68-
},
69-
getProgrammingModel() {
70-
return {
71-
name: "@azure/functions",
72-
version: "2.x",
73-
};
74-
},
75-
};
76-
}
77-
return originalRequire.apply(this, arguments);
78-
};
79-
let azureFnHook = new AzureFunctionsHook();
80-
assert.ok(azureFnHook, "azureFnHook");
81-
assert.ok(!preInvocationCalled, "preInvocationCalled");
82-
});
83-
8458
it("Pre Invokation Hook added if running in Azure Functions and context is propagated", () => {
8559
let Module = require("module");
8660
let preInvocationCalled = false;

0 commit comments

Comments
 (0)