-
Notifications
You must be signed in to change notification settings - Fork 63
[processor/elasticapmprocessor] set agentVersion, normalize dataset, service name values #1058
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
Changes from 17 commits
c1737e2
e621a3f
c4e9351
ea8edc7
90621aa
226b55f
cb596d6
057b657
a3a683b
6692425
3aca2df
988327b
f9ccb36
16a6f68
e973034
3c5006d
976aec0
1b57bea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ package enrichments // import "github.com/elastic/opentelemetry-collector-compon | |
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/elastic/opentelemetry-collector-components/processor/elasticapmprocessor/internal/sanitize" | ||
| "go.opentelemetry.io/collector/pdata/pcommon" | ||
| semconv25 "go.opentelemetry.io/otel/semconv/v1.25.0" | ||
| semconv "go.opentelemetry.io/otel/semconv/v1.27.0" | ||
|
|
@@ -49,6 +50,7 @@ type resourceEnrichmentContext struct { | |
| deploymentEnvironmentName string | ||
|
|
||
| serviceInstanceID string | ||
| serviceName string | ||
| containerID string | ||
|
|
||
| osType string | ||
|
|
@@ -78,6 +80,8 @@ func (s *resourceEnrichmentContext) Enrich(resource pcommon.Resource, cfg config | |
| s.deploymentEnvironmentName = v.Str() | ||
| case string(semconv25.ServiceInstanceIDKey): | ||
| s.serviceInstanceID = v.Str() | ||
| case string(semconv.ServiceNameKey): | ||
| s.serviceName = v.Str() | ||
| case string(semconv.ContainerIDKey): | ||
| s.containerID = v.Str() | ||
| case string(semconv.OSTypeKey): | ||
|
|
@@ -100,13 +104,21 @@ func (s *resourceEnrichmentContext) Enrich(resource pcommon.Resource, cfg config | |
| if cfg.OverrideHostName.Enabled { | ||
| s.overrideHostNameWithK8sNodeName(resource) | ||
| } | ||
|
|
||
| if cfg.DeploymentEnvironment.Enabled { | ||
| s.setDeploymentEnvironment(resource) | ||
| } | ||
|
|
||
| if cfg.DefaultDeploymentEnvironment.Enabled { | ||
| s.setDefaultDeploymentEnvironment(resource) | ||
| } | ||
|
|
||
| if cfg.ServiceInstanceID.Enabled { | ||
| s.setServiceInstanceID(resource) | ||
| } | ||
| if cfg.ServiceName.Enabled { | ||
| s.sanitizeServiceName(resource) | ||
| } | ||
| if cfg.HostOSType.Enabled { | ||
| s.setHostOSType(resource) | ||
| } | ||
|
|
@@ -117,13 +129,32 @@ func (s *resourceEnrichmentContext) Enrich(resource pcommon.Resource, cfg config | |
| // ES currently doesn't allow aliases with multiple targets, so if the new field name is used (SemConv v1.27+), | ||
| // we duplicate the value and also send it with the old field name to make the alias work. | ||
| func (s *resourceEnrichmentContext) setDeploymentEnvironment(resource pcommon.Resource) { | ||
|
lanre-ade marked this conversation as resolved.
|
||
| if s.deploymentEnvironmentName != "" && s.deploymentEnvironment == "" { | ||
| attribute.PutStr( | ||
| resource.Attributes(), | ||
| string(semconv25.DeploymentEnvironmentKey), | ||
| s.deploymentEnvironmentName, | ||
| ) | ||
| if s.deploymentEnvironment != "" { | ||
| return | ||
| } | ||
| if s.deploymentEnvironmentName == "" { | ||
| return | ||
| } | ||
|
|
||
| attribute.PutStr( | ||
| resource.Attributes(), | ||
| string(semconv25.DeploymentEnvironmentKey), | ||
|
lanre-ade marked this conversation as resolved.
|
||
| s.deploymentEnvironmentName, | ||
| ) | ||
| } | ||
|
|
||
| // setDefaultDeploymentEnvironment sets deployment.environment to "unset" | ||
| // when neither deployment environment field is present, matching the | ||
| // apm-data/MIS default only where explicitly configured. | ||
| func (s *resourceEnrichmentContext) setDefaultDeploymentEnvironment(resource pcommon.Resource) { | ||
| if s.deploymentEnvironment != "" || s.deploymentEnvironmentName != "" { | ||
| return | ||
| } | ||
| attribute.PutStr( | ||
| resource.Attributes(), | ||
| string(semconv25.DeploymentEnvironmentKey), | ||
| "unset", | ||
| ) | ||
| } | ||
|
|
||
| func (s *resourceEnrichmentContext) setAgentName(resource pcommon.Resource) { | ||
|
|
@@ -225,3 +256,13 @@ func (s *resourceEnrichmentContext) setServiceInstanceID(resource pcommon.Resour | |
| } | ||
| attribute.PutStr(resource.Attributes(), string(semconv25.ServiceInstanceIDKey), s.serviceInstanceID) | ||
| } | ||
|
|
||
| func (s *resourceEnrichmentContext) sanitizeServiceName(resource pcommon.Resource) { | ||
| if s.serviceName == "" { | ||
| return | ||
| } | ||
| cleaned := sanitize.CleanServiceName(s.serviceName) | ||
| if cleaned != s.serviceName { | ||
| resource.Attributes().PutStr(string(semconv.ServiceNameKey), cleaned) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Can we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should still sanitize. I meant to just use |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note this will require some extra coordination to ensure all modules that use this package update the version of
elasticattrthey rely on and that a new version ofelasticattris taggedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remember to change the relevant go.mod files to use the next version of the
elasticattrpackage (it should be v0.38.0). Example commit. Without this external modules will face build errors unfortunately