Skip to content

Commit 73b9343

Browse files
committed
add claude response
1 parent 40e4b0f commit 73b9343

2 files changed

Lines changed: 107 additions & 64 deletions

File tree

.github/workflows/build-deploy.yml

Lines changed: 94 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -129,47 +129,62 @@ jobs:
129129
- name: Publish application
130130
run: dotnet publish src/MyBlog.Web/MyBlog.Web.csproj -c Release -o ./publish -r win-x86 --self-contained false
131131

132-
- name: Inject OTLP environment variables into web.config
132+
- name: Inject OTLP configuration into web.config
133133
shell: pwsh
134134
env:
135135
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
136136
OTLP_ENDPOINT: ${{ secrets.OTLP_ENDPOINT }}
137137
run: |
138138
$webConfigPath = "./publish/web.config"
139-
if (Test-Path $webConfigPath) {
140-
[xml]$xml = Get-Content $webConfigPath
141-
$aspNetCore = $xml.configuration.'system.webServer'.aspNetCore
142-
143-
# Create or get environmentVariables element
144-
$envVars = $aspNetCore.SelectSingleNode('environmentVariables')
145-
if (-not $envVars) {
146-
$envVars = $xml.CreateElement('environmentVariables')
147-
$aspNetCore.AppendChild($envVars) | Out-Null
148-
}
149-
150-
# Add OTLP API key if configured
151-
if (-not [string]::IsNullOrWhiteSpace($env:HONEYCOMB_API_KEY)) {
152-
$envVar = $xml.CreateElement('environmentVariable')
153-
$envVar.SetAttribute('name', 'Otlp__ApiKey')
154-
$envVar.SetAttribute('value', $env:HONEYCOMB_API_KEY)
155-
$envVars.AppendChild($envVar) | Out-Null
156-
Write-Host "Added Otlp__ApiKey to web.config"
157-
}
158-
159-
# Add OTLP endpoint (default to Honeycomb US if not specified)
160-
$endpoint = if (-not [string]::IsNullOrWhiteSpace($env:OTLP_ENDPOINT)) { $env:OTLP_ENDPOINT } else { "https://api.honeycomb.io" }
161-
$envVar2 = $xml.CreateElement('environmentVariable')
162-
$envVar2.SetAttribute('name', 'Otlp__Endpoint')
163-
$envVar2.SetAttribute('value', $endpoint)
164-
$envVars.AppendChild($envVar2) | Out-Null
165-
Write-Host "Added Otlp__Endpoint=$endpoint to web.config"
166-
167-
$xml.Save($webConfigPath)
168-
Write-Host "web.config updated successfully"
139+
if (-not (Test-Path $webConfigPath)) {
140+
Write-Host "web.config not found at $webConfigPath — skipping OTLP injection"
141+
exit 0
142+
}
143+
144+
Write-Host "=== Current web.config ==="
145+
Get-Content $webConfigPath
146+
Write-Host "==========================="
147+
148+
[xml]$xml = Get-Content $webConfigPath
149+
150+
# Navigate to the aspNetCore element using XPath to handle any structure
151+
$aspNetCore = $xml.SelectSingleNode('//aspNetCore')
152+
if (-not $aspNetCore) {
153+
Write-Host "No aspNetCore element found in web.config — skipping OTLP injection"
154+
exit 0
155+
}
156+
157+
# Create or get environmentVariables element
158+
$envVars = $aspNetCore.SelectSingleNode('environmentVariables')
159+
if (-not $envVars) {
160+
$envVars = $xml.CreateElement('environmentVariables')
161+
$aspNetCore.AppendChild($envVars) | Out-Null
162+
}
163+
164+
# Add OTLP API key if configured
165+
if (-not [string]::IsNullOrWhiteSpace($env:HONEYCOMB_API_KEY)) {
166+
$envVar = $xml.CreateElement('environmentVariable')
167+
$envVar.SetAttribute('name', 'Otlp__ApiKey')
168+
$envVar.SetAttribute('value', $env:HONEYCOMB_API_KEY)
169+
$envVars.AppendChild($envVar) | Out-Null
170+
Write-Host "Added Otlp__ApiKey to web.config"
169171
} else {
170-
Write-Host "web.config not found at $webConfigPath"
172+
Write-Host "No HONEYCOMB_API_KEY secret configured — OTLP export will be disabled"
171173
}
172174
175+
# Add OTLP endpoint (default to Honeycomb US if secret not specified)
176+
$endpoint = if (-not [string]::IsNullOrWhiteSpace($env:OTLP_ENDPOINT)) { $env:OTLP_ENDPOINT } else { "https://api.honeycomb.io" }
177+
$envVar2 = $xml.CreateElement('environmentVariable')
178+
$envVar2.SetAttribute('name', 'Otlp__Endpoint')
179+
$envVar2.SetAttribute('value', $endpoint)
180+
$envVars.AppendChild($envVar2) | Out-Null
181+
Write-Host "Added Otlp__Endpoint=$endpoint to web.config"
182+
183+
$xml.Save((Resolve-Path $webConfigPath).Path)
184+
Write-Host "=== Updated web.config ==="
185+
Get-Content $webConfigPath
186+
Write-Host "==========================="
187+
173188
- name: Deploy via WebDeploy
174189
shell: pwsh
175190
env:
@@ -223,47 +238,62 @@ jobs:
223238
- name: Publish application
224239
run: dotnet publish src/MyBlog.Web/MyBlog.Web.csproj -c Release -o ./publish -r win-x86 --self-contained false
225240

226-
- name: Inject OTLP environment variables into web.config
241+
- name: Inject OTLP configuration into web.config
227242
shell: pwsh
228243
env:
229244
HONEYCOMB_API_KEY: ${{ secrets.NICE_HONEYCOMB_API_KEY }}
230245
OTLP_ENDPOINT: ${{ secrets.NICE_OTLP_ENDPOINT }}
231246
run: |
232247
$webConfigPath = "./publish/web.config"
233-
if (Test-Path $webConfigPath) {
234-
[xml]$xml = Get-Content $webConfigPath
235-
$aspNetCore = $xml.configuration.'system.webServer'.aspNetCore
236-
237-
# Create or get environmentVariables element
238-
$envVars = $aspNetCore.SelectSingleNode('environmentVariables')
239-
if (-not $envVars) {
240-
$envVars = $xml.CreateElement('environmentVariables')
241-
$aspNetCore.AppendChild($envVars) | Out-Null
242-
}
243-
244-
# Add OTLP API key if configured
245-
if (-not [string]::IsNullOrWhiteSpace($env:HONEYCOMB_API_KEY)) {
246-
$envVar = $xml.CreateElement('environmentVariable')
247-
$envVar.SetAttribute('name', 'Otlp__ApiKey')
248-
$envVar.SetAttribute('value', $env:HONEYCOMB_API_KEY)
249-
$envVars.AppendChild($envVar) | Out-Null
250-
Write-Host "Added Otlp__ApiKey to web.config"
251-
}
252-
253-
# Add OTLP endpoint (default to Honeycomb US if not specified)
254-
$endpoint = if (-not [string]::IsNullOrWhiteSpace($env:OTLP_ENDPOINT)) { $env:OTLP_ENDPOINT } else { "https://api.honeycomb.io" }
255-
$envVar2 = $xml.CreateElement('environmentVariable')
256-
$envVar2.SetAttribute('name', 'Otlp__Endpoint')
257-
$envVar2.SetAttribute('value', $endpoint)
258-
$envVars.AppendChild($envVar2) | Out-Null
259-
Write-Host "Added Otlp__Endpoint=$endpoint to web.config"
260-
261-
$xml.Save($webConfigPath)
262-
Write-Host "web.config updated successfully"
248+
if (-not (Test-Path $webConfigPath)) {
249+
Write-Host "web.config not found at $webConfigPath — skipping OTLP injection"
250+
exit 0
251+
}
252+
253+
Write-Host "=== Current web.config ==="
254+
Get-Content $webConfigPath
255+
Write-Host "==========================="
256+
257+
[xml]$xml = Get-Content $webConfigPath
258+
259+
# Navigate to the aspNetCore element using XPath to handle any structure
260+
$aspNetCore = $xml.SelectSingleNode('//aspNetCore')
261+
if (-not $aspNetCore) {
262+
Write-Host "No aspNetCore element found in web.config — skipping OTLP injection"
263+
exit 0
264+
}
265+
266+
# Create or get environmentVariables element
267+
$envVars = $aspNetCore.SelectSingleNode('environmentVariables')
268+
if (-not $envVars) {
269+
$envVars = $xml.CreateElement('environmentVariables')
270+
$aspNetCore.AppendChild($envVars) | Out-Null
271+
}
272+
273+
# Add OTLP API key if configured
274+
if (-not [string]::IsNullOrWhiteSpace($env:HONEYCOMB_API_KEY)) {
275+
$envVar = $xml.CreateElement('environmentVariable')
276+
$envVar.SetAttribute('name', 'Otlp__ApiKey')
277+
$envVar.SetAttribute('value', $env:HONEYCOMB_API_KEY)
278+
$envVars.AppendChild($envVar) | Out-Null
279+
Write-Host "Added Otlp__ApiKey to web.config"
263280
} else {
264-
Write-Host "web.config not found at $webConfigPath"
281+
Write-Host "No NICE_HONEYCOMB_API_KEY secret configured — OTLP export will be disabled"
265282
}
266283
284+
# Add OTLP endpoint (default to Honeycomb US if secret not specified)
285+
$endpoint = if (-not [string]::IsNullOrWhiteSpace($env:OTLP_ENDPOINT)) { $env:OTLP_ENDPOINT } else { "https://api.honeycomb.io" }
286+
$envVar2 = $xml.CreateElement('environmentVariable')
287+
$envVar2.SetAttribute('name', 'Otlp__Endpoint')
288+
$envVar2.SetAttribute('value', $endpoint)
289+
$envVars.AppendChild($envVar2) | Out-Null
290+
Write-Host "Added Otlp__Endpoint=$endpoint to web.config"
291+
292+
$xml.Save((Resolve-Path $webConfigPath).Path)
293+
Write-Host "=== Updated web.config ==="
294+
Get-Content $webConfigPath
295+
Write-Host "==========================="
296+
267297
- name: Deploy via WebDeploy
268298
shell: pwsh
269299
env:

docs/llm/claude.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,16 @@ Error: Process completed with exit code 1.
818818

819819

820820

821+
The `aspNetCore` element isn't being found because the XML path is wrong. The ASP.NET Core `web.config` uses a namespace or the structure is slightly different. Let me check what `dotnet publish` actually generates for the `web.config`.
822+
823+
The issue is that `dotnet publish` with `-r win-x86 --self-contained false` generates a `web.config` where the `aspNetCore` element path might differ, or more likely, the `system.webServer` node lookup is failing because PowerShell's XML dot-notation is picky.
824+
825+
Let me fix the script to be more robust — it'll dump the actual web.config content first so we can see the structure, and use XPath properly:The fix: the old script used `$xml.configuration.'system.webServer'.aspNetCore` which is PowerShell dot-notation navigating through XML. The problem is `system.webServer` contains a dot, which confuses PowerShell's property resolution — it was returning `$null` for `aspNetCore`, and then the `.SelectSingleNode()` call on `$null` blew up.
826+
827+
The new script uses `$xml.SelectSingleNode('//aspNetCore')` instead — XPath with `//` finds the `aspNetCore` element anywhere in the document regardless of the parent element naming. This is robust against any `web.config` structure.
828+
829+
I also added diagnostic output (prints the web.config before and after modification) so if anything goes wrong on the next run you'll see exactly what the file looks like, and added graceful early exits instead of crashing if the file or element isn't found.
830+
831+
13
832+
14
833+

0 commit comments

Comments
 (0)