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

feat(resource-detector-aws): add support for cloud.resource_id to AWS ECS detector #1936

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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',
};
Original file line number Diff line number Diff line change
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
Loading