Skip to content

Commit cc71492

Browse files
mmancioptrentm
andauthored
feat: add support for cloud.resource_id to AWS ECS detector (#1936)
Co-authored-by: Trent Mick <trentm@gmail.com>
1 parent 16f920a commit cc71492

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

detectors/node/opentelemetry-resource-detector-aws/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ Populates `container` for containers running on [Amazon ECS](https://aws.amazon.
8484
| cloud.platform | The cloud platform. In this context, it's always "aws_ecs" |
8585
| cloud.provider | The cloud provider. In this context, it's always "aws" |
8686
| cloud.region | Parsed value from the `TaskARN` |
87-
| container.id | Value of from file `/proc/self/cgroup` |
87+
| cloud.resource_id | Value of `ContainerARN` from `ECS_CONTAINER_METADATA_URI_V4/task` request |
88+
| container.id | Value from file `/proc/self/cgroup` |
8889
| container.name | The hostname of the operating system |
8990

9091
### AWS EKS Detector

detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import {
4141
CLOUDPROVIDERVALUES_AWS,
4242
CLOUDPLATFORMVALUES_AWS_ECS,
4343
} from '@opentelemetry/semantic-conventions';
44+
// Patch until the OpenTelemetry SDK is updated to ship this attribute
45+
import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from './SemanticResourceAttributes';
4446
import * as http from 'http';
4547
import * as util from 'util';
4648
import * as fs from 'fs';
@@ -170,6 +172,7 @@ export class AwsEcsDetector implements Detector {
170172

171173
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
172174
[SEMRESATTRS_CLOUD_REGION]: region,
175+
[AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID]: containerArn,
173176
};
174177

175178
// The availability zone is not available in all Fargate runtimes
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
export const SemanticResourceAttributes = {
17+
/**
18+
* Cloud provider-specific native identifier of the monitored cloud resource
19+
* (e.g. an ARN on AWS, a fully qualified resource ID on Azure, a full resource
20+
* name on GCP)
21+
*/
22+
CLOUD_RESOURCE_ID: 'cloud.resource_id',
23+
};

detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsEcsDetector.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import {
4242
CLOUDPROVIDERVALUES_AWS,
4343
CLOUDPLATFORMVALUES_AWS_ECS,
4444
} from '@opentelemetry/semantic-conventions';
45+
// Patch until the OpenTelemetry SDK is updated to ship this attribute
46+
import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from '../../src/detectors/SemanticResourceAttributes';
4547
import { readFileSync } from 'fs';
4648
import * as os from 'os';
4749
import { join } from 'path';
@@ -81,6 +83,10 @@ const assertEcsResource = (
8183
resource.attributes[SEMRESATTRS_AWS_ECS_CONTAINER_ARN],
8284
validations.containerArn
8385
);
86+
assert.strictEqual(
87+
resource.attributes[AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID],
88+
validations.containerArn
89+
);
8490
if (validations.clusterArn)
8591
assert.strictEqual(
8692
resource.attributes[SEMRESATTRS_AWS_ECS_CLUSTER_ARN],

0 commit comments

Comments
 (0)