Skip to content

Commit 0986213

Browse files
Update AzureEventsHubReceiver with new resource logs translator (open-telemetry#35357)
**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: - open-telemetry#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]>
1 parent ca26982 commit 0986213

File tree

9 files changed

+64
-10
lines changed

9 files changed

+64
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: azureeventshubreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Updates the Azure Event Hub receiver to use the new Resource Logs translator.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35357]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

cmd/otelcontribcol/builder-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ replaces:
465465
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector => ../../connector/spanmetricsconnector
466466
- github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api v0.0.0-20180801171038-322a19404e37
467467
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure => ../../pkg/translator/azure
468+
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs => ../../pkg/translator/azurelogs
468469
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking => ../../pkg/translator/skywalking
469470
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/collectd => ../../internal/collectd
470471
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../../extension/encoding

receiver/azureeventhubreceiver/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ section below for details.
4343

4444
Default: "azure"
4545

46+
### apply_semantic_conventions (optional)
47+
Determines whether Azure Resource Logs are translated into OpenTelemetry Logs using semantic
48+
convention attrobute names or not. When not applying semantic conventions, the log entry
49+
attribute nates are copied without any changes.
50+
51+
Default: `false` (semantic conventions are not applied)
52+
4653
### Example Configuration
4754

4855
```yaml

receiver/azureeventhubreceiver/azureresourcelogs_unmarshaler.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,26 @@ import (
1010
"go.uber.org/zap"
1111

1212
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure"
13+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs"
1314
)
1415

15-
type AzureResourceLogsEventUnmarshaler struct {
16-
unmarshaler *azure.ResourceLogsUnmarshaler
16+
type logsUnmarshaler interface {
17+
UnmarshalLogs([]byte) (plog.Logs, error)
1718
}
1819

19-
func newAzureResourceLogsUnmarshaler(buildInfo component.BuildInfo, logger *zap.Logger) eventLogsUnmarshaler {
20+
type AzureResourceLogsEventUnmarshaler struct {
21+
unmarshaler logsUnmarshaler
22+
}
2023

24+
func newAzureResourceLogsUnmarshaler(buildInfo component.BuildInfo, logger *zap.Logger, applySemanticConventions bool) eventLogsUnmarshaler {
25+
if applySemanticConventions {
26+
return AzureResourceLogsEventUnmarshaler{
27+
unmarshaler: &azurelogs.ResourceLogsUnmarshaler{
28+
Version: buildInfo.Version,
29+
Logger: logger,
30+
},
31+
}
32+
}
2133
return AzureResourceLogsEventUnmarshaler{
2234
unmarshaler: &azure.ResourceLogsUnmarshaler{
2335
Version: buildInfo.Version,

receiver/azureeventhubreceiver/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ var (
2525
)
2626

2727
type Config struct {
28-
Connection string `mapstructure:"connection"`
29-
Partition string `mapstructure:"partition"`
30-
Offset string `mapstructure:"offset"`
31-
StorageID *component.ID `mapstructure:"storage"`
32-
Format string `mapstructure:"format"`
33-
ConsumerGroup string `mapstructure:"group"`
28+
Connection string `mapstructure:"connection"`
29+
Partition string `mapstructure:"partition"`
30+
Offset string `mapstructure:"offset"`
31+
StorageID *component.ID `mapstructure:"storage"`
32+
Format string `mapstructure:"format"`
33+
ConsumerGroup string `mapstructure:"group"`
34+
ApplySemanticConventions bool `mapstructure:"apply_semantic_conventions"`
3435
}
3536

3637
func isValidFormat(format string) bool {

receiver/azureeventhubreceiver/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ func TestLoadConfig(t *testing.T) {
3535
assert.Equal(t, "", r0.(*Config).Offset)
3636
assert.Equal(t, "", r0.(*Config).Partition)
3737
assert.Equal(t, defaultLogFormat, logFormat(r0.(*Config).Format))
38+
assert.False(t, r0.(*Config).ApplySemanticConventions)
3839

3940
r1 := cfg.Receivers[component.NewIDWithName(metadata.Type, "all")]
4041
assert.Equal(t, "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName", r1.(*Config).Connection)
4142
assert.Equal(t, "1234-5566", r1.(*Config).Offset)
4243
assert.Equal(t, "foo", r1.(*Config).Partition)
4344
assert.Equal(t, rawLogFormat, logFormat(r1.(*Config).Format))
45+
assert.True(t, r1.(*Config).ApplySemanticConventions)
4446
}
4547

4648
func TestMissingConnection(t *testing.T) {

receiver/azureeventhubreceiver/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (f *eventhubReceiverFactory) getReceiver(
116116
if logFormat(receiverConfig.Format) == rawLogFormat {
117117
logsUnmarshaler = newRawLogsUnmarshaler(settings.Logger)
118118
} else {
119-
logsUnmarshaler = newAzureResourceLogsUnmarshaler(settings.BuildInfo, settings.Logger)
119+
logsUnmarshaler = newAzureResourceLogsUnmarshaler(settings.BuildInfo, settings.Logger, receiverConfig.ApplySemanticConventions)
120120
}
121121
case pipeline.SignalMetrics:
122122
if logFormat(receiverConfig.Format) == rawLogFormat {

receiver/azureeventhubreceiver/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.111.0
1010
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.111.0
1111
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.111.0
12+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs v0.111.0
1213
github.com/relvacode/iso8601 v1.4.0
1314
github.com/stretchr/testify v1.9.0
1415
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
163164

164165
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure => ../../pkg/translator/azure
165166

167+
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs => ../../pkg/translator/azurelogs
168+
166169
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden
167170

168171
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common

receiver/azureeventhubreceiver/testdata/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ receivers:
77
partition: foo
88
offset: "1234-5566"
99
format: "raw"
10+
apply_semantic_conventions: true
1011

1112
processors:
1213
nop:

0 commit comments

Comments
 (0)