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 func v4 compatibility #4178

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 32 additions & 6 deletions lib/instrumentation/azure-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,33 @@ function instrument(agent) {
isFirstRun = false;
}

let bindingDefinitions = context.bindingDefinitions;
if (!bindingDefinitions) {
// cater for possibly v4 version of the function app
bindingDefinitions = [];

// push input bindings
bindingDefinitions.push({
name: context?.options?.trigger?.name,
type: context?.options?.trigger?.type,
direction: context?.options?.trigger?.direction,
});

// push the output bindings
bindingDefinitions.push(context?.options?.return);
}

let executionContext = context.executionContext;
if (!executionContext) {
executionContext = {
functionDirectory: '',
functionName: context.functionName,
};
}

const funcInfo = (hookCtx.hookData.funcInfo = new FunctionInfo(
context.bindingDefinitions,
context.executionContext,
bindingDefinitions,
executionContext,
log,
));
const triggerType = funcInfo.triggerType;
Expand All @@ -380,13 +404,15 @@ function instrument(agent) {
if (triggerType === TRIGGER_HTTP && context.req && context.req.headers) {
traceparent =
context.req.headers.traceparent ||
context.req.headers['elastic-apm-traceparent'];
tracestate = context.req.headers.tracestate;
context.req.headers['elastic-apm-traceparent'] ||
context.traceContext.traceParent;
tracestate = context.req.headers.tracestate ||
context.traceContext.traceState;
}

const trans = (hookCtx.hookData.trans = ins.startTransaction(
// This is the default name. Trigger-specific values are added below.
context.executionContext.functionName,
executionContext.functionName,
TRANS_TYPE_FROM_TRIGGER_TYPE[triggerType],
{
childOf: traceparent,
Expand All @@ -399,7 +425,7 @@ function instrument(agent) {
const accountId = getAzureAccountId();
const resourceGroup = process.env.WEBSITE_RESOURCE_GROUP;
const fnAppName = process.env.WEBSITE_SITE_NAME;
const fnName = context.executionContext.functionName;
const fnName = executionContext.functionName;
const faasData = {
trigger: {
type: FAAS_TRIGGER_TYPE_FROM_TRIGGER_TYPE[triggerType],
Expand Down