Skip to content

Commit

Permalink
fix(resources): fix when attribute values are surrounded by double qu…
Browse files Browse the repository at this point in the history
…otes
  • Loading branch information
anthony-telljohann committed Oct 12, 2022
1 parent 550da3c commit 6e2eda1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class EnvDetector implements Detector {
let [key, value] = keyValuePair;
// Leading and trailing whitespaces are trimmed.
key = key.trim();
value = value.trim().split('^"|"$').join('');
value = value.trim().split(/^\"|\"$/).join('');
if (!this._isValidAndNotEmpty(key)) {
throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);
}
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",k8s.deployment.name="deployment name"';
});

after(() => {
Expand All @@ -36,9 +36,10 @@ 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_CLUSTER_NAME]: 'c1',
[SemanticResourceAttributes.K8S_NAMESPACE_NAME]: 'default',
podName: 'pod-xyz-123',
clusterName: 'c1',
namespaceName: 'default',
deploymentName: 'deployment name'
});
});
});
Expand Down

0 comments on commit 6e2eda1

Please sign in to comment.