Skip to content

Commit

Permalink
feat: add support for cloud.resource_id to AWS ECS detector (#1936)
Browse files Browse the repository at this point in the history
Co-authored-by: Trent Mick <trentm@gmail.com>
  • Loading branch information
mmanciop and trentm committed May 3, 2024
1 parent 16f920a commit cc71492
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion detectors/node/opentelemetry-resource-detector-aws/README.md
Expand Up @@ -84,7 +84,8 @@ Populates `container` for containers running on [Amazon ECS](https://aws.amazon.
| cloud.platform | The cloud platform. In this context, it's always "aws_ecs" |
| cloud.provider | The cloud provider. In this context, it's always "aws" |
| cloud.region | Parsed value from the `TaskARN` |
| container.id | Value of from file `/proc/self/cgroup` |
| cloud.resource_id | Value of `ContainerARN` from `ECS_CONTAINER_METADATA_URI_V4/task` request |
| container.id | Value from file `/proc/self/cgroup` |
| container.name | The hostname of the operating system |

### AWS EKS Detector
Expand Down
Expand Up @@ -41,6 +41,8 @@ import {
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_ECS,
} from '@opentelemetry/semantic-conventions';
// Patch until the OpenTelemetry SDK is updated to ship this attribute
import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from './SemanticResourceAttributes';
import * as http from 'http';
import * as util from 'util';
import * as fs from 'fs';
Expand Down Expand Up @@ -170,6 +172,7 @@ export class AwsEcsDetector implements Detector {

[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
[SEMRESATTRS_CLOUD_REGION]: region,
[AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID]: containerArn,
};

// The availability zone is not available in all Fargate runtimes
Expand Down
@@ -0,0 +1,23 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const SemanticResourceAttributes = {
/**
* Cloud provider-specific native identifier of the monitored cloud resource
* (e.g. an ARN on AWS, a fully qualified resource ID on Azure, a full resource
* name on GCP)
*/
CLOUD_RESOURCE_ID: 'cloud.resource_id',
};
Expand Up @@ -42,6 +42,8 @@ import {
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_ECS,
} from '@opentelemetry/semantic-conventions';
// Patch until the OpenTelemetry SDK is updated to ship this attribute
import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from '../../src/detectors/SemanticResourceAttributes';
import { readFileSync } from 'fs';
import * as os from 'os';
import { join } from 'path';
Expand Down Expand Up @@ -81,6 +83,10 @@ const assertEcsResource = (
resource.attributes[SEMRESATTRS_AWS_ECS_CONTAINER_ARN],
validations.containerArn
);
assert.strictEqual(
resource.attributes[AdditionalSemanticResourceAttributes.CLOUD_RESOURCE_ID],
validations.containerArn
);
if (validations.clusterArn)
assert.strictEqual(
resource.attributes[SEMRESATTRS_AWS_ECS_CLUSTER_ARN],
Expand Down

0 comments on commit cc71492

Please sign in to comment.