Skip to content

Commit

Permalink
Merge branch 'main' into fix_mongoose_model_method_session_instrument…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
ferrelucas committed Apr 3, 2024
2 parents 1381823 + 8c6ba2c commit d3294fe
Show file tree
Hide file tree
Showing 67 changed files with 788 additions and 715 deletions.
1 change: 1 addition & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ components:
plugins/node/opentelemetry-instrumentation-runtime-node:
- d4nyll
plugins/node/opentelemetry-instrumentation-pg:
- maryliag
- rauno56
plugins/node/opentelemetry-instrumentation-pino:
- seemk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-alibaba-cloud#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ import {
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudPlatformValues,
CloudProviderValues,
SemanticResourceAttributes,
CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
SEMRESATTRS_CLOUD_ACCOUNT_ID,
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_REGION,
SEMRESATTRS_HOST_ID,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_HOST_TYPE,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';

Expand Down Expand Up @@ -61,16 +68,14 @@ class AlibabaCloudEcsDetector implements Detector {
const hostname = await this._fetchHost();

return new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]:
CloudProviderValues.ALIBABA_CLOUD,
[SemanticResourceAttributes.CLOUD_PLATFORM]:
CloudPlatformValues.ALIBABA_CLOUD_ECS,
[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: accountId,
[SemanticResourceAttributes.CLOUD_REGION]: region,
[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SemanticResourceAttributes.HOST_ID]: instanceId,
[SemanticResourceAttributes.HOST_TYPE]: instanceType,
[SemanticResourceAttributes.HOST_NAME]: hostname,
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
[SEMRESATTRS_CLOUD_REGION]: region,
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SEMRESATTRS_HOST_ID]: instanceId,
[SEMRESATTRS_HOST_TYPE]: instanceType,
[SEMRESATTRS_HOST_NAME]: hostname,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as nock from 'nock';
import * as assert from 'assert';
import { Resource } from '@opentelemetry/resources';
import { CloudProviderValues } from '@opentelemetry/semantic-conventions';
import { CLOUDPROVIDERVALUES_ALIBABA_CLOUD } from '@opentelemetry/semantic-conventions';
import { alibabaCloudEcsDetector } from '../../src';
import {
assertCloudResource,
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('alibabaCloudEcsDetector', () => {
assert.ok(resource);

assertCloudResource(resource, {
provider: CloudProviderValues.ALIBABA_CLOUD,
provider: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
accountId: 'my-owner-account-id',
region: 'my-region-id',
zone: 'my-zone-id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"dependencies": {
"@opentelemetry/core": "^1.0.0",
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-aws#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ import {
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
SemanticResourceAttributes,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_SERVICE_NAME,
SEMRESATTRS_SERVICE_NAMESPACE,
SEMRESATTRS_SERVICE_VERSION,
SEMRESATTRS_SERVICE_INSTANCE_ID,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_ELASTIC_BEANSTALK,
} from '@opentelemetry/semantic-conventions';
import * as fs from 'fs';
import * as util from 'util';
Expand Down Expand Up @@ -69,16 +74,12 @@ export class AwsBeanstalkDetector implements Detector {
const parsedData = JSON.parse(rawData);

return new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]:
CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
[SemanticResourceAttributes.SERVICE_NAME]:
CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
[SemanticResourceAttributes.SERVICE_NAMESPACE]:
parsedData.environment_name,
[SemanticResourceAttributes.SERVICE_VERSION]: parsedData.version_label,
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]:
parsedData.deployment_id,
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AWS,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AWS_ELASTIC_BEANSTALK,
[SEMRESATTRS_SERVICE_NAME]: CLOUDPLATFORMVALUES_AWS_ELASTIC_BEANSTALK,
[SEMRESATTRS_SERVICE_NAMESPACE]: parsedData.environment_name,
[SEMRESATTRS_SERVICE_VERSION]: parsedData.version_label,
[SEMRESATTRS_SERVICE_INSTANCE_ID]: parsedData.deployment_id,
});
} catch (e: any) {
diag.debug(`AwsBeanstalkDetector failed: ${e.message}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ import {
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
SemanticResourceAttributes,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_CLOUD_REGION,
SEMRESATTRS_CLOUD_ACCOUNT_ID,
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
SEMRESATTRS_HOST_ID,
SEMRESATTRS_HOST_TYPE,
SEMRESATTRS_HOST_NAME,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_EC2,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';

Expand Down Expand Up @@ -62,14 +69,14 @@ class AwsEc2Detector implements Detector {
const hostname = await this._fetchHost(token);

return new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_EC2,
[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: accountId,
[SemanticResourceAttributes.CLOUD_REGION]: region,
[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SemanticResourceAttributes.HOST_ID]: instanceId,
[SemanticResourceAttributes.HOST_TYPE]: instanceType,
[SemanticResourceAttributes.HOST_NAME]: hostname,
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AWS,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AWS_EC2,
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
[SEMRESATTRS_CLOUD_REGION]: region,
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SEMRESATTRS_HOST_ID]: instanceId,
[SEMRESATTRS_HOST_TYPE]: instanceType,
[SEMRESATTRS_HOST_NAME]: hostname,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,25 @@ import {
ResourceAttributes,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
SemanticResourceAttributes,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_CONTAINER_ID,
SEMRESATTRS_CONTAINER_NAME,
SEMRESATTRS_AWS_ECS_CONTAINER_ARN,
SEMRESATTRS_AWS_ECS_CLUSTER_ARN,
SEMRESATTRS_AWS_ECS_LAUNCHTYPE,
SEMRESATTRS_AWS_ECS_TASK_ARN,
SEMRESATTRS_AWS_ECS_TASK_FAMILY,
SEMRESATTRS_AWS_ECS_TASK_REVISION,
SEMRESATTRS_CLOUD_ACCOUNT_ID,
SEMRESATTRS_CLOUD_REGION,
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
SEMRESATTRS_AWS_LOG_GROUP_NAMES,
SEMRESATTRS_AWS_LOG_GROUP_ARNS,
SEMRESATTRS_AWS_LOG_STREAM_NAMES,
SEMRESATTRS_AWS_LOG_STREAM_ARNS,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_ECS,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';
import * as util from 'util';
Expand Down Expand Up @@ -58,8 +74,8 @@ export class AwsEcsDetector implements Detector {
}

let resource = new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_ECS,
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AWS,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AWS_ECS,
}).merge(await AwsEcsDetector._getContainerIdAndHostnameResource());

const metadataUrl = getEnv().ECS_CONTAINER_METADATA_URI_V4;
Expand Down Expand Up @@ -114,8 +130,8 @@ export class AwsEcsDetector implements Detector {

if (hostName || containerId) {
return new Resource({
[SemanticResourceAttributes.CONTAINER_NAME]: hostName || '',
[SemanticResourceAttributes.CONTAINER_ID]: containerId || '',
[SEMRESATTRS_CONTAINER_NAME]: hostName || '',
[SEMRESATTRS_CONTAINER_ID]: containerId || '',
});
}

Expand Down Expand Up @@ -145,23 +161,20 @@ export class AwsEcsDetector implements Detector {

// https://github.com/open-telemetry/semantic-conventions/blob/main/semantic_conventions/resource/cloud_provider/aws/ecs.yaml
const attributes: ResourceAttributes = {
[SemanticResourceAttributes.AWS_ECS_CONTAINER_ARN]: containerArn,
[SemanticResourceAttributes.AWS_ECS_CLUSTER_ARN]: clusterArn,
[SemanticResourceAttributes.AWS_ECS_LAUNCHTYPE]:
launchType?.toLowerCase(),
[SemanticResourceAttributes.AWS_ECS_TASK_ARN]: taskArn,
[SemanticResourceAttributes.AWS_ECS_TASK_FAMILY]: taskMetadata['Family'],
[SemanticResourceAttributes.AWS_ECS_TASK_REVISION]:
taskMetadata['Revision'],

[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: accountId,
[SemanticResourceAttributes.CLOUD_REGION]: region,
[SEMRESATTRS_AWS_ECS_CONTAINER_ARN]: containerArn,
[SEMRESATTRS_AWS_ECS_CLUSTER_ARN]: clusterArn,
[SEMRESATTRS_AWS_ECS_LAUNCHTYPE]: launchType?.toLowerCase(),
[SEMRESATTRS_AWS_ECS_TASK_ARN]: taskArn,
[SEMRESATTRS_AWS_ECS_TASK_FAMILY]: taskMetadata['Family'],
[SEMRESATTRS_AWS_ECS_TASK_REVISION]: taskMetadata['Revision'],

[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
[SEMRESATTRS_CLOUD_REGION]: region,
};

// The availability zone is not available in all Fargate runtimes
if (availabilityZone) {
attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE] =
availabilityZone;
attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE] = availabilityZone;
}

return new Resource(attributes);
Expand Down Expand Up @@ -192,10 +205,10 @@ export class AwsEcsDetector implements Detector {
const logsStreamArn = `arn:aws:logs:${logsRegion}:${awsAccount}:log-group:${logsGroupName}:log-stream:${logsStreamName}`;

return new Resource({
[SemanticResourceAttributes.AWS_LOG_GROUP_NAMES]: [logsGroupName],
[SemanticResourceAttributes.AWS_LOG_GROUP_ARNS]: [logsGroupArn],
[SemanticResourceAttributes.AWS_LOG_STREAM_NAMES]: [logsStreamName],
[SemanticResourceAttributes.AWS_LOG_STREAM_ARNS]: [logsStreamArn],
[SEMRESATTRS_AWS_LOG_GROUP_NAMES]: [logsGroupName],
[SEMRESATTRS_AWS_LOG_GROUP_ARNS]: [logsGroupArn],
[SEMRESATTRS_AWS_LOG_STREAM_NAMES]: [logsStreamName],
[SEMRESATTRS_AWS_LOG_STREAM_ARNS]: [logsStreamArn],
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import {
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
SemanticResourceAttributes,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_K8S_CLUSTER_NAME,
SEMRESATTRS_CONTAINER_ID,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_EKS,
} from '@opentelemetry/semantic-conventions';
import * as https from 'https';
import * as fs from 'fs';
Expand Down Expand Up @@ -79,12 +82,10 @@ export class AwsEksDetector implements Detector {
return !containerId && !clusterName
? Resource.empty()
: new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]:
CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]:
CloudPlatformValues.AWS_EKS,
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: clusterName || '',
[SemanticResourceAttributes.CONTAINER_ID]: containerId || '',
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AWS,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AWS_EKS,
[SEMRESATTRS_K8S_CLUSTER_NAME]: clusterName || '',
[SEMRESATTRS_CONTAINER_ID]: containerId || '',
});
} 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 @@ -21,9 +21,13 @@ import {
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
SemanticResourceAttributes,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_CLOUD_REGION,
SEMRESATTRS_FAAS_VERSION,
SEMRESATTRS_FAAS_NAME,
CLOUDPROVIDERVALUES_AWS,
CLOUDPLATFORMVALUES_AWS_LAMBDA,
} from '@opentelemetry/semantic-conventions';

/**
Expand All @@ -42,22 +46,18 @@ export class AwsLambdaDetector implements Detector {
const region = process.env.AWS_REGION;

const attributes: ResourceAttributes = {
[SemanticResourceAttributes.CLOUD_PROVIDER]: String(
CloudProviderValues.AWS
),
[SemanticResourceAttributes.CLOUD_PLATFORM]: String(
CloudPlatformValues.AWS_LAMBDA
),
[SEMRESATTRS_CLOUD_PROVIDER]: String(CLOUDPROVIDERVALUES_AWS),
[SEMRESATTRS_CLOUD_PLATFORM]: String(CLOUDPLATFORMVALUES_AWS_LAMBDA),
};
if (region) {
attributes[SemanticResourceAttributes.CLOUD_REGION] = region;
attributes[SEMRESATTRS_CLOUD_REGION] = region;
}

if (functionName) {
attributes[SemanticResourceAttributes.FAAS_NAME] = functionName;
attributes[SEMRESATTRS_FAAS_NAME] = functionName;
}
if (functionVersion) {
attributes[SemanticResourceAttributes.FAAS_VERSION] = functionVersion;
attributes[SEMRESATTRS_FAAS_VERSION] = functionVersion;
}

return new Resource(attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
assertEmptyResource,
assertServiceResource,
} from '@opentelemetry/contrib-test-utils';
import { CloudPlatformValues } from '@opentelemetry/semantic-conventions';
import { CLOUDPLATFORMVALUES_AWS_ELASTIC_BEANSTALK } from '@opentelemetry/semantic-conventions';

describe('BeanstalkResourceDetector', () => {
const err = new Error('failed to read config file');
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('BeanstalkResourceDetector', () => {
sinon.assert.calledOnce(readStub);
assert.ok(resource);
assertServiceResource(resource, {
name: CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
name: CLOUDPLATFORMVALUES_AWS_ELASTIC_BEANSTALK,
namespace: 'scorekeep',
version: 'app-5a56-170119_190650-stage-170119_190650',
instanceId: '32',
Expand All @@ -80,7 +80,7 @@ describe('BeanstalkResourceDetector', () => {
sinon.assert.calledOnce(readStub);
assert.ok(resource);
assertServiceResource(resource, {
name: CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
name: CLOUDPLATFORMVALUES_AWS_ELASTIC_BEANSTALK,
namespace: 'scorekeep',
version: 'app-5a56-170119_190650-stage-170119_190650',
instanceId: '32',
Expand Down
Loading

0 comments on commit d3294fe

Please sign in to comment.