Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
338b9a5
feat: Azure Functions
trentm Dec 9, 2022
97f0040
ritm and azure-functions-nodejs-worker module instr to get first basi…
trentm Dec 13, 2022
7535675
fix 'npm run test:deps'
trentm Dec 13, 2022
f79ed79
Merge branch 'main' into trentm/azure-functions
trentm Dec 13, 2022
a7ac8f9
fix config.test.js doing the usual thing
trentm Dec 13, 2022
48b675a
a working test suite (more tests to add) and producing all the spec'd…
trentm Dec 15, 2022
183b129
forgot to add the main test file
trentm Dec 15, 2022
7cc9998
does this work for 'npm install' in CI?
trentm Dec 15, 2022
bf74e47
addition proposed metadata fields
trentm Dec 15, 2022
03024b0
update package-lock file
trentm Dec 15, 2022
d20d754
try this instead to get CI to be able to npm install
trentm Dec 15, 2022
ea32c84
correct serviceName validation: only if got a value from the special …
trentm Dec 15, 2022
0ef7fcf
update to a release (11.1.0) of the apm-http-client
trentm Dec 16, 2022
3121935
test case for handler that throws; add http response context and resu…
trentm Dec 16, 2022
d5e8191
config.test penance for the other patched module
trentm Dec 16, 2022
ca7255d
only run AF tests with node >=14 <20
trentm Dec 17, 2022
198c3ba
test cases for all the supported ways to get the HTTP response data f…
trentm Dec 17, 2022
db1c39e
more tests; skip out with node v19 because current *release* version …
trentm Dec 17, 2022
c0c2d09
impl of reading 'route' from function.json lazily, and 'METHOD ROUTE'…
trentm Dec 20, 2022
8727d62
bump the 'func start' timeout to 60s for possibly slow CI (though I'm…
trentm Dec 20, 2022
09b4f11
a shot in the dark that func.cmd might work on Windows
trentm Dec 20, 2022
1d3d561
drop 'func start' timeout back to 30s; fix a node v18 locahost ambigu…
trentm Dec 20, 2022
4e46b37
plat indep path for Windows tests (and some XXX-cleanup)
trentm Dec 20, 2022
c71cabf
formatForTComment improvement for Windows; extend 'func start' startu…
trentm Dec 20, 2022
71e7fbb
trace-context propagation for HTTP-triggered Azure Functions
trentm Dec 20, 2022
d01c29d
per recent spec discussion, get and add the routePrefix to the trans.…
trentm Dec 22, 2022
f27e901
drop debugging print
trentm Dec 22, 2022
600e33b
fix edge cases with custom 'routePrefix' values
trentm Jan 3, 2023
988eac2
add support for separate trigger types; add TRIGGER_TIMER (only diffe…
trentm Jan 4, 2023
0bc509c
fix test
trentm Jan 4, 2023
4413317
fix findPkgInfo fallback to cwd; explicitly don't infer service.versi…
trentm Jan 5, 2023
8534c2a
changes to avoid the 'lose instrumentation on cycling of worker proce…
trentm Jan 10, 2023
17424c7
move azure-functions test code out of the 'modules/' subdir to match …
trentm Jan 10, 2023
b2d11c7
don't need .vscode files in test fixtures
trentm Jan 10, 2023
424bb58
add an-azure-funcction-app example for users/demos/dev
trentm Jan 11, 2023
399bfa5
reduce the RITM vendoring to just the part we need; I'll follow-up se…
trentm Jan 12, 2023
3d60a37
fix make check
trentm Jan 12, 2023
0e9a345
no longer need this passed through now that we are using the newer in…
trentm Jan 12, 2023
3736b0c
add a log.warn for, and explicitly ignore, `serviceNodeName` usage in…
trentm Jan 12, 2023
21c6b74
add a nice-to-have local setting for the example azure fn app to mimi…
trentm Jan 12, 2023
02157be
clearing out XXXs
trentm Jan 12, 2023
fac5c6f
simplify and cleanup the block for turning on AF instr; share a test …
trentm Jan 12, 2023
d436227
docs and changelog
trentm Jan 12, 2023
c88326d
Merge branch 'main' into trentm/azure-functions
trentm Jan 12, 2023
1643767
fix mismerge of changelog
trentm Jan 12, 2023
1e1e670
correct this import path
trentm Jan 12, 2023
c118aab
improve language
trentm Jan 13, 2023
6f3d663
rm errant paren
trentm Jan 13, 2023
b7a5697
docs: correct which step these are from
trentm Jan 13, 2023
e0f3a15
add missing spec'd metadata.cloud. values; more defensive handling of…
trentm Jan 16, 2023
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"/examples/esbuild/dist",
"/examples/typescript/dist",
"/examples/nextjs",
"/examples/an-azure-function-app",
"/lib/opentelemetry-bridge/opentelemetry-core-mini",
"/test/babel/out.js",
"/test/lambda/fixtures/esbuild-bundled-handler/hello.js",
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ Notes:
=== Node.js Agent version 3.x


==== Unreleased

[float]
===== Breaking changes

[float]
===== Features

* Support for tracing/monitoring https://learn.microsoft.com/en-us/azure/azure-functions/[Azure Functions].
See the <<azure-functions>> document.
({pull}3071[#3071], https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-azure-functions.md[spec])

[float]
===== Bug fixes

[float]
===== Chores


[[release-notes-3.41.1]]
==== 3.41.1 2022/12/21

Expand Down
34 changes: 34 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,37 @@ The above copyright notice and this permission notice shall be included in all c

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```


## require-in-the-middle

- **path:** [lib/ritm.js](lib/ritm.js)
- **author:** Thomas Watson Steen
- **project url:** https://github.com/elastic/require-in-the-middle
- **original file:** https://github.com/elastic/require-in-the-middle/blob/v5.2.0/index.js
- **license:** MIT License (MIT), http://opensource.org/licenses/MIT

```
The MIT License (MIT)

Copyright (c) 2016-2019 Thomas Watson Steen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

155 changes: 155 additions & 0 deletions docs/azure-functions.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
:framework: Azure Functions

[[azure-functions]]

ifdef::env-github[]
NOTE: For the best reading experience,
please view this documentation at https://www.elastic.co/guide/en/apm/agent/nodejs/current/azure-functions.html[elastic.co]
endif::[]

=== Monitoring Node.js Azure Functions

The Node.js APM Agent can trace function invocations in an https://learn.microsoft.com/en-us/azure/azure-functions/[Azure Functions] app.


[float]
[[azure-functions-prerequisites]]
==== Prerequisites

You need an APM Server to send APM data to. Follow the
{apm-guide-ref}/apm-quick-start.html[APM Quick start] if you have not set one up
yet. You will need your *APM server URL* and an APM server *secret token* (or
*API key*) for configuring the APM agent below.

You will also need an Azure Function app to monitor. If you do not have an
existing one, you can follow https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-node#create-supporting-azure-resources-for-your-function[this Azure guide]
to create one.

[IMPORTANT]
====
If you use `func init --javascript ...` as suggested in this Azure guide,
then it is recommended that you *uninstall* the `azure-functions-core-tools`
dependency by running `npm uninstall azure-functions-core-tools` and
https://github.com/Azure/azure-functions-core-tools#installing[install it separately].
Having `azure-functions-core-tools` as a "devDependency" in your package.json
will result in unreasonably large deployments that will be very slow to publish
and will run your Azure Function app VM out of disk space.
====

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].

[float]
[[azure-functions-setup]]
==== Step 1: Add the APM agent dependency

Add the `elastic-apm-node` module as a dependency of your application:

[source,bash]
----
npm install elastic-apm-node --save # or 'yarn add elastic-apm-node'
----


[float]
==== Step 2: Start the APM agent

For the APM agent to instrument Azure Functions, it needs to be started when the
Azure host starts its Node.js worker processes. The best way to do so is by
using an app-level entry point (support for this was added for Node.js Azure
Functions https://github.com/Azure/azure-functions-nodejs-worker/issues/537[here]).

1. Create a module to start the APM agent. For example, a file at the root of your repository named "initapm.js":
+
[source,javascript]
----
// initapm.js
require('elastic-apm-node').start({
<1>
})
----
<1> Optional <<configuration,configuration options>> can be added here.

2. Add a "main" entry to your package.json pointing to the app init file.
+
[source,json]
----
...
"main": "initapm.js",
...
----
+
If your application already has a "main" init file, you can instead add the
`require('elastic-apm-node').start()` to top of that file.


[float]
==== Step 3: Configure the APM agent

The APM agent can be <<configuring-the-agent,configured>> with options to the
`.start()` method or with environment variables. Using environment variables
allows one to use https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#settings[application settings in the Azure Portal] which allows hiding values and updating settings
without needing to re-deploy code.

Open _Configuration > Application settings_ for your Function App in the Azure Portal
and set:

[source,yaml]
----
ELASTIC_APM_SERVER_URL: <your APM server URL from the prerequisites step>
ELASTIC_APM_SECRET_TOKEN: <your APM secret token from the prerequisites step>
----

For example:

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

For local testing via `func start` you can set these environment variables in
your terminal, or in the "local.settings.json" file. See the
<<configuration,agent configuration guide>> for full details on supported
configuration variables.


[float]
==== Step 4: (Re-)deploy your Azure Function app

[source,bash]
----
func azure functionapp publish <APP_NAME>
----

Now, when you invoke your Azure Functions, you should see your application
show up as a Service in the APM app in Kibana and see APM transactions for
function invocations. Tracing data is forwarded to APM server after a period
of time, so allow a minute or so for data to appear.


[float]
[[azure-functions-limitations]]
==== Limitations

This instrumentation does not send an APM transaction or error to APM server when
a handler has an `uncaughtException` or `unhandledRejection`.
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.

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).


[float]
[[azure-functions-filter-sensitive-information]]
==== Filter sensitive information

include::./shared-set-up.asciidoc[tag=filter-sensitive-info]

[float]
[[azure-functions-compatibility]]
==== Compatibility

include::./shared-set-up.asciidoc[tag=compatibility-link]

[float]
[[azure-functions-troubleshooting]]
==== Troubleshooting

include::./shared-set-up.asciidoc[tag=troubleshooting-link]
Binary file added docs/images/azure-functions-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/set-up.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ To get you off the ground, we've prepared guides for setting up the Agent with a
// Updates made here will be applied elsewhere as well.
// tag::web-frameworks-list[]
* <<lambda>>
* <<azure-functions>>
* <<express>>
* <<fastify>>
* <<hapi>>
* <<koa>>
* <<nextjs>>
* <<restify>>
* <<typescript>>
* <<nextjs>>
// end::web-frameworks-list[]

Alternatively, you can <<custom-stack>>.
Expand All @@ -30,6 +30,8 @@ Other useful documentation includes:

include::./lambda.asciidoc[]

include::./azure-functions.asciidoc[]

include::./express.asciidoc[]

include::./fastify.asciidoc[]
Expand Down
1 change: 1 addition & 0 deletions docs/supported-technologies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ These are the frameworks that we officially support:
|=======================================================================
| Framework | Version | Note
| <<lambda,AWS Lambda>> | N/A |
| <<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].
| <<express,Express>> | ^4.0.0 |
| <<fastify,Fastify>> | >=1.0.0 | See also https://www.fastify.io/docs/latest/Reference/LTS/[Fastify's own LTS documentation]
| <<hapi,@hapi/hapi>> | >=17.9.0 <22.0.0 |
Expand Down
49 changes: 49 additions & 0 deletions examples/an-azure-function-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.vscode/

bin
obj
csx
.vs
edge
Publish

*.user
*.suo
*.cscfg
*.Cache
project.lock.json

/packages
/TestResults

/tools/NuGet.exe
/App_Data
/secrets
/data
.secrets
appsettings.json

node_modules
dist

# Local python packages
.python_packages/

# Python Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
1 change: 1 addition & 0 deletions examples/an-azure-function-app/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
19 changes: 19 additions & 0 deletions examples/an-azure-function-app/Bye/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "Anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
11 changes: 11 additions & 0 deletions examples/an-azure-function-app/Bye/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = async function (context, _req) {
const body = JSON.stringify({ good: 'bye' })
context.res = {
status: 200,
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body)
},
body
}
}
19 changes: 19 additions & 0 deletions examples/an-azure-function-app/Hi/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "Anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
28 changes: 28 additions & 0 deletions examples/an-azure-function-app/Hi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const http = require('http')
const https = require('https')

module.exports = async function (context, req) {
return new Promise((resolve, reject) => {
// Call the 'Bye' Function in this same Function App...
const url = new URL(req.url)
url.pathname = '/api/Bye'
const proto = (url.protocol === 'https:' ? https : http)
proto.get(url, res => {
res.resume()
res.on('error', reject)
res.on('end', () => {
// ... then respond.
const body = JSON.stringify({ hi: 'there' })
context.res = {
status: 200,
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body)
},
body
}
resolve()
})
})
})
}
Loading