Skip to content

Commit

Permalink
fix(resources): fix EnvDetector throwing errors when attribute values…
Browse files Browse the repository at this point in the history
… contain spaces
  • Loading branch information
anthony-telljohann committed Oct 5, 2022
1 parent 1864a9a commit 05d3441
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ All notable changes to this project will be documented in this file.

### :bug: (Bug Fix)

* fix(resources): fix EnvDetector throwing errors when attribute values contain spaces
[#3295](https://github.com/open-telemetry/opentelemetry-js/issues/3295)

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class EnvDetector implements Detector {
private _isPrintableString(str: string): boolean {
for (let i = 0; i < str.length; i++) {
const ch: string = str.charAt(i);
if (ch <= ' ' || ch >= '~') {
if (ch < ' ' || ch >= '~') {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describeNode('envDetector() on Node.js', () => {
describe('with valid env', () => {
before(() => {
process.env.OTEL_RESOURCE_ATTRIBUTES =
'k8s.pod.name="pod-xyz-123",k8s.cluster.name="c1",k8s.namespace.name="default"';
'k8s.pod.name="pod xyz 123",k8s.cluster.name="c1",k8s.namespace.name="default"';
});

after(() => {
Expand All @@ -36,7 +36,7 @@ describeNode('envDetector() on Node.js', () => {
it('should return resource information from environment variable', async () => {
const resource: Resource = await envDetector.detect();
assertK8sResource(resource, {
[SemanticResourceAttributes.K8S_POD_NAME]: 'pod-xyz-123',
[SemanticResourceAttributes.K8S_POD_NAME]: 'pod xyz 123',
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: 'c1',
[SemanticResourceAttributes.K8S_NAMESPACE_NAME]: 'default',
});
Expand Down

0 comments on commit 05d3441

Please sign in to comment.