Skip to content

[exporter/awsemfexporter] Add user agent string when EBS metrics exist #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2025

Conversation

zhihonl
Copy link

@zhihonl zhihonl commented May 9, 2025

Description

Adds additional user agent if EBS metrics exist. This scrapes all metric names and stops the scrape once EBS metric has been found. This new process will only activate for enhanced container insights.

Testing

Unit Tests.

User Agent string

User-Agent: CWAgent/Unknown (go1.24.2; linux; amd64) ID/33abf24a-63f4-4695-8cdb-67e7d868349b inputs:(awscontainerinsightreceiver otlp) processors:(awsapplicationsignals awsentity batch filter gpuattributes metricstransform resourcedetection) outputs:(application_signals awsemf awsxray cloudwatchlogs debug enhanced_container_insights) feature:(ci_ebs) / (awsemf; EnhancedEKSContainerInsights; ContainerInsights) aws-sdk-go/1.48.6 (go1.24.2; linux; amd64)

@zhihonl zhihonl requested a review from mxiamxia as a code owner May 9, 2025 05:19
Signed-off-by: Zhihong Lin <zhiholin@amazon.com>
ms := ilms.At(j).Metrics()
for k := 0; k < ms.Len(); k++ {
metric := ms.At(k)
if strings.HasPrefix(metric.Name(), "node_diskio_ebs") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could you have a const for node_diskio_ebs

@@ -75,11 +76,7 @@ func newEmfExporter(config *Config, set exporter.Settings) (*emfExporter, error)
collectorID: collectorIdentifier.String(),
pusherMap: map[cwlogs.StreamKey]cwlogs.Pusher{},
processResourceLabels: func(map[string]string) {},
}

if config.IsAppSignalsEnabled() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in upstream, so it will cause merge conflicts. Is there a way we can keep this in? Or at least make note that this diverges from upstream

Copy link
Author

@zhihonl zhihonl May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has to be moved because of this line

emf.svcStructuredLog.Handlers().Build.PushFrontNamed(userAgent.Handler())

In a previous PR We moved svcStructuredLog variable around which is what we use to access the useragent. It is not available in newEmfExporter function anymore. We never added back PushFrontNamed function anywhere else. This basically means we stopped emitting appsignal useragent since then.

@@ -27,12 +28,15 @@ const (

// TODO: Available in semconv/v1.21.0+. Replace after collector dependency is v0.91.0+.
attributeTelemetryDistroVersion = "telemetry.distro.version"

attributeEBS = "EBS"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda weird that we have this code under internal/appsignals when its not appsignals related

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to just rename this folder to internal/useragent. Useragent related logic doesn't have to be AppSignal specific.

@@ -87,6 +92,30 @@ func (ua *UserAgent) Process(labels map[string]string) {
}
}

// ProcessMetrics checks metric names for specific patterns and updates user agent accordingly
func (ua *UserAgent) ProcessMetrics(metrics pmetric.Metrics) {
// Check if we've already detected NVME
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like we should have a separate util file for each metric we plan on identifying. In the future we may want to add a flag for GPU. It would also make it easier for merge conflicts.

Maybe have like exporter/awsemfexporter/internal/useragent_util.go with a func userAgentUtil.processNVMEMetrics(rms) that reads the resource metric and returns if it has been found or not. And we can keep track if it's found previously to not re-scan the metrics.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will cause a merge conflict since this folder doesn't exist on upstream: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/awsemfexporter/internal/

lisguo
lisguo previously approved these changes May 9, 2025
)

type UserAgent struct {
mu sync.RWMutex
prebuiltStr string
cache *ttlcache.Cache[string, string]
metrics map[string]struct{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prob would rename this variable to featureFlags or something relating to appending to the feature section

@@ -10,12 +10,14 @@ import (

"github.com/aws/aws-sdk-go/aws/request"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pmetric"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"
)

func TestUserAgent(t *testing.T) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a test just for the build() function to ensure it can build multiple feature flags in 1 section?

@zhihonl zhihonl merged commit 060e328 into aws-cwa-dev May 9, 2025
126 of 147 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants