Skip to content

Commit

Permalink
refining the example; cleaning up XXXs in the instr
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Jan 16, 2025
1 parent cdbd751 commit 333062c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 44 deletions.
2 changes: 1 addition & 1 deletion examples/an-azure-function-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ APM agent. The App has a single function:
4. Call your functions:
```
curl -i https://<APP_NAME>.azurewebsites.net/api/hi
curl -i https://<APP_NAME>.azurewebsites.net/api/hello
```
The result (after a minute for data to propagate) should be a `<APP_NAME>` service
Expand Down
17 changes: 0 additions & 17 deletions examples/an-azure-function-app/src/functions/Bye.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { app } = require('@azure/functions');

app.http('Hi', {
app.http('Hello', {
methods: ['GET'],
authLevel: 'anonymous',
handler: async (request, _context) => {
handler: async (_request, _context) => {
const url = new URL('http://worldtimeapi.org/api/timezone/America/Vancouver');
const timeRes = await fetch(url);
const timeBody = await byeRes.json();
const timeRes = await fetch(url, { signal: AbortSignal.timeout(5000) });
const timeBody = await timeRes.json();

const body = JSON.stringify({
hello: 'world',
Expand Down
27 changes: 5 additions & 22 deletions lib/instrumentation/azure-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ function instrument(agent) {
}

const context = hookCtx.invocationContext;
console.log('XXX context:');
console.dir(context, { depth: 50 }); // XXX
const invocationId = context.invocationId;
log.trace({ invocationId }, 'azure-functions: preInvocation');

Expand All @@ -365,18 +363,19 @@ function instrument(agent) {
isFirstRun = false;
}

// XXX https://github.com/elastic/apm-agent-nodejs/pull/4178/files for azfunc v4
// In programming model v3 the InvocationContext includes
// `bindingDefinitions` and `executionContext`. In v4 the structure is a
// little different.
let bindingDefinitions = context.bindingDefinitions;
if (!bindingDefinitions) {
// cater for possibly v4 version of the function app
bindingDefinitions = [];
// push input bindings
// Input bindings
bindingDefinitions.push({
name: context?.options?.trigger?.name,
type: context?.options?.trigger?.type,
direction: context?.options?.trigger?.direction,
});
// push the output bindings
// Output bindings
bindingDefinitions.push(context?.options?.return);
}
let executionContext = context.executionContext;
Expand All @@ -394,22 +393,6 @@ function instrument(agent) {
));
const triggerType = funcInfo.triggerType;

// Handle trace-context.
// XXX bring back distributed tracing language.
// XXX also with v4 we don't ahve access to the request headers (context.req.headers),
// so we cannot optionally use a traceparent header there. That means
// distributed traces going through HTTP-triggered Azure Functions
// won't be connected in our waterfall because of the broken trace limitation.
// XXX Possible concerns:
// - Was `traceContext` appropriate/accurate with Azure Functions v3?
// I.e. for TRIGGER_HTTP, did it reflect an incoming traceparent header?
// - When incoming requests do *not* provide trace context, Azure Functions
// provides a traceparent. At least when running locally it always has
// the sampling flag set *false*! If this happens in a deployed function
// then that looks like no tracing at all. Do we want to call out
// `traceContinuationStrategy`?
// Trace-context.

// `InvocationContext.traceContext` is broken: it results in sampled=false
// (i.e. traces are discarded) and/or broken traces because it creates an
// internal Span ID in the trace that cannot be ingested.
Expand Down

0 comments on commit 333062c

Please sign in to comment.