Skip to content

Commit

Permalink
Merge branch 'main' into te
Browse files Browse the repository at this point in the history
  • Loading branch information
obecny authored May 10, 2021
2 parents b1f8107 + 9ce9eea commit 63ade70
Show file tree
Hide file tree
Showing 35 changed files with 260 additions and 329 deletions.
3 changes: 2 additions & 1 deletion packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@opentelemetry/api": "^1.0.0-rc.0"
},
"dependencies": {
"semver": "^7.1.3"
"semver": "^7.1.3",
"@opentelemetry/semantic-conventions": "0.19.0"
}
}
12 changes: 8 additions & 4 deletions packages/opentelemetry-core/src/platform/browser/sdk-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/

import { VERSION } from '../../version';
import {
TelemetrySdkLanguageValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';

/** Constants describing the SDK in use */
export const SDK_INFO = {
NAME: 'opentelemetry',
RUNTIME: 'browser',
LANGUAGE: 'webjs',
VERSION: VERSION,
[ResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[ResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser',
[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]: TelemetrySdkLanguageValues.WEBJS,
[ResourceAttributes.TELEMETRY_SDK_VERSION]: VERSION,
};
13 changes: 9 additions & 4 deletions packages/opentelemetry-core/src/platform/node/sdk-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
*/

import { VERSION } from '../../version';
import {
TelemetrySdkLanguageValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';

/** Constants describing the SDK in use */
export const SDK_INFO = {
NAME: 'opentelemetry',
RUNTIME: 'node',
LANGUAGE: 'nodejs',
VERSION: VERSION,
[ResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[ResourceAttributes.PROCESS_RUNTIME_NAME]: 'node',
[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]:
TelemetrySdkLanguageValues.NODEJS,
[ResourceAttributes.TELEMETRY_SDK_VERSION]: VERSION,
};
3 changes: 3 additions & 0 deletions packages/opentelemetry-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"references": [
{
"path": "../opentelemetry-propagator-b3"
},
{
"path": "../opentelemetry-semantic-conventions"
}
]
}
3 changes: 2 additions & 1 deletion packages/opentelemetry-exporter-zipkin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"dependencies": {
"@opentelemetry/core": "0.19.0",
"@opentelemetry/resources": "0.19.0",
"@opentelemetry/tracing": "0.19.0"
"@opentelemetry/tracing": "0.19.0",
"@opentelemetry/semantic-conventions": "0.19.0"
}
}
8 changes: 4 additions & 4 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
statusCodeTagName,
statusDescriptionTagName,
} from './transform';
import { SERVICE_RESOURCE } from '@opentelemetry/resources';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { prepareGetHeaders } from './utils';

/**
Expand Down Expand Up @@ -66,7 +66,7 @@ export class ZipkinExporter implements SpanExporter {
) {
if (typeof this._serviceName !== 'string') {
this._serviceName = String(
spans[0].resource.attributes[SERVICE_RESOURCE.NAME] ||
spans[0].resource.attributes[ResourceAttributes.SERVICE_NAME] ||
this.DEFAULT_SERVICE_NAME
);
}
Expand Down Expand Up @@ -128,8 +128,8 @@ export class ZipkinExporter implements SpanExporter {
toZipkinSpan(
span,
String(
span.attributes[SERVICE_RESOURCE.NAME] ||
span.resource.attributes[SERVICE_RESOURCE.NAME] ||
span.attributes[ResourceAttributes.SERVICE_NAME] ||
span.resource.attributes[ResourceAttributes.SERVICE_NAME] ||
serviceName
),
this._statusCodeTagName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
hrTimeToMicroseconds,
VERSION,
} from '@opentelemetry/core';
import { Resource, TELEMETRY_SDK_RESOURCE } from '@opentelemetry/resources';
import { Resource } from '@opentelemetry/resources';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { BasicTracerProvider, Span } from '@opentelemetry/tracing';
import * as assert from 'assert';
import {
Expand All @@ -33,7 +34,8 @@ import {
import * as zipkinTypes from '../../src/types';
const tracer = new BasicTracerProvider().getTracer('default');

const language = tracer.resource.attributes[TELEMETRY_SDK_RESOURCE.LANGUAGE];
const language =
tracer.resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE];

const parentId = '5c1c63257de34c67';
const spanContext: api.SpanContext = {
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Resource } from '@opentelemetry/resources';
import { ZipkinExporter } from '../../src';
import * as zipkinTypes from '../../src/types';
import { TraceFlags } from '@opentelemetry/api';
import { SERVICE_RESOURCE } from '@opentelemetry/resources';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';

const MICROS_PER_SECS = 1e6;

Expand Down Expand Up @@ -417,7 +417,7 @@ describe('Zipkin Exporter - node', () => {
},
],
resource: new Resource({
[SERVICE_RESOURCE.NAME]: resource_service_name,
[ResourceAttributes.SERVICE_NAME]: resource_service_name,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};
Expand Down Expand Up @@ -519,7 +519,7 @@ describe('Zipkin Exporter - node', () => {
},
],
resource: new Resource({
[SERVICE_RESOURCE.NAME]: resource_service_name,
[ResourceAttributes.SERVICE_NAME]: resource_service_name,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};
Expand All @@ -542,7 +542,7 @@ describe('Zipkin Exporter - node', () => {
links: [],
events: [],
resource: new Resource({
[SERVICE_RESOURCE.NAME]: resource_service_name_prime,
[ResourceAttributes.SERVICE_NAME]: resource_service_name_prime,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};
Expand Down Expand Up @@ -598,7 +598,7 @@ describe('Zipkin Exporter - node', () => {
attributes: {
key1: 'value1',
key2: 'value2',
[SERVICE_RESOURCE.NAME]: span_service_name,
[ResourceAttributes.SERVICE_NAME]: span_service_name,
},
links: [],
events: [
Expand Down Expand Up @@ -627,7 +627,7 @@ describe('Zipkin Exporter - node', () => {
code: api.SpanStatusCode.OK,
},
attributes: {
[SERVICE_RESOURCE.NAME]: span_service_name_prime,
[ResourceAttributes.SERVICE_NAME]: span_service_name_prime,
},
links: [],
events: [],
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-exporter-zipkin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
{
"path": "../opentelemetry-resources"
},
{
"path": "../opentelemetry-semantic-conventions"
},
{
"path": "../opentelemetry-tracing"
}
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"devDependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/resources": "0.19.0",
"@opentelemetry/semantic-conventions": "0.19.0",
"@types/mocha": "8.2.2",
"@types/node": "14.14.43",
"@types/semver": "7.3.5",
Expand Down
5 changes: 3 additions & 2 deletions packages/opentelemetry-node/test/NodeTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
import { AlwaysOnSampler, AlwaysOffSampler } from '@opentelemetry/core';
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import { Span } from '@opentelemetry/tracing';
import { Resource, TELEMETRY_SDK_RESOURCE } from '@opentelemetry/resources';
import { Resource } from '@opentelemetry/resources';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import * as path from 'path';
import { ContextManager, ROOT_CONTEXT } from '@opentelemetry/api';
Expand Down Expand Up @@ -147,7 +148,7 @@ describe('NodeTracerProvider', () => {
assert.ok(span);
assert.ok(span.resource instanceof Resource);
assert.equal(
span.resource.attributes[TELEMETRY_SDK_RESOURCE.LANGUAGE],
span.resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE],
'nodejs'
);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
{
"path": "../opentelemetry-resources"
},
{
"path": "../opentelemetry-semantic-conventions"
},
{
"path": "../opentelemetry-tracing"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-resource-detector-aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
},
"dependencies": {
"@opentelemetry/core": "0.19.0",
"@opentelemetry/resources": "0.19.0"
"@opentelemetry/resources": "0.19.0",
"@opentelemetry/semantic-conventions": "0.19.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import { diag } from '@opentelemetry/api';
import {
Detector,
Resource,
SERVICE_RESOURCE,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as fs from 'fs';
import * as util from 'util';

Expand Down Expand Up @@ -65,10 +69,14 @@ export class AwsBeanstalkDetector implements Detector {
const parsedData = JSON.parse(rawData);

return new Resource({
[SERVICE_RESOURCE.NAME]: 'elastic_beanstalk',
[SERVICE_RESOURCE.NAMESPACE]: parsedData.environment_name,
[SERVICE_RESOURCE.VERSION]: parsedData.version_label,
[SERVICE_RESOURCE.INSTANCE_ID]: parsedData.deployment_id,
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]:
CloudPlatformValues.AWS_ELASTICBEANSTALK,
[ResourceAttributes.SERVICE_NAME]:
CloudPlatformValues.AWS_ELASTICBEANSTALK,
[ResourceAttributes.SERVICE_NAMESPACE]: parsedData.environment_name,
[ResourceAttributes.SERVICE_VERSION]: parsedData.version_label,
[ResourceAttributes.SERVICE_INSTANCE_ID]: parsedData.deployment_id,
});
} catch (e) {
diag.debug(`AwsBeanstalkDetector failed: ${e.message}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import {
Detector,
Resource,
CLOUD_RESOURCE,
HOST_RESOURCE,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';

/**
Expand Down Expand Up @@ -64,13 +67,14 @@ class AwsEc2Detector implements Detector {
const hostname = await this._fetchHost(token);

return new Resource({
[CLOUD_RESOURCE.PROVIDER]: 'aws',
[CLOUD_RESOURCE.ACCOUNT_ID]: accountId,
[CLOUD_RESOURCE.REGION]: region,
[CLOUD_RESOURCE.ZONE]: availabilityZone,
[HOST_RESOURCE.ID]: instanceId,
[HOST_RESOURCE.TYPE]: instanceType,
[HOST_RESOURCE.NAME]: hostname,
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_EC2,
[ResourceAttributes.CLOUD_ACCOUNT_ID]: accountId,
[ResourceAttributes.CLOUD_REGION]: region,
[ResourceAttributes.CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[ResourceAttributes.HOST_ID]: instanceId,
[ResourceAttributes.HOST_TYPE]: instanceType,
[ResourceAttributes.HOST_NAME]: hostname,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import {
Detector,
Resource,
ResourceDetectionConfig,
CONTAINER_RESOURCE,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as util from 'util';
import * as fs from 'fs';
import * as os from 'os';
Expand Down Expand Up @@ -49,8 +53,10 @@ export class AwsEcsDetector implements Detector {
return !hostName && !containerId
? Resource.empty()
: new Resource({
[CONTAINER_RESOURCE.NAME]: hostName || '',
[CONTAINER_RESOURCE.ID]: containerId || '',
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_ECS,
[ResourceAttributes.CONTAINER_NAME]: hostName || '',
[ResourceAttributes.CONTAINER_ID]: containerId || '',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import {
Detector,
Resource,
CONTAINER_RESOURCE,
K8S_RESOURCE,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as https from 'https';
import * as fs from 'fs';
import * as util from 'util';
Expand Down Expand Up @@ -76,8 +79,10 @@ export class AwsEksDetector implements Detector {
return !containerId && !clusterName
? Resource.empty()
: new Resource({
[K8S_RESOURCE.CLUSTER_NAME]: clusterName || '',
[CONTAINER_RESOURCE.ID]: containerId || '',
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_EKS,
[ResourceAttributes.K8S_CLUSTER_NAME]: clusterName || '',
[ResourceAttributes.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 @@ -17,9 +17,12 @@
import {
Detector,
Resource,
CLOUD_RESOURCE,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudProviderValues,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';

/**
* The AwsLambdaDetector can be used to detect if a process is running in AWS Lambda
Expand All @@ -37,18 +40,17 @@ export class AwsLambdaDetector implements Detector {
const region = process.env.AWS_REGION;

const attributes = {
[CLOUD_RESOURCE.PROVIDER]: 'aws',
[ResourceAttributes.CLOUD_PROVIDER]: String(CloudProviderValues.AWS),
};
if (region) {
attributes[CLOUD_RESOURCE.REGION] = region;
attributes[ResourceAttributes.CLOUD_REGION] = region;
}

// TODO(https://github.com/open-telemetry/opentelemetry-js/issues/2123): Migrate to FAAS_RESOURCE when defined.
if (functionName) {
attributes['faas.name'] = functionName;
attributes[ResourceAttributes.FAAS_NAME] = functionName;
}
if (functionVersion) {
attributes['faas.version'] = functionVersion;
attributes[ResourceAttributes.FAAS_VERSION] = functionVersion;
}

return new Resource(attributes);
Expand Down
Loading

0 comments on commit 63ade70

Please sign in to comment.