-
Notifications
You must be signed in to change notification settings - Fork 233
feat: Azure Functions #3071
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
Merged
Merged
feat: Azure Functions #3071
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
338b9a5
feat: Azure Functions
trentm 97f0040
ritm and azure-functions-nodejs-worker module instr to get first basi…
trentm 7535675
fix 'npm run test:deps'
trentm f79ed79
Merge branch 'main' into trentm/azure-functions
trentm a7ac8f9
fix config.test.js doing the usual thing
trentm 48b675a
a working test suite (more tests to add) and producing all the spec'd…
trentm 183b129
forgot to add the main test file
trentm 7cc9998
does this work for 'npm install' in CI?
trentm bf74e47
addition proposed metadata fields
trentm 03024b0
update package-lock file
trentm d20d754
try this instead to get CI to be able to npm install
trentm ea32c84
correct serviceName validation: only if got a value from the special …
trentm 0ef7fcf
update to a release (11.1.0) of the apm-http-client
trentm 3121935
test case for handler that throws; add http response context and resu…
trentm d5e8191
config.test penance for the other patched module
trentm ca7255d
only run AF tests with node >=14 <20
trentm 198c3ba
test cases for all the supported ways to get the HTTP response data f…
trentm db1c39e
more tests; skip out with node v19 because current *release* version …
trentm c0c2d09
impl of reading 'route' from function.json lazily, and 'METHOD ROUTE'…
trentm 8727d62
bump the 'func start' timeout to 60s for possibly slow CI (though I'm…
trentm 09b4f11
a shot in the dark that func.cmd might work on Windows
trentm 1d3d561
drop 'func start' timeout back to 30s; fix a node v18 locahost ambigu…
trentm 4e46b37
plat indep path for Windows tests (and some XXX-cleanup)
trentm c71cabf
formatForTComment improvement for Windows; extend 'func start' startu…
trentm 71e7fbb
trace-context propagation for HTTP-triggered Azure Functions
trentm d01c29d
per recent spec discussion, get and add the routePrefix to the trans.…
trentm f27e901
drop debugging print
trentm 600e33b
fix edge cases with custom 'routePrefix' values
trentm 988eac2
add support for separate trigger types; add TRIGGER_TIMER (only diffe…
trentm 0bc509c
fix test
trentm 4413317
fix findPkgInfo fallback to cwd; explicitly don't infer service.versi…
trentm 8534c2a
changes to avoid the 'lose instrumentation on cycling of worker proce…
trentm 17424c7
move azure-functions test code out of the 'modules/' subdir to match …
trentm b2d11c7
don't need .vscode files in test fixtures
trentm 424bb58
add an-azure-funcction-app example for users/demos/dev
trentm 399bfa5
reduce the RITM vendoring to just the part we need; I'll follow-up se…
trentm 3d60a37
fix make check
trentm 0e9a345
no longer need this passed through now that we are using the newer in…
trentm 3736b0c
add a log.warn for, and explicitly ignore, `serviceNodeName` usage in…
trentm 21c6b74
add a nice-to-have local setting for the example azure fn app to mimi…
trentm 02157be
clearing out XXXs
trentm fac5c6f
simplify and cleanup the block for turning on AF instr; share a test …
trentm d436227
docs and changelog
trentm c88326d
Merge branch 'main' into trentm/azure-functions
trentm 1643767
fix mismerge of changelog
trentm 1e1e670
correct this import path
trentm c118aab
improve language
trentm 6f3d663
rm errant paren
trentm b7a5697
docs: correct which step these are from
trentm e0f3a15
add missing spec'd metadata.cloud. values; more defensive handling of…
trentm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.