Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure Monitor OpenTelemetry] Add support for Azure Functions programming model v4 #27161

Merged
merged 1 commit into from
Sep 19, 2023
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
11 changes: 1 addition & 10 deletions sdk/monitor/monitor-opentelemetry/src/traces/azureFnHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ export class AzureFunctionsHook {
try {
// TODO: Add types files when publicly available
this._functionsCoreModule = require("@azure/functions-core");
// Only v3 of Azure Functions library is supported right now. See matrix of versions here:
// https://github.com/Azure/azure-functions-nodejs-library
const funcProgModel = this._functionsCoreModule.getProgrammingModel();
if (funcProgModel.name === "@azure/functions" && funcProgModel.version.startsWith("3.")) {
this._addPreInvocationHook();
} else {
Logger.getInstance().debug(
`AzureFunctionsHook does not support model "${funcProgModel.name}" version "${funcProgModel.version}"`
);
}
this._addPreInvocationHook();
} catch (error) {
Logger.getInstance().debug(
"@azure/functions-core failed to load, not running in Azure Functions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,6 @@ describe("Library/AzureFunctionsHook", () => {
Module.prototype.require = originalRequire;
});

it("Hook not added if using not supported programming model", () => {
var Module = require("module");
var preInvocationCalled = false;
Module.prototype.require = function () {
if (arguments[0] === "@azure/functions-core") {
return {
registerHook(name: string) {
if (name === "preInvocation") {
preInvocationCalled = true;
}
},
getProgrammingModel() {
return {
name: "@azure/functions",
version: "2.x",
};
},
};
}
return originalRequire.apply(this, arguments);
};
let azureFnHook = new AzureFunctionsHook();
assert.ok(azureFnHook, "azureFnHook");
assert.ok(!preInvocationCalled, "preInvocationCalled");
});

it("Pre Invokation Hook added if running in Azure Functions and context is propagated", () => {
let Module = require("module");
let preInvocationCalled = false;
Expand Down