Skip to content
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

[k8sattributesprocessor] Support set resource attributes from environment variables of k8s pods #33700

Open
chenlujjj opened this issue Jun 21, 2024 · 3 comments
Labels
enhancement New feature or request needs triage New item requiring triage processor/k8sattributes k8s Attributes processor

Comments

@chenlujjj
Copy link
Contributor

Component(s)

processor/k8sattributes

Is your feature request related to a problem? Please describe.

We are using the receiver creator with prometheus simple receiver as the receiver inside to automatically discover pods with prometheus.io/scrape: "true" annotations and collect metrics from them. The problem is that the service.name labels in the metrics are prometheus_simple/<ip:port>, but we want them be the real service name of the applications.

Describe the solution you'd like

Currently the k8sattributesprocessor can set resource attributes from k8s labels and annotations of pods, namespaces and nodes. If it can also extract pod environment variables, such as the OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME, and set them as the resource attributes, that would help to solve the problem above.

Describe alternatives you've considered

No response

Additional context

No response

@chenlujjj chenlujjj added enhancement New feature or request needs triage New item requiring triage labels Jun 21, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the processor/k8sattributes k8s Attributes processor label Jun 21, 2024
@TylerHelmuth
Copy link
Member

Is prometheus_simple from prometheus_simple/<ip:port> the service name? If so, extracting the value from the resource attribute via the transformprocessor is a better way to go. https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/ottlfuncs#extractpatterns

@chenlujjj
Copy link
Contributor Author

chenlujjj commented Jun 22, 2024

Hi @TylerHelmuth , metrics service.name label is set as prometheus_simple/<ip:port> by the prometheus_simple receiver. The logic should be at this line of code.

So I came up with the idea to use k8sattributesprocessor to set the service.name from pod environment variable. Say if the pod has an environment variable OTEL_SERVICE_NAME=foo or OTEL_RESOURCE_ATTRIBUTES=service.name=foo, then the service.name label will be set as foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New item requiring triage processor/k8sattributes k8s Attributes processor
Projects
None yet
Development

No branches or pull requests

2 participants