From f09080137d786d57cb3666d00487abed5cb97f23 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 16:06:24 -0400 Subject: [PATCH 01/13] chore(resource-detector-azure): use exported strings for attributes (#2048) Use exported strings for Semantic Resource Attributes, Cloud Platform Values and Cloud Provider Values. Signed-off-by: maryliag Co-authored-by: Jamie Danielson --- .../package.json | 2 +- .../src/detectors/AzureAppServiceDetector.ts | 27 ++++---- .../src/detectors/AzureFunctionsDetector.ts | 35 +++++----- .../src/detectors/AzureVmDetector.ts | 26 +++++--- .../detectors/AzureAppServiceDetector.test.ts | 64 +++++++------------ .../detectors/AzureFunctionsDetector.test.ts | 45 ++++++------- package-lock.json | 4 +- 7 files changed, 97 insertions(+), 106 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-azure/package.json b/detectors/node/opentelemetry-resource-detector-azure/package.json index 6e1f51ae42..7690843f9d 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/package.json +++ b/detectors/node/opentelemetry-resource-detector-azure/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "@opentelemetry/resources": "^1.10.1", - "@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-azure#readme" } diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts index 430899b81c..7811ba4fa3 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts @@ -29,16 +29,22 @@ import { FUNCTIONS_VERSION, } from '../types'; import { - CloudProviderValues, - CloudPlatformValues, - SemanticResourceAttributes, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_DEPLOYMENT_ENVIRONMENT, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_SERVICE_INSTANCE_ID, + SEMRESATTRS_SERVICE_NAME, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_PLATFORM, + CLOUDPROVIDERVALUES_AZURE, + CLOUDPLATFORMVALUES_AZURE_APP_SERVICE, } from '@opentelemetry/semantic-conventions'; const APP_SERVICE_ATTRIBUTE_ENV_VARS = { - [SemanticResourceAttributes.CLOUD_REGION]: REGION_NAME, - [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME, - [SemanticResourceAttributes.HOST_ID]: WEBSITE_HOSTNAME, - [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID, + [SEMRESATTRS_CLOUD_REGION]: REGION_NAME, + [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME, + [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME, + [SEMRESATTRS_SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID, [AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE]: WEBSITE_HOME_STAMPNAME, }; @@ -54,16 +60,15 @@ class AzureAppServiceDetector implements DetectorSync { if (websiteSiteName && !isAzureFunction) { attributes = { ...attributes, - [SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName, + [SEMRESATTRS_SERVICE_NAME]: websiteSiteName, }; attributes = { ...attributes, - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE, }; attributes = { ...attributes, - [SemanticResourceAttributes.CLOUD_PLATFORM]: - CloudPlatformValues.AZURE_APP_SERVICE, + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE, }; const azureResourceUri = this.getAzureResourceUri(websiteSiteName); diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts index 2a695fd2d6..38b2f62f5e 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts @@ -17,9 +17,15 @@ import { DetectorSync, IResource, Resource } from '@opentelemetry/resources'; import { - CloudProviderValues, - CloudPlatformValues, - SemanticResourceAttributes, + SEMRESATTRS_FAAS_NAME, + SEMRESATTRS_FAAS_VERSION, + SEMRESATTRS_FAAS_MAX_MEMORY, + SEMRESATTRS_FAAS_INSTANCE, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_REGION, + CLOUDPROVIDERVALUES_AZURE, + CLOUDPLATFORMVALUES_AZURE_FUNCTIONS, } from '@opentelemetry/semantic-conventions'; import { WEBSITE_SITE_NAME, @@ -30,10 +36,10 @@ import { } from '../types'; const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = { - [SemanticResourceAttributes.FAAS_NAME]: WEBSITE_SITE_NAME, - [SemanticResourceAttributes.FAAS_VERSION]: FUNCTIONS_VERSION, - [SemanticResourceAttributes.FAAS_INSTANCE]: WEBSITE_INSTANCE_ID, - [SemanticResourceAttributes.FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT, + [SEMRESATTRS_FAAS_NAME]: WEBSITE_SITE_NAME, + [SEMRESATTRS_FAAS_VERSION]: FUNCTIONS_VERSION, + [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID, + [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT, }; /** @@ -50,34 +56,33 @@ class AzureFunctionsDetector implements DetectorSync { const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT]; attributes = { - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, - [SemanticResourceAttributes.CLOUD_PLATFORM]: - CloudPlatformValues.AZURE_FUNCTIONS, - [SemanticResourceAttributes.CLOUD_REGION]: process.env[REGION_NAME], + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE, + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS, + [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME], }; if (functionName) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_NAME]: functionName, + [SEMRESATTRS_FAAS_NAME]: functionName, }; } if (functionVersion) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_VERSION]: functionVersion, + [SEMRESATTRS_FAAS_VERSION]: functionVersion, }; } if (functionInstance) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_INSTANCE]: functionInstance, + [SEMRESATTRS_FAAS_INSTANCE]: functionInstance, }; } if (functionMemLimit) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_MAX_MEMORY]: functionMemLimit, + [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit, }; } diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts index 9de9bc330b..1dfc6da705 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts @@ -22,9 +22,15 @@ import { ResourceAttributes, } from '@opentelemetry/resources'; import { - CloudPlatformValues, - CloudProviderValues, - SemanticResourceAttributes, + CLOUDPLATFORMVALUES_AZURE_VM, + CLOUDPROVIDERVALUES_AZURE, + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_HOST_NAME, + SEMRESATTRS_HOST_TYPE, + SEMRESATTRS_OS_VERSION, } from '@opentelemetry/semantic-conventions'; import { CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, @@ -90,14 +96,14 @@ class AzureVmResourceDetector implements DetectorSync { const attributes = { [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'], [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'], - [SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AZURE_VM, - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, - [SemanticResourceAttributes.CLOUD_REGION]: metadata['location'], + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM, + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE, + [SEMRESATTRS_CLOUD_REGION]: metadata['location'], [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'], - [SemanticResourceAttributes.HOST_ID]: metadata['vmId'], - [SemanticResourceAttributes.HOST_NAME]: metadata['name'], - [SemanticResourceAttributes.HOST_TYPE]: metadata['vmSize'], - [SemanticResourceAttributes.OS_VERSION]: metadata['version'], + [SEMRESATTRS_HOST_ID]: metadata['vmId'], + [SEMRESATTRS_HOST_NAME]: metadata['name'], + [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'], + [SEMRESATTRS_OS_VERSION]: metadata['version'], }; return attributes; } diff --git a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts index 46796d3a6a..c178106f32 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts @@ -16,7 +16,15 @@ import * as assert from 'assert'; import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_DEPLOYMENT_ENVIRONMENT, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_SERVICE_INSTANCE_ID, + SEMRESATTRS_SERVICE_NAME, +} from '@opentelemetry/semantic-conventions'; import { azureFunctionsDetector } from '../../src'; import { detectResourcesSync } from '@opentelemetry/resources'; @@ -45,36 +53,24 @@ describe('AzureAppServiceDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_SERVICE_NAME], 'test-site'); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure'); assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_NAME], - 'test-site' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PROVIDER], - 'azure' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PLATFORM], + attributes[SEMRESATTRS_CLOUD_PLATFORM], 'azure_app_service' ); assert.strictEqual( attributes['cloud.resource_id'], `/subscriptions/${process.env.WEBSITE_OWNER_NAME}/resourceGroups/${process.env.WEBSITE_RESOURCE_GROUP}/providers/Microsoft.Web/sites/${process.env.WEBSITE_SITE_NAME}` ); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT], + attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT], 'test-slot' ); + assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname'); assert.strictEqual( - attributes[SemanticResourceAttributes.HOST_ID], - 'test-hostname' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], 'test-instance-id' ); assert.strictEqual( @@ -97,20 +93,14 @@ describe('AzureAppServiceDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT], + attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT], 'test-slot' ); + assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname'); assert.strictEqual( - attributes[SemanticResourceAttributes.HOST_ID], - 'test-hostname' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], 'test-instance-id' ); assert.strictEqual( @@ -134,20 +124,14 @@ describe('AzureAppServiceDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT], + attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT], 'test-slot' ); + assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname'); assert.strictEqual( - attributes[SemanticResourceAttributes.HOST_ID], - 'test-hostname' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], 'test-instance-id' ); assert.strictEqual( diff --git a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts index 2918f245f5..0a334ab66f 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts @@ -17,7 +17,16 @@ import * as assert from 'assert'; import { azureFunctionsDetector } from '../../src/detectors/AzureFunctionsDetector'; import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_FAAS_INSTANCE, + SEMRESATTRS_FAAS_MAX_MEMORY, + SEMRESATTRS_FAAS_NAME, + SEMRESATTRS_FAAS_VERSION, + SEMRESATTRS_SERVICE_INSTANCE_ID, +} from '@opentelemetry/semantic-conventions'; import { detectResourcesSync } from '@opentelemetry/resources'; import { AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE } from '../../src/types'; @@ -43,40 +52,22 @@ describe('AzureFunctionsDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_FAAS_NAME], 'test-function'); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure'); assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_NAME], - 'test-function' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PROVIDER], - 'azure' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PLATFORM], + attributes[SEMRESATTRS_CLOUD_PLATFORM], 'azure_functions' ); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_INSTANCE], + attributes[SEMRESATTRS_FAAS_INSTANCE], 'test-instance-id' ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_MAX_MEMORY], - '1000' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_VERSION], - '~4' - ); + assert.strictEqual(attributes[SEMRESATTRS_FAAS_MAX_MEMORY], '1000'); + assert.strictEqual(attributes[SEMRESATTRS_FAAS_VERSION], '~4'); // Should not detect app service values - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], - undefined - ); + assert.strictEqual(attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], undefined); assert.strictEqual( attributes[AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE], diff --git a/package-lock.json b/package-lock.json index 9a502dc61d..f215b16732 100644 --- a/package-lock.json +++ b/package-lock.json @@ -112,7 +112,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/resources": "^1.10.1", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.0.0", @@ -48028,7 +48028,7 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/contrib-test-utils": "^0.38.0", "@opentelemetry/resources": "^1.10.1", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/sinon": "10.0.18", From cf25c50362900c177cecf4ef58a5f79c43418898 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 17:01:55 -0400 Subject: [PATCH 02/13] chore(resource-detector-instana): use exported strings for attributes (#2051) Use exported strings for Semantic Resource Attributes --- .../opentelemetry-resource-detector-instana/README.md | 4 ++-- .../opentelemetry-resource-detector-instana/package.json | 2 +- .../src/detectors/InstanaAgentDetector.ts | 9 ++++++--- .../test/InstanaAgentDetectorIntegrationTest.test.ts | 6 +++--- package-lock.json | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-instana/README.md b/detectors/node/opentelemetry-resource-detector-instana/README.md index fef7b05bbd..203b5a2280 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/README.md +++ b/detectors/node/opentelemetry-resource-detector-instana/README.md @@ -26,12 +26,12 @@ import { processDetector, envDetector, } from "@opentelemetry/resources"; -import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions"; +import { SEMRESATTRS_SERVICE_NAME } from "@opentelemetry/semantic-conventions"; import { NodeSDK } from "@opentelemetry/sdk-node"; import { instanaAgentDetector } from "@opentelemetry/resource-detector-instana"; const globalResource = new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: "TestService", + [SEMRESATTRS_SERVICE_NAME]: "TestService", }); const sdk = new NodeSDK({ diff --git a/detectors/node/opentelemetry-resource-detector-instana/package.json b/detectors/node/opentelemetry-resource-detector-instana/package.json index dd4e3391c7..2bc2b34f36 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/package.json +++ b/detectors/node/opentelemetry-resource-detector-instana/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" diff --git a/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts b/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts index e036523240..ed0a11284c 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts @@ -15,7 +15,10 @@ */ import { Detector, Resource, IResource } from '@opentelemetry/resources'; import { diag } from '@opentelemetry/api'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMRESATTRS_PROCESS_PID, + SEMRESATTRS_SERVICE_INSTANCE_ID, +} from '@opentelemetry/semantic-conventions'; import * as http from 'http'; class InstanaAgentDetector implements Detector { @@ -32,8 +35,8 @@ class InstanaAgentDetector implements Detector { const data = await this._retryHandler(host, port, 0); return new Resource({ - [SemanticResourceAttributes.PROCESS_PID]: data.pid, - [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: data.agentUuid, + [SEMRESATTRS_PROCESS_PID]: data.pid, + [SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid, }); } diff --git a/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts b/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts index ee8124f3cc..e99aa78487 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts +++ b/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts @@ -21,7 +21,7 @@ import { processDetector, envDetector, } from '@opentelemetry/resources'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; import { NodeSDK } from '@opentelemetry/sdk-node'; import { instanaAgentDetector } from '../src'; @@ -54,7 +54,7 @@ describe('[Integration] instanaAgentDetector', () => { const serviceName = 'TestService'; const globalResource = new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: serviceName, + [SEMRESATTRS_SERVICE_NAME]: serviceName, }); const sdk = new NodeSDK({ @@ -93,7 +93,7 @@ describe('[Integration] instanaAgentDetector', () => { const serviceName = 'TestService'; const globalResource = new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: serviceName, + [SEMRESATTRS_SERVICE_NAME]: serviceName, }); const sdk = new NodeSDK({ diff --git a/package-lock.json b/package-lock.json index f215b16732..856082a284 100644 --- a/package-lock.json +++ b/package-lock.json @@ -250,7 +250,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -48135,7 +48135,7 @@ "@opentelemetry/contrib-test-utils": "^0.38.0", "@opentelemetry/resources": "^1.0.0", "@opentelemetry/sdk-node": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/semver": "7.5.3", From 4da02680b6441e0662f21f690714097e63076fa7 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 17:03:09 -0400 Subject: [PATCH 03/13] chore: update readme for gcp resource detector (#2062) Update README of GCP Resource Detector to clarify the source of the data and add semantic conventions. Part Of #2055 Part Of #2025 --- .../README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/detectors/node/opentelemetry-resource-detector-gcp/README.md b/detectors/node/opentelemetry-resource-detector-gcp/README.md index 5262d02c33..5eee1f8820 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/README.md +++ b/detectors/node/opentelemetry-resource-detector-gcp/README.md @@ -27,6 +27,24 @@ const resource = await detectResources({ const tracerProvider = new NodeTracerProvider({ resource }); ``` +## Available detectors + +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + +### GCP Detector + +| Resource Attribute | Description | +|-------------------------|---------------------------------------------------------------| +| cloud.account.id | Value of `project-id` from GCP Metadata project | +| cloud.availability_zone | Value of `zone` from GCP Metadata instance | +| cloud.provider | The cloud provider. In this context, it's always "gcp" | +| container.name | Value of Environment Variable `CONTAINER_NAME` | +| host.id | Value of `id` from GCP Metadata instance | +| host.name | Value of `hostname` from GCP Metadata instance | +| k8s.cluster.name | Value of `attributes/cluster-name` from GCP Metadata instance | +| k8s.namespace.name | Value of Environment Variable `NAMESPACE` | +| k8s.pod.name | Value of Environment Variable `HOSTNAME` | + ## Useful links - [GCP Metadata Documentation][] From 1a7b87a200b84b1df10f0a5b56ce034676277f51 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 18:42:45 -0400 Subject: [PATCH 04/13] chore(test-utils): update semantic resource attributes (#2080) Update Semantic Resource Attributes Part Of #2025 --- package-lock.json | 4 +- packages/opentelemetry-test-utils/README.md | 4 + .../opentelemetry-test-utils/package.json | 2 +- .../src/instrumentations/index.ts | 4 +- .../src/resource-assertions.ts | 84 ++++++++++++------- 5 files changed, 64 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index 856082a284..eef1558af7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36772,7 +36772,7 @@ "@opentelemetry/sdk-node": "^0.50.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -45796,7 +45796,7 @@ "@opentelemetry/sdk-node": "^0.50.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/node": "18.6.5", "typescript": "4.4.4" } diff --git a/packages/opentelemetry-test-utils/README.md b/packages/opentelemetry-test-utils/README.md index 5820ef175e..62219eb7c3 100644 --- a/packages/opentelemetry-test-utils/README.md +++ b/packages/opentelemetry-test-utils/README.md @@ -65,6 +65,10 @@ it('some test', () => { That's it - supper short and easy. +## Semantic Conventions + +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/packages/opentelemetry-test-utils/package.json b/packages/opentelemetry-test-utils/package.json index 21162672d0..0b77a8acbf 100644 --- a/packages/opentelemetry-test-utils/package.json +++ b/packages/opentelemetry-test-utils/package.json @@ -51,6 +51,6 @@ "@opentelemetry/sdk-node": "^0.50.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" } } diff --git a/packages/opentelemetry-test-utils/src/instrumentations/index.ts b/packages/opentelemetry-test-utils/src/instrumentations/index.ts index 0a8f456236..b480032e8e 100644 --- a/packages/opentelemetry-test-utils/src/instrumentations/index.ts +++ b/packages/opentelemetry-test-utils/src/instrumentations/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { Resource } from '@opentelemetry/resources'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; import { getInstrumentation } from './instrumentation-singleton'; import { registerInstrumentationTestingProvider } from './otel-default-provider'; import { resetMemoryExporter } from './otel-provider-api'; @@ -40,7 +40,7 @@ export const mochaHooks = { } const provider = registerInstrumentationTestingProvider({ resource: new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: serviceName, + [SEMRESATTRS_SERVICE_NAME]: serviceName, }), }); getInstrumentation()?.setTracerProvider(provider); diff --git a/packages/opentelemetry-test-utils/src/resource-assertions.ts b/packages/opentelemetry-test-utils/src/resource-assertions.ts index fb179fb40e..eb248d41d8 100644 --- a/packages/opentelemetry-test-utils/src/resource-assertions.ts +++ b/packages/opentelemetry-test-utils/src/resource-assertions.ts @@ -19,6 +19,32 @@ import * as assert from 'assert'; import { Resource } from '@opentelemetry/resources'; import { SemanticResourceAttributes, + SEMRESATTRS_CLOUD_ACCOUNT_ID, + SEMRESATTRS_CLOUD_AVAILABILITY_ZONE, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_CONTAINER_ID, + SEMRESATTRS_CONTAINER_IMAGE_NAME, + SEMRESATTRS_CONTAINER_IMAGE_TAG, + SEMRESATTRS_CONTAINER_NAME, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_HOST_IMAGE_ID, + SEMRESATTRS_HOST_IMAGE_NAME, + SEMRESATTRS_HOST_IMAGE_VERSION, + SEMRESATTRS_HOST_NAME, + SEMRESATTRS_HOST_TYPE, + SEMRESATTRS_K8S_CLUSTER_NAME, + SEMRESATTRS_K8S_DEPLOYMENT_NAME, + SEMRESATTRS_K8S_NAMESPACE_NAME, + SEMRESATTRS_K8S_POD_NAME, + SEMRESATTRS_PROCESS_COMMAND, + SEMRESATTRS_PROCESS_COMMAND_LINE, + SEMRESATTRS_PROCESS_EXECUTABLE_NAME, + SEMRESATTRS_PROCESS_PID, + SEMRESATTRS_SERVICE_INSTANCE_ID, + SEMRESATTRS_SERVICE_NAME, + SEMRESATTRS_SERVICE_NAMESPACE, + SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_TELEMETRY_SDK_LANGUAGE, SEMRESATTRS_TELEMETRY_SDK_NAME, SEMRESATTRS_TELEMETRY_SDK_VERSION, @@ -42,22 +68,22 @@ export const assertCloudResource = ( assertHasOneLabel('CLOUD', resource); if (validations.provider) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CLOUD_PROVIDER], + resource.attributes[SEMRESATTRS_CLOUD_PROVIDER], validations.provider ); if (validations.accountId) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID], + resource.attributes[SEMRESATTRS_CLOUD_ACCOUNT_ID], validations.accountId ); if (validations.region) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CLOUD_REGION], + resource.attributes[SEMRESATTRS_CLOUD_REGION], validations.region ); if (validations.zone) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE], + resource.attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE], validations.zone ); }; @@ -80,22 +106,22 @@ export const assertContainerResource = ( assertHasOneLabel('CONTAINER', resource); if (validations.name) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CONTAINER_NAME], + resource.attributes[SEMRESATTRS_CONTAINER_NAME], validations.name ); if (validations.id) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CONTAINER_ID], + resource.attributes[SEMRESATTRS_CONTAINER_ID], validations.id ); if (validations.imageName) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_NAME], + resource.attributes[SEMRESATTRS_CONTAINER_IMAGE_NAME], validations.imageName ); if (validations.imageTag) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_TAG], + resource.attributes[SEMRESATTRS_CONTAINER_IMAGE_TAG], validations.imageTag ); }; @@ -120,32 +146,32 @@ export const assertHostResource = ( assertHasOneLabel('HOST', resource); if (validations.id) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.HOST_ID], + resource.attributes[SEMRESATTRS_HOST_ID], validations.id ); if (validations.name) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.HOST_NAME], + resource.attributes[SEMRESATTRS_HOST_NAME], validations.name ); if (validations.hostType) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.HOST_TYPE], + resource.attributes[SEMRESATTRS_HOST_TYPE], validations.hostType ); if (validations.imageName) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.HOST_IMAGE_NAME], + resource.attributes[SEMRESATTRS_HOST_IMAGE_NAME], validations.imageName ); if (validations.imageId) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.HOST_IMAGE_ID], + resource.attributes[SEMRESATTRS_HOST_IMAGE_ID], validations.imageId ); if (validations.imageVersion) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.HOST_IMAGE_VERSION], + resource.attributes[SEMRESATTRS_HOST_IMAGE_VERSION], validations.imageVersion ); }; @@ -168,22 +194,22 @@ export const assertK8sResource = ( assertHasOneLabel('K8S', resource); if (validations.clusterName) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME], + resource.attributes[SEMRESATTRS_K8S_CLUSTER_NAME], validations.clusterName ); if (validations.namespaceName) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME], + resource.attributes[SEMRESATTRS_K8S_NAMESPACE_NAME], validations.namespaceName ); if (validations.podName) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.K8S_POD_NAME], + resource.attributes[SEMRESATTRS_K8S_POD_NAME], validations.podName ); if (validations.deploymentName) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME], + resource.attributes[SEMRESATTRS_K8S_DEPLOYMENT_NAME], validations.deploymentName ); }; @@ -211,17 +237,17 @@ export const assertTelemetrySDKResource = ( if (validations.name) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_NAME], + resource.attributes[SEMRESATTRS_TELEMETRY_SDK_NAME], validations.name ); if (validations.language) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE], + resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE], validations.language ); if (validations.version) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_VERSION], + resource.attributes[SEMRESATTRS_TELEMETRY_SDK_VERSION], validations.version ); }; @@ -242,21 +268,21 @@ export const assertServiceResource = ( } ) => { assert.strictEqual( - resource.attributes[SemanticResourceAttributes.SERVICE_NAME], + resource.attributes[SEMRESATTRS_SERVICE_NAME], validations.name ); assert.strictEqual( - resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], validations.instanceId ); if (validations.namespace) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE], + resource.attributes[SEMRESATTRS_SERVICE_NAMESPACE], validations.namespace ); if (validations.version) assert.strictEqual( - resource.attributes[SemanticResourceAttributes.SERVICE_VERSION], + resource.attributes[SEMRESATTRS_SERVICE_VERSION], validations.version ); }; @@ -277,24 +303,24 @@ export const assertProcessResource = ( } ) => { assert.strictEqual( - resource.attributes[SemanticResourceAttributes.PROCESS_PID], + resource.attributes[SEMRESATTRS_PROCESS_PID], validations.pid ); if (validations.name) { assert.strictEqual( - resource.attributes[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME], + resource.attributes[SEMRESATTRS_PROCESS_EXECUTABLE_NAME], validations.name ); } if (validations.command) { assert.strictEqual( - resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND], + resource.attributes[SEMRESATTRS_PROCESS_COMMAND], validations.command ); } if (validations.commandLine) { assert.strictEqual( - resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND_LINE], + resource.attributes[SEMRESATTRS_PROCESS_COMMAND_LINE], validations.commandLine ); } From 6bd62a27a81564b4518a15732967cdebc73d6e54 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 18:43:03 -0400 Subject: [PATCH 05/13] chore(resource-detector-gcp): use exported strings for attributes (#2050) Use exported strings for Semantic Resource Attributes and Cloud Provider Values. Signed-off-by: maryliag --- .../package.json | 2 +- .../src/detectors/GcpDetector.ts | 31 ++++++++++++------- package-lock.json | 4 +-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-gcp/package.json b/detectors/node/opentelemetry-resource-detector-gcp/package.json index 6a3df59b58..cc070b0c5b 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/package.json +++ b/detectors/node/opentelemetry-resource-detector-gcp/package.json @@ -56,7 +56,7 @@ "dependencies": { "@opentelemetry/core": "^1.0.0", "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "gcp-metadata": "^6.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp#readme" diff --git a/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts b/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts index 206bb4d1d3..142885eaa6 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts @@ -24,8 +24,16 @@ import { } from '@opentelemetry/resources'; import { getEnv } from '@opentelemetry/core'; import { - CloudProviderValues, - SemanticResourceAttributes, + CLOUDPROVIDERVALUES_GCP, + SEMRESATTRS_CLOUD_ACCOUNT_ID, + SEMRESATTRS_CLOUD_AVAILABILITY_ZONE, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CONTAINER_NAME, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_HOST_NAME, + SEMRESATTRS_K8S_CLUSTER_NAME, + SEMRESATTRS_K8S_NAMESPACE_NAME, + SEMRESATTRS_K8S_POD_NAME, } from '@opentelemetry/semantic-conventions'; /** @@ -58,12 +66,11 @@ class GcpDetector implements Detector { ]); const attributes: ResourceAttributes = {}; - attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID] = projectId; - attributes[SemanticResourceAttributes.HOST_ID] = instanceId; - attributes[SemanticResourceAttributes.HOST_NAME] = hostname; - attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE] = zoneId; - attributes[SemanticResourceAttributes.CLOUD_PROVIDER] = - CloudProviderValues.GCP; + attributes[SEMRESATTRS_CLOUD_ACCOUNT_ID] = projectId; + attributes[SEMRESATTRS_HOST_ID] = instanceId; + attributes[SEMRESATTRS_HOST_NAME] = hostname; + attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE] = zoneId; + attributes[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_GCP; if (getEnv().KUBERNETES_SERVICE_HOST) this._addK8sAttributes(attributes, clusterName); @@ -78,10 +85,10 @@ class GcpDetector implements Detector { ): void { const env = getEnv(); - attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME] = clusterName; - attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME] = env.NAMESPACE; - attributes[SemanticResourceAttributes.K8S_POD_NAME] = env.HOSTNAME; - attributes[SemanticResourceAttributes.CONTAINER_NAME] = env.CONTAINER_NAME; + attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName; + attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE; + attributes[SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME; + attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME; } /** Gets project id from GCP project metadata. */ diff --git a/package-lock.json b/package-lock.json index eef1558af7..ba9b0c9ab0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -183,7 +183,7 @@ "dependencies": { "@opentelemetry/core": "^1.0.0", "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "gcp-metadata": "^6.0.0" }, "devDependencies": { @@ -48083,7 +48083,7 @@ "@opentelemetry/contrib-test-utils": "^0.38.0", "@opentelemetry/core": "^1.0.0", "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/semver": "7.5.3", From 10c0c93e58d7921119cda7d454ee13b606638904 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 18:45:35 -0400 Subject: [PATCH 06/13] docs(resource-detector-container): update readme for container resource detector (#2061) Refs: #2055 Signed-off-by: maryliag --- .../README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/detectors/node/opentelemetry-resource-detector-container/README.md b/detectors/node/opentelemetry-resource-detector-container/README.md index 8e8baa4e45..f798241a28 100644 --- a/detectors/node/opentelemetry-resource-detector-container/README.md +++ b/detectors/node/opentelemetry-resource-detector-container/README.md @@ -28,7 +28,15 @@ const tracerProvider = new NodeTracerProvider({ resource }); ## Available detectors -- `containerDetector`: Populates `container.id` for processes running on containers supporting : docker( cgroup v1 or v2 ) or with containerd +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + +### ContainerDetector + +Populates `container.id` for processes running on containers supporting : docker( cgroup v1 or v2 ) or with containerd + +| Resource Attribute | Description | +|--------------------|------------------------------------------------------------------------------------------------------------------------------------------| +| `container.id` | Value parsed from file `/proc/self/cgroup` (cgroup v1). If it doesn't exist, parse the value from file `/proc/self/mountinfo` (cgroup v2)| ## Useful links From 69e8077caa2949d2243ccd998a66b88c900b7744 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 18:46:46 -0400 Subject: [PATCH 07/13] docs(resource-detector-aws): update readme for aws resource detector (#2060) Refs: #2055 Signed-off-by: maryliag --- .../README.md | 85 +++++++++++++++++-- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-aws/README.md b/detectors/node/opentelemetry-resource-detector-aws/README.md index 690c25700d..aeb075c237 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/README.md +++ b/detectors/node/opentelemetry-resource-detector-aws/README.md @@ -33,13 +33,84 @@ const tracerProvider = new NodeTracerProvider({ resource }); ## Available detectors -- `awsBeanstalkDetector`: Populates `service` for processes running on [AWS Elastic Beanstalk](https://aws.amazon.com/elasticbeanstalk/) -- `awsEc2Detector`: Populates `cloud` and `host` for processes running on [Amazon EC2](https://aws.amazon.com/ec2/), including abstractions such as ECS on EC2. Notably, it does not populate anything on AWS Fargate -- `awsEcsDetector`: Populates `container` for containers running on [Amazon ECS](https://aws.amazon.com/ecs/) -- `awsEksDetector`: Populates `container` and `k8s.cluster_name` for containers running on [Amazon EKS](https://aws.amazon.com/eks/) - - `k8s.cluster_name` is not always available depending on the configuration of CloudWatch monitoring for the EKS cluster -- `awsLambdaDetector`: Populates `faas` and `cloud` for functions running on [AWS Lambda](https://aws.amazon.com/lambda/) - - `faas.id` is currently not populated as it is not provided by the runtime at startup +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + +### AWS Beanstalk Detector + +Populates `service` for processes running on [AWS Elastic Beanstalk](https://aws.amazon.com/elasticbeanstalk/) + +| Resource Attribute | Description | +|---------------------|--------------------------------------------------------------------------| +| cloud.platform | The cloud platform. In this context, it's always "aws_elastic_beanstalk" | +| cloud.provider | The cloud provider. In this context, it's always "aws" | +| service.instance.id | Value of `deployment_id` from config file `environment.conf` | +| service.name | The service name. In this context, it's always "aws_elastic_beanstalk" | +| service.namespace | Value of `environment_name` from config file `environment.conf` | +| service.version | Value of `version_label` from config file `environment.conf` | + +### AWS EC2 Detector + +Populates `cloud` and `host` for processes running on [Amazon EC2](https://aws.amazon.com/ec2/), including abstractions such as ECS on EC2. Notably, it does not populate anything on AWS Fargate. + +| Resource Attribute | Description | +|-------------------------|---------------------------------------------------------------------------------------| +| cloud.account.id | Value of `accountId` from `/latest/dynamic/instance-identity/document` request | +| cloud.availability_zone | Value of `availabilityZone` from `/latest/dynamic/instance-identity/document` request | +| cloud.platform | The cloud platform. In this context, it's always "aws_ec2" | +| cloud.provider | The cloud provider. In this context, it's always "aws" | +| cloud.region | Value of `region` from `/latest/dynamic/instance-identity/document` request | +| host.id | Value of `instanceId` from `/latest/dynamic/instance-identity/document` request | +| host.name | Value of `hostname` from `/latest/dynamic/instance-identity/document` request | +| host.type | Value of `instanceType` from `/latest/dynamic/instance-identity/document` request | + +### AWS ECS Detector + +Populates `container` for containers running on [Amazon ECS](https://aws.amazon.com/ecs/). + +| Resource Attribute | Description | +|-------------------------|----------------------------------------------------------------------------------------| +| aws.ecs.container.arn | Value of `ContainerARN` from the request to the metadata Uri. The Metadata Uri is stored on the Environment Variable `ECS_CONTAINER_METADATA_URI_V4` | +| aws.ecs.cluster.arn | Value in the format `${baseArn}:cluster/${cluster}`, with `baseArn` and `cluster` from a `ECS_CONTAINER_METADATA_URI_V4/task` request, with values from `TaskARN` and `Cluster` respectively | +| aws.ecs.launchtype | Value of `LaunchType` from `ECS_CONTAINER_METADATA_URI_V4/task` request | +| aws.ecs.task.arn | Value of `TaskARN` from `ECS_CONTAINER_METADATA_URI_V4/task` request | +| aws.ecs.task.family | Value of `Family` from `ECS_CONTAINER_METADATA_URI_V4/task` request | +| aws.ecs.task.revision | Value of `Revision` from `ECS_CONTAINER_METADATA_URI_V4/task` request | +| aws.log.group.arns | Value on format `arn:aws:logs:${logsRegion}:${awsAccount}:log-group:${logsGroupName}`, with `logsRegions` and `logsGroupName` from logs metadata, values of `awslogs-region` and `awslogs-group` respectively, and `awsAccount` parsed value from the `TaskARN`. Logs metadata values come from `LogOptions` on `ECS_CONTAINER_METADATA_URI_V4` request | +| aws.log.group.names | Value of `awslogs-group` from logs metadata. Logs metadata values come from `LogOptions` on `ECS_CONTAINER_METADATA_URI_V4` request | +| aws.log.stream.arns | Value on format `arn:aws:logs:${logsRegion}:${awsAccount}:log-group:${logsGroupName}:log-stream:${logsStreamName}`, with `logsRegions`, `logsGroupName` and `logsStreamName` from logs metadata, values of `awslogs-region`, `awslogs-group` and `awslogs-stream` respectively, and `awsAccount` parsed value from the `TaskARN` | +| aws.log.stream.names | Value of `awslogs-stream` from logs metadata | +| cloud.account.id | Parsed value from the `TaskARN` | +| cloud.availability_zone | Value of `AvailabilityZone` from `ECS_CONTAINER_METADATA_URI_V4/task` request. This value is not available in all Fargate runtimes | +| 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` | +| container.name | The hostname of the operating system | + +### AWS EKS Detector + +Populates `container` and `k8s.cluster_name` for containers running on [Amazon EKS](https://aws.amazon.com/eks/). +`k8s.cluster_name` is not always available depending on the configuration of CloudWatch monitoring for the EKS cluster. + +| Resource Attribute | Description | +|--------------------|-----------------------------------------------------------------------------------------------------| +| cloud.platform | The cloud platform. In this context, it's always "aws_eks" | +| cloud.provider | The cloud provider. In this context, it's always "aws" | +| container.id | Value from config file `/proc/self/cgroup` | +| k8s.cluster.name | Value of `cluster.name` from `/api/v1/namespaces/amazon-cloudwatch/configmaps/cluster-info` request | + +### AWS Lambda Detector + +Populates `faas` and `cloud` for functions running on [AWS Lambda](https://aws.amazon.com/lambda/). +`faas.id` is currently not populated as it is not provided by the runtime at startup. + +| Resource Attribute | Description | +|--------------------|---------------------------------------------------------------------| +| cloud.platform | The cloud platform. In this context, it's always "aws_lambda" | +| cloud.provider | The cloud provider. In this context, it's always "aws" | +| cloud.region | Value of Process Environment Variable `AWS_REGION` | +| faas.name | Value of Process Environment Variable `AWS_LAMBDA_FUNCTION_NAME` | +| faas.version | Value of Process Environment Variable `AWS_LAMBDA_FUNCTION_VERSION` | ## Useful links From 13b49b3f3b26b1405eb3be62d0985f8874f898b2 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 19:02:27 -0400 Subject: [PATCH 08/13] docs(resource-detector-instana): update readme for instana resource detector (#2063) Refs: #2055 Signed-off-by: maryliag --- .../opentelemetry-resource-detector-instana/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/detectors/node/opentelemetry-resource-detector-instana/README.md b/detectors/node/opentelemetry-resource-detector-instana/README.md index 203b5a2280..8845808cdf 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/README.md +++ b/detectors/node/opentelemetry-resource-detector-instana/README.md @@ -42,6 +42,17 @@ const sdk = new NodeSDK({ sdk.start() ``` +## Available detectors + +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + +### Instana Agent Detector + +| Resource Attribute | Description | +|------------------------------|--------------------------------------------------------------------------------------------------------------------------| +| process.pid | The ID of the process. Value of parameter `pid` from the response to a request to `/com.instana.plugin.nodejs.discovery` | +| service.instance.id | The agent UUID. Value of parameter `agentUuid` from the response to a request to `/com.instana.plugin.nodejs.discovery` | + ## Useful links - For more information about Instana Agent, visit: From 88514d96d9d6d48d56ca0e79b9214303593a64f7 Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 19:57:54 -0400 Subject: [PATCH 09/13] docs(resource-detector-azure): update readme for azure resource detector (#2057) Update README of Azure Resource Detector to clarify the source of the data and also remove values from the table that were not actually being set. Add Semantic conventions to README Refs: #2055 Refs: #2025 Signed-off-by: maryliag Co-authored-by: Jamie Danielson Co-authored-by: Trent Mick --- .../README.md | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-azure/README.md b/detectors/node/opentelemetry-resource-detector-azure/README.md index ea4efc6862..c900a48663 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/README.md +++ b/detectors/node/opentelemetry-resource-detector-azure/README.md @@ -27,48 +27,48 @@ const tracerProvider = new NodeTracerProvider({ resource }); ## Available Detectors +This package implements Semantic Convention [Version 1.19.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.19.0/semantic_conventions/README.md). + ### App Service Resource Detector -| Attribute | Description | +| Resource Attribute | Description | |-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| azure.app.service.stamp | The specific "stamp" cluster within Azure where the App Service is running, e.g., "waws-prod-sn1-001". | +| azure.app.service.stamp | The specific "stamp" cluster within Azure where the App Service is running, e.g., "waws-prod-sn1-001". Value of Process Environment Variable `APP_SERVICE_ATTRIBUTE_ENV_VARS`. | | cloud.platform | The cloud platform. Here, it's always "azure_app_service". | | cloud.provider | The cloud service provider. In this context, it's always "azure". | -| cloud.resource_id | The Azure Resource Manager URI uniquely identifying the Azure App Service. Typically in the format "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Web/sites/{siteName}". | -| cloud.region | The Azure region where the App Service is hosted, e.g., "East US", "West Europe", etc. | -| deployment.environment | The deployment slot where the Azure App Service is running, such as "staging", "production", etc. | -| host.id | The primary hostname for the app, excluding any custom hostnames. | -| service.instance.id | The specific instance of the Azure App Service, useful in a scaled-out configuration. | -| service.name | The name of the Azure App Service. | +| cloud.region | The Azure region where the App Service is hosted, e.g., "East US", "West Europe", etc. Value of Process Environment Variable `REGION_NAME`. | +| cloud.resource_id | The Azure Resource Manager URI uniquely identifying the Azure App Service. Typically in the format `/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Web/sites/{siteName}`. | +| deployment.environment | The deployment slot where the Azure App Service is running, such as "staging", "production", etc. Value of Process Environment Variable `WEBSITE_SLOT_NAME`. | +| host.id | The primary hostname for the app, excluding any custom hostnames. Value of Process Environment Variable `WEBSITE_HOSTNAME`. | +| service.instance.id | The specific instance of the Azure App Service, useful in a scaled-out configuration. Value of Process Environment Variable `WEBSITE_INSTANCE_ID`. | +| service.name | The name of the Azure App Service. Value of Process Environment Variable `WEBSITE_SITE_NAME`. | ### VM Resource Detector -| Attribute | Description | -|--------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| azure.vm.scaleset.name | The name of the Virtual Machine Scale Set if the VM is part of one. | -| azure.vm.sku | The SKU of the Azure Virtual Machine's operating system. For instance, for a VM running Windows Server 2019 Datacenter edition, this value would be "2019-Datacenter". | -| cloud.platform | The cloud platform, which is always set to "azure_vm" in this context. | -| cloud.provider | The cloud service provider, which is always set to "azure" in this context. | -| cloud.region | The Azure region where the Virtual Machine is hosted, such as "East US", "West Europe", etc. | -| cloud.resource_id | The Azure Resource Manager URI uniquely identifying the Azure Virtual Machine. It typically follows this format: "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/virtualMachines/{vmName}". | -| host.id | A unique identifier for the VM host, for instance, "02aab8a4-74ef-476e-8182-f6d2ba4166a6". | -| host.name | The name of the host machine. | -| host.type | The size of the VM instance, for example, "Standard_D2s_v3". | -| os.type | The type of operating system running on the VM, such as "Linux" or "Windows". | -| os.version | The version of the operating system running on the VM. | -| service.instance.id | An identifier for a specific instance of the service running on the Azure VM, for example, "02aab8a4-74ef-476e-8182-f6d2ba4166a6". | +| Resource Attribute | Description | +|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| azure.vm.scaleset.name | The name of the Virtual Machine Scale Set if the VM is part of one. Value from `vmScaleSetName` key on `/metadata/instance/compute` request. | +| azure.vm.sku | The SKU of the Azure Virtual Machine's operating system. For instance, for a VM running Windows Server 2019 Datacenter edition, this value would be "2019-Datacenter". Value from `sku` key on `/metadata/instance/compute` request. | +| cloud.platform | The cloud platform, which is always set to "azure_vm" in this context. | +| cloud.provider | The cloud service provider, which is always set to "azure" in this context. | +| cloud.region | The Azure region where the Virtual Machine is hosted, such as "East US", "West Europe", etc. Value from `location` key on `/metadata/instance/compute` request. | +| cloud.resource_id | The Azure Resource Manager URI uniquely identifying the Azure Virtual Machine. It typically follows this format: `/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/virtualMachines/{vmName}`. Value from `resourceId` key on `/metadata/instance/compute` request.| +| host.id | A unique identifier for the VM host, for instance, "02aab8a4-74ef-476e-8182-f6d2ba4166a6". Value from `vmId` key on `/metadata/instance/compute` request. | +| host.name | The name of the host machine. Value from `name` key on `/metadata/instance/compute` request. | +| host.type | The size of the VM instance, for example, "Standard_D2s_v3". Value from `vmSize` key on `/metadata/instance/compute` request. | +| os.version | The version of the operating system running on the VM. Value from `version` key on `/metadata/instance/compute` request. | ### Azure Functions Resource Detector -| Attribute | Description | -|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| cloud.platform | The cloud platform. Here, it's always "azure_functions". | -| cloud.provider | The cloud service provider. In this context, it's always "azure". | -| cloud.region | The Azure region where the Azure Function is hosted, e.g., "East US", "West Europe", etc. | -| faas.instance | The specific instance of the Azure App Service, useful in a scaled-out configuration. | -| faas.name | The name of the Azure App Service. | -| faas.version | The version of the Azure Function being executed, e.g., "~4". | -| faas.max_memory | The amount of memory available to the Azure Function expressed in MiB. | +| Resource Attribute | Description | +|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------| +| cloud.platform | The cloud platform. Here, it's always "azure_functions". | +| cloud.provider | The cloud service provider. In this context, it's always "azure". | +| cloud.region | The Azure region where the Azure Function is hosted, e.g., "East US", "West Europe", etc. Value of Process Environment Variable `REGION_NAME`. | +| faas.instance | The specific instance of the Azure App Service, useful in a scaled-out configuration. Value from Process Environment Variable `WEBSITE_INSTANCE_ID`. | +| faas.max_memory | The amount of memory available to the Azure Function expressed in MiB. value from Process Environment Variable `WEBSITE_MEMORY_LIMIT_MB`. | +| faas.name | The name of the Azure App Service. Value from Process Environment Variable `WEBSITE_SITE_NAME`. | +| faas.version | The version of the Azure Function being executed, e.g., "~4". value from Process Environment Variable `FUNCTIONS_EXTENSION_VERSION`. | ## Useful links From eaa99f8fd0d9ac1b454d0672e579461d06330bce Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Tue, 9 Apr 2024 19:59:06 -0400 Subject: [PATCH 10/13] chore: update readme for github resource detector (#2064) Update README of GitHub Resource Detector to clarify the source of the data. Refs: #2055 Signed-off-by: maryliag --- .../README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/detectors/node/opentelemetry-resource-detector-github/README.md b/detectors/node/opentelemetry-resource-detector-github/README.md index 8f2066af71..31cdf85839 100644 --- a/detectors/node/opentelemetry-resource-detector-github/README.md +++ b/detectors/node/opentelemetry-resource-detector-github/README.md @@ -33,6 +33,21 @@ async function run() { run() ``` +## Available detectors + +### GitHub Detector + +| Resource Attribute | Description | +|--------------------|-----------------------------------------------------------| +| github.actor | Value of Process Environment Variable `GITHUB_ACTOR` | +| github.base_ref | Value of Process Environment Variable `GITHUB_BASE_REF` | +| github.head_ref | Value of Process Environment Variable `GITHUB_HEAD_REF` | +| github.ref | Value of Process Environment Variable `GITHUB_REF` | +| github.run_id | Value of Process Environment Variable `GITHUB_RUN_ID` | +| github.run_number | Value of Process Environment Variable `GITHUB_RUN_NUMBER` | +| github.sha | Value of Process Environment Variable `GITHUB_SHA` | +| github.workflow | Value of Process Environment Variable `GITHUB_WORKFLOW` | + ## Useful links - [GitHub Action Environment Variables](https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables) From a172f8affa2d54b13542c3dfc103dd54ccf031ad Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Wed, 10 Apr 2024 12:45:30 +0200 Subject: [PATCH 11/13] fix(instrumentation-ioredis): drop @types/ioredis dependency (#2069) --- package-lock.json | 8 +++++--- .../opentelemetry-instrumentation-ioredis/package.json | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index ba9b0c9ab0..2386287d84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10574,6 +10574,7 @@ "version": "4.28.10", "resolved": "https://registry.npmjs.org/@types/ioredis/-/ioredis-4.28.10.tgz", "integrity": "sha512-69LyhUgrXdgcNDv7ogs1qXZomnfOEnSmrmMFqKgt1XMJxmoOSG/u3wYy13yACIfKuMJ8IhKgHafDO3sx19zVQQ==", + "dev": true, "dependencies": { "@types/node": "*" } @@ -37989,8 +37990,7 @@ "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/redis-common": "^0.36.1", - "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/ioredis4": "npm:@types/ioredis@^4.28.10" + "@opentelemetry/semantic-conventions": "^1.0.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -37998,6 +37998,7 @@ "@opentelemetry/contrib-test-utils": "^0.38.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", + "@types/ioredis4": "npm:@types/ioredis@4.28.10", "@types/mocha": "7.0.2", "@types/node": "18.6.5", "@types/sinon": "10.0.18", @@ -46475,7 +46476,7 @@ "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/ioredis4": "npm:@types/ioredis@^4.28.10", + "@types/ioredis4": "npm:@types/ioredis@4.28.10", "@types/mocha": "7.0.2", "@types/node": "18.6.5", "@types/sinon": "10.0.18", @@ -49647,6 +49648,7 @@ "version": "npm:@types/ioredis@4.28.10", "resolved": "https://registry.npmjs.org/@types/ioredis/-/ioredis-4.28.10.tgz", "integrity": "sha512-69LyhUgrXdgcNDv7ogs1qXZomnfOEnSmrmMFqKgt1XMJxmoOSG/u3wYy13yACIfKuMJ8IhKgHafDO3sx19zVQQ==", + "dev": true, "requires": { "@types/node": "*" } diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index 688c37abba..4ecc2eb1b3 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -63,13 +63,13 @@ "sinon": "15.2.0", "test-all-versions": "6.1.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "@types/ioredis4": "npm:@types/ioredis@4.28.10" }, "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/redis-common": "^0.36.1", - "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/ioredis4": "npm:@types/ioredis@^4.28.10" + "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis#readme" } From 66d9cea9c963c03e5e3736b59520cecd27403b22 Mon Sep 17 00:00:00 2001 From: David Luna Date: Wed, 10 Apr 2024 13:10:41 +0200 Subject: [PATCH 12/13] refactor(instr-mongodb): use exported strings for attributes (#2088) * refactor(instr-mongodb): use exported strings for attributes * refactor(instr-mongodb): update README --------- Co-authored-by: Marc Pichler --- package-lock.json | 4 +-- .../README.md | 16 +++++++++++ .../package.json | 2 +- .../src/instrumentation.ts | 27 ++++++++++++------- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2386287d84..e43fb44c4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38126,7 +38126,7 @@ "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/sdk-metrics": "^1.9.1", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -46634,7 +46634,7 @@ "@opentelemetry/sdk-metrics": "^1.9.1", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/bson": "4.0.5", "@types/mocha": "7.0.2", "@types/mongodb": "3.6.20", diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/README.md b/plugins/node/opentelemetry-instrumentation-mongodb/README.md index 07b50e95d2..efec965ee9 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/README.md +++ b/plugins/node/opentelemetry-instrumentation-mongodb/README.md @@ -55,6 +55,22 @@ Mongodb instrumentation has few options available to choose from. You can set th | `responseHook` | `MongoDBInstrumentationExecutionResponseHook` (function) | Function for adding custom attributes from db response | | `dbStatementSerializer` | `DbStatementSerializer` (function) | Custom serializer function for the db.statement tag | +## Semantic Conventions + +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + +Attributes collected: + +| Attribute | Short Description | +| ----------------------- | ------------------------------------------------------------------------------ | +| `db.system` | An identifier for the database management system (DBMS) product being used. | +| `db.connection_string` | The connection string used to connect to the database. | +| `db.name` | This attribute is used to report the name of the database being accessed. | +| `db.operation` | The name of the operation being executed. | +| `db.mongodb.collection` | The collection being accessed within the database stated in `db.name`. | +| `net.peer.name` | Remote hostname or similar. | +| `net.peer.port` | Remote port number. | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/package.json index 967c35c088..f3d704c7da 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/package.json @@ -68,7 +68,7 @@ "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/sdk-metrics": "^1.9.1", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts index 0a1dad9af9..d5239d9706 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts @@ -29,8 +29,15 @@ import { safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MONGODB, + SEMATTRS_DB_CONNECTION_STRING, + SEMATTRS_DB_MONGODB_COLLECTION, + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import { MongoDBInstrumentationConfig, CommandResult } from './types'; import { @@ -898,18 +905,18 @@ export class MongoDBInstrumentation extends InstrumentationBase { ) { // add database related attributes span.setAttributes({ - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MONGODB, - [SemanticAttributes.DB_NAME]: dbName, - [SemanticAttributes.DB_MONGODB_COLLECTION]: dbCollection, - [SemanticAttributes.DB_OPERATION]: operation, - [SemanticAttributes.DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MONGODB, + [SEMATTRS_DB_NAME]: dbName, + [SEMATTRS_DB_MONGODB_COLLECTION]: dbCollection, + [SEMATTRS_DB_OPERATION]: operation, + [SEMATTRS_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`, }); if (host && port) { - span.setAttribute(SemanticAttributes.NET_PEER_NAME, host); + span.setAttribute(SEMATTRS_NET_PEER_NAME, host); const portNumber = parseInt(port, 10); if (!isNaN(portNumber)) { - span.setAttribute(SemanticAttributes.NET_PEER_PORT, portNumber); + span.setAttribute(SEMATTRS_NET_PEER_PORT, portNumber); } } if (!commandObj) return; @@ -921,7 +928,7 @@ export class MongoDBInstrumentation extends InstrumentationBase { safeExecuteInTheMiddle( () => { const query = dbStatementSerializer(commandObj); - span.setAttribute(SemanticAttributes.DB_STATEMENT, query); + span.setAttribute(SEMATTRS_DB_STATEMENT, query); }, err => { if (err) { From 1af49014b8a77d34058750ce2a87bd58211ebe70 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 10 Apr 2024 08:59:18 -0700 Subject: [PATCH 13/13] chore(instr-undici): updates/tweaks for new undici instrumentation (#2085) - set min supported undici to v5.12.0 - 'codecov' npm script was copypasta from core repo - update to same test-all-versions ver as other pkgs in the workspace - update undici to latest (it is a security update) - add label-prs workflow support pkg:instrumentation-undici - reduce number of versions tested with TAV --- .github/component-label-map.yml | 4 + package-lock.json | 282 +----------------- plugins/node/instrumentation-undici/.tav.yml | 8 +- plugins/node/instrumentation-undici/README.md | 4 + .../node/instrumentation-undici/package.json | 7 +- .../node/instrumentation-undici/src/undici.ts | 9 +- .../test/undici.test.ts | 47 +-- 7 files changed, 49 insertions(+), 312 deletions(-) diff --git a/.github/component-label-map.yml b/.github/component-label-map.yml index de2ff8c3ef..d49f02ac12 100644 --- a/.github/component-label-map.yml +++ b/.github/component-label-map.yml @@ -225,6 +225,10 @@ pkg:instrumentation-tedious: - any-glob-to-any-file: - plugins/node/instrumentation-tedious/** - packages/opentelemetry-test-utils/** +pkg:instrumentation-undici: + - changed-files: + - any-glob-to-any-file: + - plugins/node/instrumentation-undici/** pkg:instrumentation-user-interaction: - changed-files: - any-glob-to-any-file: diff --git a/package-lock.json b/package-lock.json index e43fb44c4b..0f7fb562c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34430,9 +34430,9 @@ } }, "node_modules/undici": { - "version": "6.10.1", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.10.1.tgz", - "integrity": "sha512-kSzmWrOx3XBKTgPm4Tal8Hyl3yf+hzlA00SAf4goxv8LZYafKmS6gJD/7Fe5HH/DMNiFTRXvkwhLo7mUn5fuQQ==", + "version": "6.11.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.11.1.tgz", + "integrity": "sha512-KyhzaLJnV1qa3BSHdj4AZ2ndqI0QWPxYzaIOio0WzcEJB9gvuysprJSLtpvc2D9mhR9jPDUk7xlJlZbH2KR5iw==", "dev": true, "engines": { "node": ">=18.0" @@ -37383,7 +37383,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.49.1" + "@opentelemetry/instrumentation": "^0.50.0" }, "devDependencies": { "@opentelemetry/api": "^1.7.0", @@ -37397,10 +37397,10 @@ "rimraf": "5.0.5", "semver": "^7.6.0", "superagent": "8.0.9", - "test-all-versions": "6.0.0", + "test-all-versions": "6.1.0", "ts-mocha": "10.0.0", "typescript": "4.4.4", - "undici": "6.10.1" + "undici": "6.11.1" }, "engines": { "node": ">=14" @@ -37409,137 +37409,6 @@ "@opentelemetry/api": "^1.7.0" } }, - "plugins/node/instrumentation-undici/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "plugins/node/instrumentation-undici/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "plugins/node/instrumentation-undici/node_modules/cli-spinners": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", - "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", - "dev": true, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "plugins/node/instrumentation-undici/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "plugins/node/instrumentation-undici/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "plugins/node/instrumentation-undici/node_modules/is-ci": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz", - "integrity": "sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==", - "dev": true, - "dependencies": { - "ci-info": "^3.2.0" - }, - "bin": { - "is-ci": "bin.js" - } - }, - "plugins/node/instrumentation-undici/node_modules/log-symbols": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", - "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", - "dev": true, - "dependencies": { - "chalk": "^4.1.0", - "is-unicode-supported": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "plugins/node/instrumentation-undici/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "plugins/node/instrumentation-undici/node_modules/test-all-versions": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/test-all-versions/-/test-all-versions-6.0.0.tgz", - "integrity": "sha512-/9wVTBRa7+arvItGinCYy/8+z7sHTsrs9cwEY/xAnzrkSEM7Tp2Cz49ewYZYuO1YYMLqxEaQp2g7Dnns7n7BGA==", - "dev": true, - "dependencies": { - "after-all-results": "^2.0.0", - "ansi-diff-stream": "^1.2.1", - "cli-spinners": "^2.9.2", - "deepmerge": "^4.3.1", - "import-fresh": "^3.3.0", - "is-ci": "^3.0.1", - "js-yaml": "^4.1.0", - "log-symbols": "^4.1.0", - "minimist": "^1.2.8", - "npm-package-versions": "^1.0.1", - "once": "^1.4.0", - "parse-env-string": "^1.0.1", - "resolve": "^1.22.8", - "semver": "^7.5.4", - "spawn-npm-install": "^1.2.0", - "which": "^2.0.2" - }, - "bin": { - "tav": "index.js" - }, - "engines": { - "node": ">=14" - } - }, "plugins/node/opentelemetry-instrumentation-aws-lambda": { "name": "@opentelemetry/instrumentation-aws-lambda", "version": "0.40.0", @@ -38799,39 +38668,6 @@ "@opentelemetry/api": "^1.3.0" } }, - "plugins/node/opentelemetry-instrumentation-undici": { - "name": "@opentelemetry/instrumentation-undici", - "version": "0.33.0", - "extraneous": true, - "license": "Apache-2.0", - "dependencies": { - "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.49.1" - }, - "devDependencies": { - "@opentelemetry/api": "^1.3.0", - "@opentelemetry/sdk-metrics": "^1.8.0", - "@opentelemetry/sdk-trace-base": "^1.8.0", - "@opentelemetry/sdk-trace-node": "^1.8.0", - "@types/mocha": "7.0.2", - "@types/node": "18.6.5", - "mocha": "7.2.0", - "nyc": "15.1.0", - "rimraf": "5.0.5", - "semver": "^7.6.0", - "superagent": "8.0.9", - "test-all-versions": "6.0.0", - "ts-mocha": "10.0.0", - "typescript": "4.4.4", - "undici": "^6.7.0" - }, - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "@opentelemetry/api": "^1.3.0" - } - }, "plugins/node/opentelemetry-instrumentation-winston": { "name": "@opentelemetry/instrumentation-winston", "version": "0.36.0", @@ -47393,7 +47229,7 @@ "requires": { "@opentelemetry/api": "^1.7.0", "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.49.1", + "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/sdk-metrics": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", @@ -47404,104 +47240,10 @@ "rimraf": "5.0.5", "semver": "^7.6.0", "superagent": "8.0.9", - "test-all-versions": "6.0.0", + "test-all-versions": "6.1.0", "ts-mocha": "10.0.0", "typescript": "4.4.4", - "undici": "6.10.1" - }, - "dependencies": { - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "cli-spinners": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", - "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", - "dev": true - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "is-ci": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz", - "integrity": "sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==", - "dev": true, - "requires": { - "ci-info": "^3.2.0" - } - }, - "log-symbols": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", - "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", - "dev": true, - "requires": { - "chalk": "^4.1.0", - "is-unicode-supported": "^0.1.0" - } - }, - "supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "requires": { - "has-flag": "^4.0.0" - } - }, - "test-all-versions": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/test-all-versions/-/test-all-versions-6.0.0.tgz", - "integrity": "sha512-/9wVTBRa7+arvItGinCYy/8+z7sHTsrs9cwEY/xAnzrkSEM7Tp2Cz49ewYZYuO1YYMLqxEaQp2g7Dnns7n7BGA==", - "dev": true, - "requires": { - "after-all-results": "^2.0.0", - "ansi-diff-stream": "^1.2.1", - "cli-spinners": "^2.9.2", - "deepmerge": "^4.3.1", - "import-fresh": "^3.3.0", - "is-ci": "^3.0.1", - "js-yaml": "^4.1.0", - "log-symbols": "^4.1.0", - "minimist": "^1.2.8", - "npm-package-versions": "^1.0.1", - "once": "^1.4.0", - "parse-env-string": "^1.0.1", - "resolve": "^1.22.8", - "semver": "^7.5.4", - "spawn-npm-install": "^1.2.0", - "which": "^2.0.2" - } - } + "undici": "6.11.1" } }, "@opentelemetry/instrumentation-user-interaction": { @@ -68503,9 +68245,9 @@ } }, "undici": { - "version": "6.10.1", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.10.1.tgz", - "integrity": "sha512-kSzmWrOx3XBKTgPm4Tal8Hyl3yf+hzlA00SAf4goxv8LZYafKmS6gJD/7Fe5HH/DMNiFTRXvkwhLo7mUn5fuQQ==", + "version": "6.11.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.11.1.tgz", + "integrity": "sha512-KyhzaLJnV1qa3BSHdj4AZ2ndqI0QWPxYzaIOio0WzcEJB9gvuysprJSLtpvc2D9mhR9jPDUk7xlJlZbH2KR5iw==", "dev": true }, "undici-types": { diff --git a/plugins/node/instrumentation-undici/.tav.yml b/plugins/node/instrumentation-undici/.tav.yml index 9ef69e2462..88b92a7898 100644 --- a/plugins/node/instrumentation-undici/.tav.yml +++ b/plugins/node/instrumentation-undici/.tav.yml @@ -1,8 +1,12 @@ undici: jobs: - - versions: ">=5 <6" + - versions: + include: ">=5.12.0 <6" + mode: max-7 node: '>=14' commands: npm run test - - versions: ">=6 <7" + - versions: + include: ">=6 <7" + mode: max-7 node: '>=18' commands: npm run test diff --git a/plugins/node/instrumentation-undici/README.md b/plugins/node/instrumentation-undici/README.md index 38b6fd6e9e..08a7128404 100644 --- a/plugins/node/instrumentation-undici/README.md +++ b/plugins/node/instrumentation-undici/README.md @@ -14,6 +14,10 @@ If you're looking the instrumentation for browser's `fetch` API it is located at npm install --save @opentelemetry/instrumentation-undici ``` +## Supported Versions + +- `undici@>=5.12.0` + ## Usage OpenTelemetry Undici/fetch Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems. diff --git a/plugins/node/instrumentation-undici/package.json b/plugins/node/instrumentation-undici/package.json index b235be769a..fd21b60b47 100644 --- a/plugins/node/instrumentation-undici/package.json +++ b/plugins/node/instrumentation-undici/package.json @@ -1,7 +1,7 @@ { "name": "@opentelemetry/instrumentation-undici", "version": "0.1.0", - "description": "OpenTelemetry undici/fetch automatic instrumentation package.", + "description": "OpenTelemetry instrumentation for undici and Node.js fetch().", "main": "build/src/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js-contrib", @@ -14,7 +14,6 @@ "clean": "rimraf build/*", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", "watch": "tsc -w", "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-undici --include-dependencies", "prewatch": "npm run precompile", @@ -53,10 +52,10 @@ "rimraf": "5.0.5", "semver": "^7.6.0", "superagent": "8.0.9", - "test-all-versions": "6.0.0", + "test-all-versions": "6.1.0", "ts-mocha": "10.0.0", "typescript": "4.4.4", - "undici": "6.10.1" + "undici": "6.11.1" }, "peerDependencies": { "@opentelemetry/api": "^1.7.0" diff --git a/plugins/node/instrumentation-undici/src/undici.ts b/plugins/node/instrumentation-undici/src/undici.ts index 262bea42cd..0fa07f97a3 100644 --- a/plugins/node/instrumentation-undici/src/undici.ts +++ b/plugins/node/instrumentation-undici/src/undici.ts @@ -270,10 +270,13 @@ export class UndiciInstrumentation extends InstrumentationBase { for (let i = 0; i < headerEntries.length; i++) { const [k, v] = headerEntries[i]; - if (typeof request.headers === 'string') { - request.headers += `${k}: ${v}\r\n`; - } else { + if (typeof request.addHeader === 'function') { request.addHeader(k, v); + } else if (typeof request.headers === 'string') { + request.headers += `${k}: ${v}\r\n`; + } else if (Array.isArray(request.headers)) { + // undici@6.11.0 accidentally, briefly removed `request.addHeader()`. + request.headers.push(k, v); } } this._recordFromReq.set(request, { span, attributes, startTime }); diff --git a/plugins/node/instrumentation-undici/test/undici.test.ts b/plugins/node/instrumentation-undici/test/undici.test.ts index fd48803a3f..aea2f036ce 100644 --- a/plugins/node/instrumentation-undici/test/undici.test.ts +++ b/plugins/node/instrumentation-undici/test/undici.test.ts @@ -38,8 +38,6 @@ import { assertSpan } from './utils/assertSpan'; import type { fetch, stream, request, Client, Dispatcher } from 'undici'; -type PromisedValue = T extends Promise ? R : never; - const instrumentation = new UndiciInstrumentation(); instrumentation.enable(); instrumentation.disable(); @@ -217,37 +215,20 @@ describe('UndiciInstrumentation `undici` tests', function () { 'foo-client': 'bar', }; - // In version v5 if `undici` you get the following error when requesting with a method - // that is not one of the known ones in uppercase. Using - // - // SocketError: other side closed - // at Socket.onSocketEnd (node_modules/undici/lib/client.js:1118:22) - // at endReadableNT (internal/streams/readable.js:1333:12) - // at processTicksAndRejections (internal/process/task_queues.js:82:21) - let firstQueryResponse: PromisedValue>; - let secondQueryResponse: PromisedValue>; - try { - const queryRequestUrl = `${protocol}://${hostname}:${mockServer.port}/?query=test`; - firstQueryResponse = await undici.request(queryRequestUrl, { - headers, - // @ts-expect-error - method type expects in uppercase - method: 'get', - }); - await consumeResponseBody(firstQueryResponse.body); - - secondQueryResponse = await undici.request(queryRequestUrl, { - headers, - // @ts-expect-error - method type expects known HTTP method (GET, POST, PUT, ...) - method: 'custom', - }); - await consumeResponseBody(secondQueryResponse.body); - } catch (undiciErr) { - const { stack } = undiciErr as Error; - - if (stack?.startsWith('SocketError: other side closed')) { - this.skip(); - } - } + const queryRequestUrl = `${protocol}://${hostname}:${mockServer.port}/?query=test`; + const firstQueryResponse = await undici.request(queryRequestUrl, { + headers, + // @ts-expect-error - method type expects in uppercase + method: 'get', + }); + await consumeResponseBody(firstQueryResponse.body); + + const secondQueryResponse = await undici.request(queryRequestUrl, { + headers, + // @ts-expect-error - method type expects known HTTP method (GET, POST, PUT, ...) + method: 'custom', + }); + await consumeResponseBody(secondQueryResponse.body); assert.ok( firstQueryResponse!.headers['propagation-error'] === undefined,