Skip to content

Commit

Permalink
chore: Update Azure Site Extension to include support for Azure Funct…
Browse files Browse the repository at this point in the history
…ions (#2976)
  • Loading branch information
tippmar-nr authored Jan 31, 2025
1 parent f7987c5 commit c726fba
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ build/Linux/keys
# Container Integration Tests
/tests/Agent/IntegrationTests/LocalStack/volume
/tests/Agent/IntegrationTests/ContainerApplications/volume/cache

# Build artifacts
/build/BuildArtifacts
/build/_staging
68 changes: 57 additions & 11 deletions build/Packaging/AzureSiteExtension/Content/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,52 @@ function InstallNewAgent($newRelicNugetContentPath, $newRelicInstallPath, $newRe

function RemoveXmlElements($file, $xPaths)
{
$xdoc = new-object System.Xml.XmlDocument
$xdoc.load($file)
foreach ($xPath in $xPaths)
{
$elementToBeRemoved = $xdoc.SelectSingleNode($xPath)
if($elementToBeRemoved -ne $null)
{
$elementToBeRemoved.ParentNode.RemoveChild($elementToBeRemoved)
}
}
$xdoc.Save($file)
$xdoc = new-object System.Xml.XmlDocument
$xdoc.load($file)
$namespaceManager = new-object System.Xml.XmlNamespaceManager($xdoc.NameTable)
$namespaceManager.AddNamespace("xdt", "http://schemas.microsoft.com/XML-Document-Transform")

foreach ($xPath in $xPaths)
{
$node = $xdoc.SelectSingleNode($xPath, $namespaceManager)
if ($node -ne $null)
{
$node.ParentNode.RemoveChild($node)
}
}
$xdoc.Save($file)
}

function AddXmlElements($file, $xPaths)
{
$xdoc = new-object System.Xml.XmlDocument
$xdoc.load($file)
$namespaceManager = new-object System.Xml.XmlNamespaceManager($xdoc.NameTable)
$namespaceManager.AddNamespace("xdt", "http://schemas.microsoft.com/XML-Document-Transform")

foreach ($xPath in $xPaths)
{
$newElement = $xdoc.CreateElement($xPath.Name)
foreach ($attribute in $xPath.Attributes.GetEnumerator())
{
if ($attribute.Key -like "xdt:*")
{
$newAttribute = $xdoc.CreateAttribute($attribute.Key, $namespaceManager.LookupNamespace("xdt"))
}
else
{
$newAttribute = $xdoc.CreateAttribute($attribute.Key)
}
$newAttribute.Value = $attribute.Value
$newElement.Attributes.Append($newAttribute)
}
$parentNode = $xdoc.SelectSingleNode($xPath.ParentPath, $namespaceManager)
if ($parentNode -ne $null)
{
$parentNode.AppendChild($newElement)
}
}
$xdoc.Save($file)
}

function CopyAgentInfo($agentInfoDestination)
Expand Down Expand Up @@ -342,6 +377,17 @@ try
RemoveXmlElements $file $xPaths
}

if ($env:FUNCTIONS_WORKER_RUNTIME -ne $null) # for Azure Functions, enable azure function mode and remove <system.applicationHost>
{
$xPaths = @(
@{ Name = "add"; Attributes = @{ name = "NEW_RELIC_AZURE_FUNCTION_MODE_ENABLED"; value = "1"; "xdt:Locator" = "Match(name)"; "xdt:Transform" = "InsertIfMissing" }; ParentPath = "/configuration/system.webServer/runtime/environmentVariables" },
@{ Name = "add"; Attributes = @{ name = "NEW_RELIC_LOG_DIRECTORY"; value = "%HOME%\LogFiles\NewRelic"; "xdt:Locator" = "Match(name)"; "xdt:Transform" = "InsertIfMissing" }; ParentPath = "/configuration/system.webServer/runtime/environmentVariables" }
)
$file = resolve-path ".\applicationHost.xdt"
WriteToInstallLog "Adding Azure Functions environment variables to applicationHost.xdt"
AddXmlElements $file $xPaths
}

$packageNames = @($nugetPackageForFrameworkApp, $nugetPackageForCoreApp)
$stagingFolders = @("NewRelicPackage", "NewRelicCorePackage")
$newRelicInstallPaths = @("$env:HOME\NewRelicAgent\Framework", "$env:HOME\NewRelicAgent\Core")
Expand Down

0 comments on commit c726fba

Please sign in to comment.