Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ if (!$SkipBuild) {
"sshdconfig",
"tools/dsctest",
"tools/test_group_resource",
"y2j"
"y2j",
"resources/repro.trace"
)
$pedantic_unclean_projects = @()
$clippy_unclean_projects = @("tree-sitter-dscexpression", "tree-sitter-ssh-server-config")
Expand Down
1 change: 1 addition & 0 deletions resources/repro.trace/copy_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./repro.trace.resource.ps1
51 changes: 51 additions & 0 deletions resources/repro.trace/repro.config.dsc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.vscode.json
resources:
- type: Dsc.Repro/Trace
name: Simple messaging
properties:
case: simpleMessage
# emittedData: # Output from repro testing
# warn: Simple message
- type: Dsc.Repro/Trace
name: Minimal struct
properties:
case: minimalStruct
# emittedData: # Output from repro testing
# timestamp: 2024-08-12T15:26:25.4477204-05:00
# level: WARN
# fields:
# message: structured trace message
- type: Dsc.Repro/Trace
name: Struct with metadata
properties:
case: structWithMetadata
# emittedData: # Output from repro testing
# timestamp: 2024-08-12T15:26:26.1439312-05:00
# level: WARN
# fields:
# message: structured trace message
# target: C:\code\powershell\working\docs\DSC\bin\debug\repro.trace.resource.ps1
- type: Dsc.Repro/Trace
name: Sruct with additional fields
properties:
case: structWithAdditionalFields
# emittedData: # Output from repro testing
# timestamp: 2024-08-12T15:26:27.1288515-05:00
# level: WARN
# fields:
# message: structured trace message
# extraInteger: 10
# extraString: additional data
- type: Dsc.Repro/Trace
name: Struct with metadata and additional fields
properties:
case: structWithMetadataAndAdditionalFields
# emittedData: # Output from repro testing
# timestamp: 2024-08-12T15:26:27.7689792-05:00
# level: WARN
# fields:
# message: structured trace message
# extraInteger: 10
# extraString: additional data
# target: C:\code\powershell\working\docs\DSC\bin\debug\repro.trace.resource.ps1
# lineNumber: 94
89 changes: 89 additions & 0 deletions resources/repro.trace/repro.config.result.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# STDERR messages START
# 2025-08-12T20:26:24.687009Z WARN PID 5020: Simple message
# 2025-08-12T20:26:25.459746Z WARN trace_message="PID 10368: structured trace message"
# 2025-08-12T20:26:26.165380Z WARN trace_message="PID 19292: structured trace message"
# 2025-08-12T20:26:27.156677Z WARN trace_message="PID 25044: structured trace message"
# 2025-08-12T20:26:27.793703Z WARN trace_message="PID 5984: structured trace message"
# STDERR messages END
metadata:
Microsoft.DSC:
version: 3.1.0
operation: get
executionType: actual
startDatetime: 2025-08-12T15:26:19.134728100-05:00
endDatetime: 2025-08-12T15:26:27.907077900-05:00
duration: PT8.7723498S
securityContext: restricted
results:
- metadata:
Microsoft.DSC:
duration: PT1.0954907S
name: Simple messaging
type: Dsc.Repro/Trace
result:
actualState:
case: simpleMessage
emittedData:
warn: Simple message
- metadata:
Microsoft.DSC:
duration: PT0.7814828S
name: Minimal struct
type: Dsc.Repro/Trace
result:
actualState:
case: minimalStruct
emittedData:
timestamp: 2024-08-12T15:26:25.4477204-05:00
level: WARN
fields:
message: structured trace message
- metadata:
Microsoft.DSC:
duration: PT0.7530085S
name: Struct with metadata
type: Dsc.Repro/Trace
result:
actualState:
case: structWithMetadata
emittedData:
timestamp: 2024-08-12T15:26:26.1439312-05:00
level: WARN
fields:
message: structured trace message
target: C:\code\powershell\working\docs\DSC\bin\debug\repro.trace.resource.ps1
lineNumber: 94
- metadata:
Microsoft.DSC:
duration: PT0.9343058S
name: Sruct with additional fields
type: Dsc.Repro/Trace
result:
actualState:
case: structWithAdditionalFields
emittedData:
timestamp: 2024-08-12T15:26:27.1288515-05:00
level: WARN
fields:
message: structured trace message
extraInteger: 10
extraString: additional data
- metadata:
Microsoft.DSC:
duration: PT0.6398828S
name: Struct with metadata and additional fields
type: Dsc.Repro/Trace
result:
actualState:
case: structWithMetadataAndAdditionalFields
emittedData:
timestamp: 2024-08-12T15:26:27.7689792-05:00
level: WARN
fields:
message: structured trace message
extraInteger: 10
extraString: additional data
target: C:\code\powershell\working\docs\DSC\bin\debug\repro.trace.resource.ps1
lineNumber: 94
messages: []
hadErrors: false
45 changes: 45 additions & 0 deletions resources/repro.trace/repro.trace.dsc.resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.vscode.json",
"type": "Dsc.Repro/Trace",
"version": "0.1.0",
"description": "Repro resource for trace messaging",
"schema": {
"embedded": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"case": {
"title": "Test case",
"description": "Defines which test case to emit messages for",
"type": "string",
"enum": [
"simpleMessage",
"minimalStruct",
"structWithMetadata",
"structWithAdditionalFields",
"structWithMetadataAndAdditionalFields"
]
},
"emittedData":{
"title": "Emitted data",
"description": "Contains the message data emitted by the resource as compressed JSON to stderr",
"type": "object",
"readOnly": true
}
}
}
},
"get": {
"executable": "pwsh",
"args": [
"-NoLogo",
"-NonInteractive",
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-Command",
"$Input | ./repro.trace.resource.ps1 Get"
],
"input": "stdin"
}
}
104 changes: 104 additions & 0 deletions resources/repro.trace/repro.trace.resource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
<#
.SYNOPSIS
Repro resource for trace messaging

.PARAMETER Operation
Operation to perform. Valid operations are:

- `Get` - return the current state of the instance.

.PARAMETER JsonInput
Configuration or resource input in JSON format.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateSet('Get')]
[string]$Operation,
[Parameter(Mandatory = $false, Position = 1, ValueFromPipeline = $true)]
[string]$jsonInput = '@{}'
)

begin {
enum TestCase {
SimpleMessage
MinimalStruct
StructWithMetadata
StructWithAdditionalFields
StructWithMetadataAndAdditionalFields
}

$script:ResourcePath = $MyInvocation.MyCommand.Path

class TraceTesting {
[TestCase] $Case
[ordered] $EmittedData

[ordered] TraceData() {
if ($null -ne $this.EmittedData) {
return $this.EmittedData
}

if ($this.Case -eq [TestCase]::SimpleMessage) {
$this.EmittedData = [ordered]@{
warn = "Simple message"
}
return $this.EmittedData
}

$date = Get-Date
$date = $date.AddYears(-1)
$this.EmittedData = [ordered]@{
timestamp = $date
level = 'WARN'
fields = [ordered]@{
message = "structured trace message"
}
}

if ($this.Case -in @([TestCase]::StructWithMetadata, [TestCase]::StructWithMetadataAndAdditionalFields)) {
$this.EmittedData.target = $script:ResourcePath
$this.EmittedData.lineNumber = 94
}
if ($this.Case -in @([TestCase]::StructWithAdditionalFields, [TestCase]::StructWithMetadataAndAdditionalFields)) {
$this.EmittedData.fields.extraInteger = 10
$this.EmittedData.fields.extraString = "additional data"
}

return $this.EmittedData
}

[string] TraceJson() {
return $this.TraceData() | ConvertTo-Json -Compress
}
[string] ToJson() {
$jsonCase = $this.Case.ToString()
$jsonCase = $jsonCase.Substring(0, 1).ToLowerInvariant() + $jsonCase.Substring(1)
return [ordered] @{
case = $jsonCase
emittedData = $this.TraceData()
} | ConvertTo-Json -Compress -Depth 99
}
static [TraceTesting] ParseJson([string]$inputJson) {
$parsed = $inputJson | ConvertFrom-Json

return [TraceTesting]@{
Case = $parsed.case
}
}
}
}

process {
[TraceTesting]$parsedInput = [TraceTesting]::ParseJson($jsonInput)
$host.ui.WriteErrorLine($parsedInput.TraceJson())

switch ($Operation) {
'Get' {
$parsedInput.ToJson()
exit 0
}
}
}
Loading
Loading