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 service.instance.id to resource detection #2082

Closed
wants to merge 1 commit into from
Closed
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 @@ -30,7 +30,9 @@ import {
SEMRESATTRS_HOST_NAME,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_EC2,
SEMRESATTRS_SERVICE_INSTANCE_ID,
} from '@opentelemetry/semantic-conventions';
import { randomUUID } from 'crypto';
import * as http from 'http';

/**
Expand Down Expand Up @@ -77,6 +79,7 @@ class AwsEc2Detector implements Detector {
[SEMRESATTRS_HOST_ID]: instanceId,
[SEMRESATTRS_HOST_TYPE]: instanceType,
[SEMRESATTRS_HOST_NAME]: hostname,
[SEMRESATTRS_SERVICE_INSTANCE_ID]: randomUUID(),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ import {
SEMRESATTRS_AWS_LOG_STREAM_ARNS,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_ECS,
SEMRESATTRS_SERVICE_INSTANCE_ID,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';
import * as util from 'util';
import * as fs from 'fs';
import * as os from 'os';
import { getEnv } from '@opentelemetry/core';
import { randomUUID } from 'crypto';

const HTTP_TIMEOUT_IN_MS = 1000;

Expand Down Expand Up @@ -76,6 +78,7 @@ export class AwsEcsDetector implements Detector {
let resource = new Resource({
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AWS,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AWS_ECS,
[SEMRESATTRS_SERVICE_INSTANCE_ID]: randomUUID(),
}).merge(await AwsEcsDetector._getContainerIdAndHostnameResource());

const metadataUrl = getEnv().ECS_CONTAINER_METADATA_URI_V4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
SEMRESATTRS_CONTAINER_ID,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_EKS,
SEMRESATTRS_SERVICE_INSTANCE_ID,
} from '@opentelemetry/semantic-conventions';
import * as https from 'https';
import * as fs from 'fs';
import * as util from 'util';
import { diag } from '@opentelemetry/api';
import { randomUUID } from 'crypto';

/**
* The AwsEksDetector can be used to detect if a process is running in AWS Elastic
Expand Down Expand Up @@ -86,6 +88,7 @@ export class AwsEksDetector implements Detector {
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AWS_EKS,
[SEMRESATTRS_K8S_CLUSTER_NAME]: clusterName || '',
[SEMRESATTRS_CONTAINER_ID]: containerId || '',
[SEMRESATTRS_SERVICE_INSTANCE_ID]: randomUUID(),
});
} catch (e) {
diag.warn('Process is not running on K8S', e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
assertCloudResource,
assertHostResource,
} from '@opentelemetry/contrib-test-utils';
import { SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions';

const AWS_HOST = 'http://' + awsEc2Detector.AWS_IDMS_ENDPOINT;
const AWS_TOKEN_PATH = awsEc2Detector.AWS_INSTANCE_TOKEN_DOCUMENT_PATH;
Expand Down Expand Up @@ -81,6 +82,10 @@ describe('awsEc2Detector', () => {
hostType: 'my-instance-type',
name: 'my-hostname',
});
assert.equal(
resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID]?.toString().length,
36
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
SEMRESATTRS_AWS_LOG_STREAM_ARNS,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_ECS,
SEMRESATTRS_SERVICE_INSTANCE_ID,
} from '@opentelemetry/semantic-conventions';
import { readFileSync } from 'fs';
import * as os from 'os';
Expand Down Expand Up @@ -126,6 +127,11 @@ const assertEcsResource = (
resource.attributes[SEMRESATTRS_AWS_LOG_STREAM_ARNS],
validations.logStreamArns
);

assert.equal(
resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID]?.toString().length,
36
);
};

describe('AwsEcsResourceDetector', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
assertContainerResource,
assertEmptyResource,
} from '@opentelemetry/contrib-test-utils';
import { SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions';

const K8S_SVC_URL = awsEksDetector.K8S_SVC_URL;
const AUTH_CONFIGMAP_PATH = awsEksDetector.AUTH_CONFIGMAP_PATH;
Expand Down Expand Up @@ -86,6 +87,10 @@ describe('awsEksDetector', () => {
assertContainerResource(resource, {
id: 'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm',
});
assert.equal(
resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID]?.toString().length,
36
);
});

it('should return a resource with clusterName attribute without cgroup file', async () => {
Expand Down
Loading