diff --git a/.chloggen/azure-events-receiver-translator.yaml b/.chloggen/azure-events-receiver-translator.yaml new file mode 100644 index 000000000000..0f1a42811203 --- /dev/null +++ b/.chloggen/azure-events-receiver-translator.yaml @@ -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: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: azureeventshubreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Updates the Azure Event Hub receiver to use the new Resource Logs translator. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35357] + +# (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: [] diff --git a/cmd/otelcontribcol/builder-config.yaml b/cmd/otelcontribcol/builder-config.yaml index 9dcc6cc77991..87969daa936e 100644 --- a/cmd/otelcontribcol/builder-config.yaml +++ b/cmd/otelcontribcol/builder-config.yaml @@ -465,6 +465,7 @@ replaces: - github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector => ../../connector/spanmetricsconnector - github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api v0.0.0-20180801171038-322a19404e37 - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure => ../../pkg/translator/azure + - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs => ../../pkg/translator/azurelogs - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking => ../../pkg/translator/skywalking - github.com/open-telemetry/opentelemetry-collector-contrib/internal/collectd => ../../internal/collectd - github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../../extension/encoding diff --git a/receiver/azureeventhubreceiver/README.md b/receiver/azureeventhubreceiver/README.md index 9cf9a13b4734..bf874629c6ed 100644 --- a/receiver/azureeventhubreceiver/README.md +++ b/receiver/azureeventhubreceiver/README.md @@ -43,6 +43,13 @@ section below for details. Default: "azure" +### apply_semantic_conventions (optional) +Determines whether Azure Resource Logs are translated into OpenTelemetry Logs using semantic +convention attrobute names or not. When not applying semantic conventions, the log entry +attribute nates are copied without any changes. + +Default: `false` (semantic conventions are not applied) + ### Example Configuration ```yaml diff --git a/receiver/azureeventhubreceiver/azureresourcelogs_unmarshaler.go b/receiver/azureeventhubreceiver/azureresourcelogs_unmarshaler.go index 1665c9f2d833..6b0b6329f893 100644 --- a/receiver/azureeventhubreceiver/azureresourcelogs_unmarshaler.go +++ b/receiver/azureeventhubreceiver/azureresourcelogs_unmarshaler.go @@ -10,14 +10,26 @@ import ( "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs" ) -type AzureResourceLogsEventUnmarshaler struct { - unmarshaler *azure.ResourceLogsUnmarshaler +type logsUnmarshaler interface { + UnmarshalLogs([]byte) (plog.Logs, error) } -func newAzureResourceLogsUnmarshaler(buildInfo component.BuildInfo, logger *zap.Logger) eventLogsUnmarshaler { +type AzureResourceLogsEventUnmarshaler struct { + unmarshaler logsUnmarshaler +} +func newAzureResourceLogsUnmarshaler(buildInfo component.BuildInfo, logger *zap.Logger, applySemanticConventions bool) eventLogsUnmarshaler { + if applySemanticConventions { + return AzureResourceLogsEventUnmarshaler{ + unmarshaler: &azurelogs.ResourceLogsUnmarshaler{ + Version: buildInfo.Version, + Logger: logger, + }, + } + } return AzureResourceLogsEventUnmarshaler{ unmarshaler: &azure.ResourceLogsUnmarshaler{ Version: buildInfo.Version, diff --git a/receiver/azureeventhubreceiver/config.go b/receiver/azureeventhubreceiver/config.go index 9ccb99205fc8..e5e01c98cf87 100644 --- a/receiver/azureeventhubreceiver/config.go +++ b/receiver/azureeventhubreceiver/config.go @@ -25,12 +25,13 @@ var ( ) type Config struct { - Connection string `mapstructure:"connection"` - Partition string `mapstructure:"partition"` - Offset string `mapstructure:"offset"` - StorageID *component.ID `mapstructure:"storage"` - Format string `mapstructure:"format"` - ConsumerGroup string `mapstructure:"group"` + Connection string `mapstructure:"connection"` + Partition string `mapstructure:"partition"` + Offset string `mapstructure:"offset"` + StorageID *component.ID `mapstructure:"storage"` + Format string `mapstructure:"format"` + ConsumerGroup string `mapstructure:"group"` + ApplySemanticConventions bool `mapstructure:"apply_semantic_conventions"` } func isValidFormat(format string) bool { diff --git a/receiver/azureeventhubreceiver/config_test.go b/receiver/azureeventhubreceiver/config_test.go index 1e48db57efb4..2372194ef18c 100644 --- a/receiver/azureeventhubreceiver/config_test.go +++ b/receiver/azureeventhubreceiver/config_test.go @@ -35,12 +35,14 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, "", r0.(*Config).Offset) assert.Equal(t, "", r0.(*Config).Partition) assert.Equal(t, defaultLogFormat, logFormat(r0.(*Config).Format)) + assert.False(t, r0.(*Config).ApplySemanticConventions) r1 := cfg.Receivers[component.NewIDWithName(metadata.Type, "all")] assert.Equal(t, "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName", r1.(*Config).Connection) assert.Equal(t, "1234-5566", r1.(*Config).Offset) assert.Equal(t, "foo", r1.(*Config).Partition) assert.Equal(t, rawLogFormat, logFormat(r1.(*Config).Format)) + assert.True(t, r1.(*Config).ApplySemanticConventions) } func TestMissingConnection(t *testing.T) { diff --git a/receiver/azureeventhubreceiver/factory.go b/receiver/azureeventhubreceiver/factory.go index c78cc01975d6..0b20556b7bcc 100644 --- a/receiver/azureeventhubreceiver/factory.go +++ b/receiver/azureeventhubreceiver/factory.go @@ -116,7 +116,7 @@ func (f *eventhubReceiverFactory) getReceiver( if logFormat(receiverConfig.Format) == rawLogFormat { logsUnmarshaler = newRawLogsUnmarshaler(settings.Logger) } else { - logsUnmarshaler = newAzureResourceLogsUnmarshaler(settings.BuildInfo, settings.Logger) + logsUnmarshaler = newAzureResourceLogsUnmarshaler(settings.BuildInfo, settings.Logger, receiverConfig.ApplySemanticConventions) } case pipeline.SignalMetrics: if logFormat(receiverConfig.Format) == rawLogFormat { diff --git a/receiver/azureeventhubreceiver/go.mod b/receiver/azureeventhubreceiver/go.mod index d32f4558d3dd..8d912a0df2d2 100644 --- a/receiver/azureeventhubreceiver/go.mod +++ b/receiver/azureeventhubreceiver/go.mod @@ -9,6 +9,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.111.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.111.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.111.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs v0.111.0 github.com/relvacode/iso8601 v1.4.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae @@ -163,6 +164,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/share replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure => ../../pkg/translator/azure +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs => ../../pkg/translator/azurelogs + replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common diff --git a/receiver/azureeventhubreceiver/testdata/config.yaml b/receiver/azureeventhubreceiver/testdata/config.yaml index 4afddc4c7175..091b2cbe0a48 100644 --- a/receiver/azureeventhubreceiver/testdata/config.yaml +++ b/receiver/azureeventhubreceiver/testdata/config.yaml @@ -7,6 +7,7 @@ receivers: partition: foo offset: "1234-5566" format: "raw" + apply_semantic_conventions: true processors: nop: