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.
  • Loading branch information
tippmar-nr committed Jan 31, 2025
1 parent 80d4c76 commit 11e9504
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 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
71 changes: 59 additions & 12 deletions build/Packaging/AzureSiteExtension/Content/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,51 @@ function InstallNewAgent($newRelicNugetContentPath, $newRelicInstallPath, $newRe
}
}

function RemoveXmlElements($file, $xPaths)
function RemoveXmlElement($file, $xPath)
{
$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")

$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 +374,21 @@ 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

WriteToInstallLog "Removing <system.applicationHost> element from applicationHost.xdt"
RemoveXmlElement $file "/configuration/system.applicationHost"
}


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

0 comments on commit 11e9504

Please sign in to comment.