Skip to content

Commit bff2e23

Browse files
authored
feat(azure-functions): support Azure Functions programming model v4 (#4426)
See https://learn.microsoft.com/en-ca/azure/azure-functions/functions-node-upgrade-v4 This builds on the work in #4178 by @qzxlkj, which provide most of the runtime code fix. The rest of this is adding testing and updated examples and docs. Refs: #4178 Closes: #3185
1 parent 4db0a45 commit bff2e23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1162
-317
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ updates:
4848
- "eslint*"
4949

5050
- package-ecosystem: "npm"
51-
directory: "/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp"
51+
directory: "/test/instrumentation/azure-functions/fixtures/azfunc3"
52+
schedule:
53+
interval: "weekly"
54+
open-pull-requests-limit: 5
55+
reviewers:
56+
- "elastic/apm-agent-node-js"
57+
58+
- package-ecosystem: "npm"
59+
directory: "/test/instrumentation/azure-functions/fixtures/azfunc4"
5260
schedule:
5361
interval: "weekly"
5462
open-pull-requests-limit: 5

CHANGELOG.asciidoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ See the <<upgrade-to-v4>> guide.
4141
[float]
4242
===== Features
4343
44+
* Support instrumentation of Azure Functions using the https://learn.microsoft.com/en-ca/azure/azure-functions/functions-node-upgrade-v4[v4 Node.js programming model].
45+
({pull}4426[#4426])
46+
4447
[float]
4548
===== Bug fixes
4649
4750
* Fix instrumentation of `@aws-sdk/client-s3`, `@aws-sdk/client-sqs`, and
48-
`@aws-sdk/client-sns` for versions 3.723.0 and later. (Internally the AWS SDK
49-
clients updated to `@smithy/smithy-client@4`.)
51+
`@aws-sdk/client-sns` for versions 3.723.0 and later. Internally the AWS SDK
52+
clients updated to `@smithy/smithy-client@4`. ({pull}4398[#4398])
5053
5154
[float]
5255
===== Chores

docs/azure-functions.asciidoc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ endif::[]
99

1010
=== Monitoring Node.js Azure Functions
1111

12-
The Node.js APM Agent can trace function invocations in an https://learn.microsoft.com/en-us/azure/azure-functions/[Azure Functions] app.
12+
The Node.js APM Agent can trace function invocations in an https://learn.microsoft.com/en-us/azure/azure-functions/[Azure Functions] app, using either v3 or https://learn.microsoft.com/en-us/azure/azure-functions/functions-node-upgrade-v4[v4 of the Node.js programming model].
1313

1414

1515
[float]
@@ -36,7 +36,7 @@ will result in unreasonably large deployments that will be very slow to publish
3636
and will run your Azure Function app VM out of disk space.
3737
====
3838

39-
You can also take a look at and use this https://github.com/elastic/apm-agent-nodejs/tree/main/examples/an-azure-function-app/[Azure Functions example app with Elastic APM already integrated].
39+
You can also take a look at and use this https://github.com/elastic/apm-agent-nodejs/tree/main/examples/azure-function-app/[Azure Functions example app with Elastic APM already integrated].
4040

4141
[float]
4242
[[azure-functions-setup]]
@@ -69,17 +69,14 @@ require('elastic-apm-node').start({
6969
----
7070
<1> Optional <<configuration,configuration options>> can be added here.
7171

72-
2. Add a "main" entry to your package.json pointing to the app init file.
72+
2. Change the "main" entry in your "package.json" to point to the initapm.js file.
7373
+
7474
[source,json]
7575
----
7676
...
77-
"main": "initapm.js",
77+
"main": "{initapm.js,src/functions/*.js}",
7878
...
7979
----
80-
+
81-
If your application already has a "main" init file, you can instead add the
82-
`require('elastic-apm-node').start()` to top of that file.
8380

8481

8582
[float]
@@ -103,7 +100,7 @@ For example:
103100

104101
image::./images/azure-functions-configuration.png[Configuring the APM Agent in the Azure Portal]
105102

106-
For local testing via `func start` you can set these environment variables in
103+
For local testing via `func start`, you can set these environment variables in
107104
your terminal, or in the "local.settings.json" file. See the
108105
<<configuration,agent configuration guide>> for full details on supported
109106
configuration variables.
@@ -127,13 +124,11 @@ of time, so allow a minute or so for data to appear.
127124
[[azure-functions-limitations]]
128125
==== Limitations
129126

130-
This instrumentation does not send an APM transaction or error to APM server when
131-
a handler has an `uncaughtException` or `unhandledRejection`.
132-
The Azure Functions Node.js reference https://learn.microsoft.com/en-ca/azure/azure-functions/functions-reference-node#use-async-and-await[has a section] with best practices for avoiding these cases.
127+
Distributed tracing for incoming HTTP requests to Azure Functions (using v4 of the programming model) does *not* work, because of a issue with Azure's handling of trace-context. See https://github.com/elastic/apm-agent-nodejs/pull/4426#issuecomment-2596922653[this] for details.
128+
129+
Azure Functions instrumentation currently does _not_ collect system metrics in the background because of a concern with unintentionally increasing Azure Functions costs (for Consumption plans).
133130

134-
Azure Functions instrumentation currently does _not_ collect system metrics in
135-
the background because of a concern with unintentionally increasing Azure
136-
Functions costs (for Consumption plans).
131+
Elastic APM's <<central-config,central configuration>> is not supported for Azure Functions.
137132

138133

139134
[float]

docs/supported-technologies.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ These are the frameworks that we officially support:
6363
|=======================================================================
6464
| Framework | Version | Note
6565
| <<lambda,AWS Lambda>> | N/A |
66-
| <<azure-functions,Azure Functions>> | ~4 | See https://learn.microsoft.com/en-ca/azure/azure-functions/set-runtime-version[the guide on Azure Functions runtime versions].
66+
| <<azure-functions,Azure Functions>> | v3, v4 | https://learn.microsoft.com/en-us/azure/azure-functions/functions-node-upgrade-v4[Node.js programming model v3 and v4]
6767
| <<express,Express>> | ^4.0.0 |
6868
| <<fastify,Fastify>> | >=1.0.0 | See also https://www.fastify.io/docs/latest/Reference/LTS/[Fastify's own LTS documentation]
6969
| <<hapi,@hapi/hapi>> | >=17.9.0 <22.0.0 |

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = [
3030

3131
'examples/esbuild/dist/**',
3232
'examples/typescript/dist/**',
33-
'examples/an-azure-function-app/**',
33+
'examples/azure-function-app/**',
3434
'lib/opentelemetry-bridge/opentelemetry-core-mini/**',
3535
'test/babel/out.js',
3636
'test/lambda/fixtures/esbuild-bundled-handler/hello.js',

examples/an-azure-function-app/Bye/index.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/an-azure-function-app/Hi/function.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/an-azure-function-app/Hi/index.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/an-azure-function-app/initapm.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/an-azure-function-app/package.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)