Skip to content
27 changes: 27 additions & 0 deletions .chloggen/azure-logs-fix-resource-attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix empty resource attributes in the azure logs translator

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [39571]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
11 changes: 6 additions & 5 deletions pkg/translator/azurelogs/property_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const (
categoryFrontdoorWebApplicationFirewallLog = "FrontdoorWebApplicationFirewallLog"
categoryAppServiceAppLogs = "AppServiceAppLogs"
categoryAppServiceAuditLogs = "AppServiceAuditLogs"
categoryAppServiceAuthenticationLogs = "AppServiceAuthenticationLogs"
categoryAppServiceConsoleLogs = "AppServiceConsoleLogs"
categoryAppServiceHTTPLogs = "AppServiceHTTPLogs"
categoryAppServiceIPSecAuditLogs = "AppServiceIPSecAuditLogs"
categoryAppServicePlatformLogs = "AppServicePlatformLogs"
// TODO Add log and expected file to the unit tests for authentication logs
categoryAppServiceAuthenticationLogs = "AppServiceAuthenticationLogs"
categoryAppServiceConsoleLogs = "AppServiceConsoleLogs"
categoryAppServiceHTTPLogs = "AppServiceHTTPLogs"
categoryAppServiceIPSecAuditLogs = "AppServiceIPSecAuditLogs"
categoryAppServicePlatformLogs = "AppServicePlatformLogs"
)

func handleAzureCDNAccessLog(field string, value any, attrs map[string]any, attrsProps map[string]any) {
Expand Down
13 changes: 4 additions & 9 deletions pkg/translator/azurelogs/resourcelogs_to_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ const (
// Constants for OpenTelemetry Specs
scopeName = "otelcol/azureresourcelogs"

// Constants for Azure Log Record Attributes
// TODO: Remove once these are available in semconv
eventNameValue = "az.resource.log"

// Constants for Azure Log Record body fields
azureCategory = "category"
azureCorrelationID = "correlation.id"
Expand Down Expand Up @@ -114,18 +110,17 @@ func (r ResourceLogsUnmarshaler) UnmarshalLogs(buf []byte) (plog.Logs, error) {
lr.SetSeverityText(log.Level.String())
}

lr.Attributes().PutStr(conventions.AttributeCloudResourceID, log.ResourceID)
lr.Attributes().PutStr(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAzure)
lr.Attributes().PutStr(conventions.AttributeEventName, eventNameValue)

if err := lr.Body().FromRaw(extractRawAttributes(log)); err != nil {
return plog.Logs{}, err
}
}

l := plog.NewLogs()
for _, scopeLogs := range allResourceScopeLogs {
for resourceID, scopeLogs := range allResourceScopeLogs {
rl := l.ResourceLogs().AppendEmpty()
rl.Resource().Attributes().PutStr(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAzure)
rl.Resource().Attributes().PutStr(conventions.AttributeCloudResourceID, resourceID)
rl.Resource().Attributes().PutStr(conventions.AttributeEventName, "az.resource.log")
scopeLogs.MoveTo(rl.ScopeLogs().AppendEmpty())
}

Expand Down
12 changes: 5 additions & 7 deletions pkg/translator/azurelogs/resourcelogs_to_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,10 @@ func TestUnmarshalLogs_Files(t *testing.T) {
logFilename: "log-bad-level.json",
expectedFilename: "log-bad-level-expected.yaml",
},
// TODO Add unit test again once bug gets fixed.
// Bug https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39186#issuecomment-2798517892
// "log_maximum": {
// logFilename: "log-maximum.json",
// expectedFilename: "log-maximum-expected.yaml",
// },
"log_maximum": {
logFilename: "log-maximum.json",
expectedFilename: "log-maximum-expected.yaml",
},
"log_minimum": {
logFilename: "log-minimum.json",
expectedFilename: "log-minimum-expected.yaml",
Expand All @@ -347,7 +345,7 @@ func TestUnmarshalLogs_Files(t *testing.T) {

expectedLogs, err := golden.ReadLogs(filepath.Join(expectedDir, test.expectedFilename))
require.NoError(t, err)
require.NoError(t, plogtest.CompareLogs(expectedLogs, logs))
require.NoError(t, plogtest.CompareLogs(expectedLogs, logs, plogtest.IgnoreResourceLogsOrder()))
})
}
}
100 changes: 50 additions & 50 deletions pkg/translator/azurelogs/testdata/expected/access-log-expected.yaml
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
resourceLogs:
- resource: {}
- resource:
attributes:
- key: cloud.provider
value:
stringValue: azure
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
- key: event.name
value:
stringValue: az.resource.log
scopeLogs:
- logRecords:
- attributes:
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
- key: cloud.provider
value:
stringValue: azure
- key: event.name
value:
stringValue: az.resource.log
body:
- body:
kvlistValue:
values:
- key: http.request.size
value:
intValue: "1234"
- key: tls.protocol.version
value:
stringValue: "1.3"
- key: http.request.method
value:
stringValue: GET
- key: az.service_request_id
value:
stringValue: TRACKING_REFERENCE
- key: network.protocol.version
value:
stringValue: 1.1.0.0
- key: client.port
value:
stringValue: "0"
- key: tls.protocol.name
- key: category
value:
stringValue: tls
stringValue: AzureCdnAccessLog
- key: client.address
value:
stringValue: 42.42.42.42
- key: http.response.status_code
value:
intValue: "200"
- key: http.request.method
- key: user_agent.original
value:
stringValue: GET
stringValue: Mozilla/5.0
- key: client.port
value:
stringValue: "0"
- key: properties
value:
kvlistValue:
values:
- key: POP
value:
stringValue: LON
- key: isReceivedFromClient
value:
boolValue: false
- key: Result
- key: TimeTaken
value:
stringValue: N/A
- key: RulesEngineMatchNames
stringValue: "0.230"
- key: BackendHostName
value:
arrayValue: {}
- key: TimeToFirstByte
stringValue: backendhost.net
- key: RoutingRuleName
value:
stringValue: "0.420"
stringValue: default-route
- key: Result
value:
stringValue: N/A
- key: SNI
value:
stringValue: originshield|parentcache|https|tier2
- key: RoutingRuleName
- key: RulesEngineMatchNames
value:
stringValue: default-route
arrayValue: {}
- key: HttpStatusDetails
value:
stringValue: "200"
- key: TimeTaken
- key: POP
value:
stringValue: "0.230"
- key: BackendHostName
stringValue: LON
- key: TimeToFirstByte
value:
stringValue: backendhost.net
- key: operation.name
value:
stringValue: Microsoft.AzureCdn/Profiles/AccessLog
- key: http.response.size
value:
intValue: "12345"
stringValue: "0.420"
- key: url.full
value:
stringValue: https://test.net/
- key: tls.protocol.name
value:
stringValue: tls
- key: error.type
value:
stringValue: NoError
- key: category
value:
stringValue: AzureCdnAccessLog
- key: http.request.size
value:
intValue: "1234"
- key: az.service_request_id
- key: operation.name
value:
stringValue: TRACKING_REFERENCE
- key: user_agent.original
stringValue: Microsoft.AzureCdn/Profiles/AccessLog
- key: http.response.size
value:
stringValue: Mozilla/5.0
intValue: "12345"
spanId: ""
timeUnixNano: "1713960372000000000"
traceId: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
resourceLogs:
- resource: {}
- resource:
attributes:
- key: cloud.provider
value:
stringValue: azure
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
- key: event.name
value:
stringValue: az.resource.log
scopeLogs:
- logRecords:
- attributes:
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
- key: cloud.provider
value:
stringValue: azure
- key: event.name
value:
stringValue: az.resource.log
body:
- body:
kvlistValue:
values:
- key: http.request.header.x-azure-fdid
value:
stringValue: FDID
- key: http.request.header.x-fd-healthprobe
value:
stringValue: HEALTH_PROBE
- key: http.request.header.x-forwarded-for
value:
stringValue: FORWARDED_FOR
- key: http.request.header.x-forwarded-host
value:
stringValue: FORWARDED_HOST
- key: client.address
value:
stringValue: 42.42.42.42
- key: url.domain
value:
stringValue: HOST
- key: category
value:
stringValue: AppServiceIPSecAuditLogs
- key: operation.name
value:
stringValue: IPSecAuditLog
- key: http.request.header.x-azure-fdid
value:
stringValue: FDID
- key: http.request.header.x-fd-healthprobe
value:
stringValue: HEALTH_PROBE
- key: http.request.header.x-forwarded-for
- key: url.domain
value:
stringValue: FORWARDED_FOR
stringValue: HOST
spanId: ""
timeUnixNano: "1713960372000000000"
traceId: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
resourceLogs:
- resource: {}
- resource:
attributes:
- key: cloud.provider
value:
stringValue: azure
- key: cloud.resource_id
value:
stringValue: /SUBSCRIPTIONS/DA2DD5CC-E7BC-4DB6-94D9-0AFB3BD30577/RESOURCEGROUPS/FRETBADGER/PROVIDERS/MICROSOFT.WEB/SITES/FBEHTESTAPP
- key: event.name
value:
stringValue: az.resource.log
scopeLogs:
- logRecords:
- attributes:
- key: cloud.resource_id
value:
stringValue: /SUBSCRIPTIONS/DA2DD5CC-E7BC-4DB6-94D9-0AFB3BD30577/RESOURCEGROUPS/FRETBADGER/PROVIDERS/MICROSOFT.WEB/SITES/FBEHTESTAPP
- key: cloud.provider
value:
stringValue: azure
- key: event.name
value:
stringValue: az.resource.log
body:
- body:
kvlistValue:
values:
- key: operation.name
value:
stringValue: Authorization
- key: enduser.id
value:
stringValue: USER_ID
- key: client.address
value:
stringValue: 42.42.42.42
- key: network.protocol.name
value:
stringValue: kudu
- key: enduser.id
value:
stringValue: USER_ID
- key: properties
value:
kvlistValue:
Expand Down
Loading
Loading