Skip to content
Prev Previous commit
Next Next commit
Add resource attributes
  • Loading branch information
constanca-m committed Apr 22, 2025
commit 87f6fe8b3cd5bb9178c000577e98e91ce604eb50
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
12 changes: 3 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,16 @@ 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)
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()))
})
}
}
101 changes: 49 additions & 52 deletions pkg/translator/azurelogs/testdata/expected/access-log-expected.yaml
Original file line number Diff line number Diff line change
@@ -1,99 +1,96 @@
resourceLogs:
- resource: {}
- resource:
attributes:
- key: cloud.provider
value:
stringValue: azure
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
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: tls.protocol.version
value:
stringValue: "1.3"
- key: network.protocol.version
value:
stringValue: 1.1.0.0
- key: client.port
- key: http.request.method
value:
stringValue: "0"
stringValue: GET
- key: http.response.size
value:
intValue: "12345"
- key: tls.protocol.name
value:
stringValue: tls
- key: client.address
value:
stringValue: 42.42.42.42
- key: http.response.status_code
- key: error.type
value:
intValue: "200"
- key: http.request.method
stringValue: NoError
- key: user_agent.original
value:
stringValue: GET
stringValue: Mozilla/5.0
- key: properties
value:
kvlistValue:
values:
- key: BackendHostName
value:
stringValue: backendhost.net
- key: POP
value:
stringValue: LON
- key: isReceivedFromClient
- key: TimeTaken
value:
boolValue: false
- key: Result
stringValue: "0.230"
- key: RoutingRuleName
value:
stringValue: N/A
stringValue: default-route
- key: RulesEngineMatchNames
value:
arrayValue: {}
- key: TimeToFirstByte
value:
stringValue: "0.420"
- key: SNI
value:
stringValue: originshield|parentcache|https|tier2
- key: RoutingRuleName
- key: Result
value:
stringValue: default-route
stringValue: N/A
- key: HttpStatusDetails
value:
stringValue: "200"
- key: TimeTaken
- key: isReceivedFromClient
value:
stringValue: "0.230"
- key: BackendHostName
boolValue: false
- key: TimeToFirstByte
value:
stringValue: backendhost.net
stringValue: "0.420"
- key: SNI
value:
stringValue: originshield|parentcache|https|tier2
- key: http.response.status_code
value:
intValue: "200"
- key: http.request.size
value:
intValue: "1234"
- key: operation.name
value:
stringValue: Microsoft.AzureCdn/Profiles/AccessLog
- key: http.response.size
- key: client.address
value:
intValue: "12345"
stringValue: 42.42.42.42
- key: url.full
value:
stringValue: https://test.net/
- key: error.type
value:
stringValue: NoError
- key: category
value:
stringValue: AzureCdnAccessLog
- key: http.request.size
- key: client.port
value:
intValue: "1234"
stringValue: "0"
- key: az.service_request_id
value:
stringValue: TRACKING_REFERENCE
- key: user_agent.original
- key: tls.protocol.version
value:
stringValue: Mozilla/5.0
stringValue: "1.3"
- key: category
value:
stringValue: AzureCdnAccessLog
spanId: ""
timeUnixNano: "1713960372000000000"
traceId: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
resourceLogs:
- resource: {}
- resource:
attributes:
- key: cloud.provider
value:
stringValue: azure
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
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-forwarded-host
- key: http.request.header.x-fd-healthprobe
value:
stringValue: FORWARDED_HOST
- key: client.address
stringValue: HEALTH_PROBE
- key: http.request.header.x-forwarded-for
value:
stringValue: 42.42.42.42
- key: url.domain
stringValue: FORWARDED_FOR
- key: http.request.header.x-forwarded-host
value:
stringValue: HOST
stringValue: FORWARDED_HOST
- key: category
value:
stringValue: AppServiceIPSecAuditLogs
- key: operation.name
value:
stringValue: IPSecAuditLog
- key: http.request.header.x-azure-fdid
- key: client.address
value:
stringValue: FDID
- key: http.request.header.x-fd-healthprobe
stringValue: 42.42.42.42
- key: url.domain
value:
stringValue: HEALTH_PROBE
- key: http.request.header.x-forwarded-for
stringValue: HOST
- key: http.request.header.x-azure-fdid
value:
stringValue: FORWARDED_FOR
stringValue: FDID
spanId: ""
timeUnixNano: "1713960372000000000"
traceId: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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
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: category
value:
stringValue: AppServiceAuditLogs
- key: operation.name
value:
stringValue: Authorization
Expand All @@ -34,9 +34,6 @@ resourceLogs:
- key: UserDisplayName
value:
stringValue: $fbehtestapp
- key: category
value:
stringValue: AppServiceAuditLogs
spanId: ""
timeUnixNano: "1713960080842740000"
traceId: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
resourceLogs:
- resource: {}
- resource:
attributes:
- key: cloud.provider
value:
stringValue: azure
- key: cloud.resource_id
value:
stringValue: /RESOURCE_ID
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: category
value:
stringValue: AppServiceConsoleLogs
- key: operation.name
value:
stringValue: ConsoleLog
Expand All @@ -24,9 +24,6 @@ resourceLogs:
- key: host.id
value:
stringValue: HOST
- key: category
value:
stringValue: AppServiceConsoleLogs
spanId: ""
timeUnixNano: "1713960372000000000"
traceId: ""
Expand Down
Loading