Skip to content

Commit

Permalink
Update AzureEventsHubReceiver with new resource logs translator (#35357)
Browse files Browse the repository at this point in the history
**Description:**

Updates the AzureEventsHubReceiver to use the new azure resource logs
translator.

Includes the following changes:
- Add config option to enable the new behaviour, default is off so
requires users to opt-in
- Add interface to allow switching over the previous and new translator
logic
- Update receiver to use new config option to return the appropriate
translator
- Update README with new configuration option

Follow-up PR to adding the translator:
- #34830 

**Link to tracking Issue:**
N/A

**Testing:**
Includes unit test to verify configuration defaults and changes.

**Documentation:**
N/A

---------

Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
MikeGoldsmith and codeboten authored Oct 16, 2024
1 parent ca26982 commit 0986213
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .chloggen/azure-events-receiver-translator.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: 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: []
1 change: 1 addition & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions receiver/azureeventhubreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions receiver/azureeventhubreceiver/azureresourcelogs_unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions receiver/azureeventhubreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions receiver/azureeventhubreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/azureeventhubreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions receiver/azureeventhubreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions receiver/azureeventhubreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ receivers:
partition: foo
offset: "1234-5566"
format: "raw"
apply_semantic_conventions: true

processors:
nop:
Expand Down

0 comments on commit 0986213

Please sign in to comment.