feat: updated spec to v1.5.0 and renamed resource class (#2345)

Co-authored-by: Weyert de Boer <weyert.deboer@tapico.io>
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
This commit is contained in:
Weyert de Boer 2021-07-25 07:41:34 +01:00 committed by GitHub
parent 884d20ab41
commit 3bc3452814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 244 additions and 208 deletions

View File

@ -226,6 +226,10 @@ To request automatic tracing support for a module not on this list, please [file
## Upgrade guidelines
### 0.23.x to x
- `ResourceAttributes` renamed to `SemanticResourceAttributes` in the `@opentelemetry/semantic-conventions` package
### 0.20.x to x
### 0.19.x to 0.20.0

View File

@ -2,13 +2,13 @@
const opentelemetry = require('@opentelemetry/api');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const provider = new BasicTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'basic-service',
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-service',
}),
});

View File

@ -6,7 +6,7 @@ const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector')
// const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector-proto');
const { MeterProvider } = require('@opentelemetry/metrics');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
// Optional and only needed to see the internal diagnostic logging (during development)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
@ -19,7 +19,7 @@ const meter = new MeterProvider({
exporter: metricExporter,
interval: 1000,
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
}),
}).getMeter('example-exporter-collector');

View File

@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/api');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
// const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-grpc');
// const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-proto');
@ -21,7 +21,7 @@ const exporter = new CollectorTraceExporter({
const provider = new BasicTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'basic-service',
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-service',
}),
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

View File

@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
@ -15,7 +15,7 @@ const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: serviceName,
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
}),
});

View File

@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
@ -15,7 +15,7 @@ const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: serviceName,
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
}),
});

View File

@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
@ -15,7 +15,7 @@ const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: serviceName,
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
}),
});

View File

@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
@ -17,7 +17,7 @@ module.exports = (serviceName) => {
let exporter;
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: serviceName,
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
}),
});

View File

@ -1,6 +1,6 @@
'use strict';
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { Resource } = require('@opentelemetry/resources');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
@ -10,7 +10,7 @@ const { TracerShim } = require('@opentelemetry/shim-opentracing');
function shim(serviceName) {
const provider = new NodeTracerProvider({
resource: new Resource({ [ResourceAttributes.SERVICE_NAME]: serviceName }),
resource: new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: serviceName }),
});
provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));

View File

@ -4,7 +4,7 @@ const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api');
const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector');
const { MeterProvider } = require('@opentelemetry/metrics');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
// Optional and only needed to see the internal diagnostic logging (during development)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
@ -26,7 +26,7 @@ function startMetrics() {
exporter: metricExporter,
interval: 1000,
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
}),
}).getMeter('example-exporter-collector');

View File

@ -126,7 +126,7 @@ After you install these dependencies, initialize and register them. Modify `trac
const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require("@opentelemetry/tracing");
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
@ -135,7 +135,7 @@ const { GrpcInstrumentation } = require("@opentelemetry/instrumentation-grpc");
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: "getting-started",
[SemanticResourceAttributes.SERVICE_NAME]: "getting-started",
})
});

View File

@ -3,7 +3,7 @@
const { NodeTracerProvider } = require("@opentelemetry/node");
const { SimpleSpanProcessor } = require("@opentelemetry/tracing");
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');
@ -11,7 +11,7 @@ const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: "getting-started",
[SemanticResourceAttributes.SERVICE_NAME]: "getting-started",
})
});

View File

@ -131,11 +131,12 @@ import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
const provider: NodeTracerProvider = new NodeTracerProvider({
logLevel: LogLevel.ERROR,
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'getting-started',
[SemanticResourceAttributes.SERVICE_NAME]: 'getting-started',
}),
});

View File

@ -1,6 +1,6 @@
import { NodeTracerProvider } from '@opentelemetry/node';
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
import { SimpleSpanProcessor } from '@opentelemetry/tracing';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
@ -13,7 +13,7 @@ const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const provider: NodeTracerProvider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'getting-started',
[SemanticResourceAttributes.SERVICE_NAME]: 'getting-started',
}),
});
provider.addSpanProcessor(

View File

@ -17,13 +17,13 @@
import { VERSION } from '../../version';
import {
TelemetrySdkLanguageValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
/** Constants describing the SDK in use */
export const SDK_INFO = {
[ResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[ResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser',
[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]: TelemetrySdkLanguageValues.WEBJS,
[ResourceAttributes.TELEMETRY_SDK_VERSION]: VERSION,
[SemanticResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser',
[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]: TelemetrySdkLanguageValues.WEBJS,
[SemanticResourceAttributes.TELEMETRY_SDK_VERSION]: VERSION,
};

View File

@ -17,14 +17,14 @@
import { VERSION } from '../../version';
import {
TelemetrySdkLanguageValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
/** Constants describing the SDK in use */
export const SDK_INFO = {
[ResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[ResourceAttributes.PROCESS_RUNTIME_NAME]: 'node',
[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]:
[SemanticResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'node',
[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]:
TelemetrySdkLanguageValues.NODEJS,
[ResourceAttributes.TELEMETRY_SDK_VERSION]: VERSION,
[SemanticResourceAttributes.TELEMETRY_SDK_VERSION]: VERSION,
};

View File

@ -18,7 +18,7 @@ import { diag } from '@opentelemetry/api';
import { ExportResult, ExportResultCode, getEnv } from '@opentelemetry/core';
import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing';
import { Socket } from 'dgram';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { spanToThrift } from './transform';
import * as jaegerTypes from './types';
@ -155,7 +155,7 @@ export class JaegerExporter implements SpanExporter {
sender._client.unref();
}
const serviceNameTag = span.tags.find(t => t.key === ResourceAttributes.SERVICE_NAME)
const serviceNameTag = span.tags.find(t => t.key === SemanticResourceAttributes.SERVICE_NAME)
const serviceName = serviceNameTag?.vStr || 'unknown_service';
sender.setProcess({

View File

@ -23,7 +23,7 @@ import { ReadableSpan } from '@opentelemetry/tracing';
import { TraceFlags } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import * as nock from 'nock';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
describe('JaegerExporter', () => {
const readableSpan: ReadableSpan = {
@ -47,7 +47,7 @@ describe('JaegerExporter', () => {
events: [],
duration: [32, 800000000],
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'opentelemetry'
[SemanticResourceAttributes.SERVICE_NAME]: 'opentelemetry'
}),
instrumentationLibrary: {
name: 'default',
@ -70,7 +70,7 @@ describe('JaegerExporter', () => {
const scope =nock(mockedEndpoint)
.post('/')
.reply(202)
const exporter = new JaegerExporter({
endpoint: mockedEndpoint,
});

View File

@ -24,7 +24,7 @@ import {
statusCodeTagName,
statusDescriptionTagName,
} from './transform';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { prepareGetHeaders } from './utils';
/**
@ -66,7 +66,7 @@ export class ZipkinExporter implements SpanExporter {
) {
const serviceName = String(
this._serviceName ||
spans[0].resource.attributes[ResourceAttributes.SERVICE_NAME] ||
spans[0].resource.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
this.DEFAULT_SERVICE_NAME
);
@ -128,8 +128,8 @@ export class ZipkinExporter implements SpanExporter {
toZipkinSpan(
span,
String(
span.attributes[ResourceAttributes.SERVICE_NAME] ||
span.resource.attributes[ResourceAttributes.SERVICE_NAME] ||
span.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
span.resource.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
serviceName
),
this._statusCodeTagName,

View File

@ -23,7 +23,7 @@ import {
import { Resource } from '@opentelemetry/resources';
import { BasicTracerProvider, Span } from '@opentelemetry/tracing';
import * as assert from 'assert';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import {
statusCodeTagName,
statusDescriptionTagName,
@ -35,13 +35,13 @@ import * as zipkinTypes from '../../src/types';
const tracer = new BasicTracerProvider({
resource: Resource.default().merge(
new Resource({
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
})
),
}).getTracer('default');
const language =
tracer.resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE];
tracer.resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE];
const parentId = '5c1c63257de34c67';
const spanContext: api.SpanContext = {
@ -54,7 +54,7 @@ const DUMMY_RESOURCE = new Resource({
service: 'ui',
version: 1,
cost: 112.12,
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
describe('transform', () => {
@ -102,7 +102,7 @@ describe('transform', () => {
key1: 'value1',
key2: 'value2',
[statusCodeTagName]: 'UNSET',
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': VERSION,
@ -141,7 +141,7 @@ describe('transform', () => {
parentId: undefined,
tags: {
[statusCodeTagName]: 'UNSET',
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': VERSION,
@ -190,7 +190,7 @@ describe('transform', () => {
parentId: undefined,
tags: {
[statusCodeTagName]: 'UNSET',
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': VERSION,
@ -231,7 +231,7 @@ describe('transform', () => {
cost: '112.12',
service: 'ui',
version: '1',
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
it('should map OpenTelemetry SpanStatus.code to a Zipkin tag', () => {
@ -258,7 +258,7 @@ describe('transform', () => {
statusDescriptionTagName,
Resource.empty().merge(
new Resource({
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
})
)
);
@ -267,7 +267,7 @@ describe('transform', () => {
key1: 'value1',
key2: 'value2',
[statusCodeTagName]: 'ERROR',
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
it('should map OpenTelemetry SpanStatus.message to a Zipkin tag', () => {
@ -295,7 +295,7 @@ describe('transform', () => {
statusDescriptionTagName,
Resource.empty().merge(
new Resource({
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
})
)
);
@ -305,7 +305,7 @@ describe('transform', () => {
key2: 'value2',
[statusCodeTagName]: 'ERROR',
[statusDescriptionTagName]: status.message,
[ResourceAttributes.SERVICE_NAME]: 'zipkin-test',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
});

View File

@ -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 { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
const MICROS_PER_SECS = 1e6;
@ -377,7 +377,7 @@ describe('Zipkin Exporter - node', () => {
},
],
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: resource_service_name,
[SemanticResourceAttributes.SERVICE_NAME]: resource_service_name,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};
@ -400,7 +400,7 @@ describe('Zipkin Exporter - node', () => {
links: [],
events: [],
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: resource_service_name_prime,
[SemanticResourceAttributes.SERVICE_NAME]: resource_service_name_prime,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};
@ -456,7 +456,7 @@ describe('Zipkin Exporter - node', () => {
attributes: {
key1: 'value1',
key2: 'value2',
[ResourceAttributes.SERVICE_NAME]: span_service_name,
[SemanticResourceAttributes.SERVICE_NAME]: span_service_name,
},
links: [],
events: [
@ -485,7 +485,7 @@ describe('Zipkin Exporter - node', () => {
code: api.SpanStatusCode.OK,
},
attributes: {
[ResourceAttributes.SERVICE_NAME]: span_service_name_prime,
[SemanticResourceAttributes.SERVICE_NAME]: span_service_name_prime,
},
links: [],
events: [],
@ -518,11 +518,11 @@ describe('Zipkin Exporter - node', () => {
})
it('should use url from env', () => {
const scope = nock('http://localhost:9412').post('/').reply(200);
const exporter = new ZipkinExporter({
serviceName: 'my-service',
});
exporter.export([getReadableSpan()], (result: ExportResult) => {
scope.done();
assert.strictEqual(result.code, ExportResultCode.SUCCESS);

View File

@ -23,7 +23,7 @@ import { AlwaysOnSampler, AlwaysOffSampler } from '@opentelemetry/core';
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import { Span } from '@opentelemetry/tracing';
import { Resource } from '@opentelemetry/resources';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import * as path from 'path';
import { ContextManager, ROOT_CONTEXT } from '@opentelemetry/api';
@ -145,7 +145,7 @@ describe('NodeTracerProvider', () => {
assert.ok(span);
assert.ok(span.resource instanceof Resource);
assert.equal(
span.resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE],
span.resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],
'nodejs'
);
});

View File

@ -23,7 +23,7 @@ import {
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as fs from 'fs';
import * as util from 'util';
@ -69,14 +69,14 @@ export class AwsBeanstalkDetector implements Detector {
const parsedData = JSON.parse(rawData);
return new Resource({
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]:
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]:
CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
[ResourceAttributes.SERVICE_NAME]:
[SemanticResourceAttributes.SERVICE_NAME]:
CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
[ResourceAttributes.SERVICE_NAMESPACE]: parsedData.environment_name,
[ResourceAttributes.SERVICE_VERSION]: parsedData.version_label,
[ResourceAttributes.SERVICE_INSTANCE_ID]: parsedData.deployment_id,
[SemanticResourceAttributes.SERVICE_NAMESPACE]: parsedData.environment_name,
[SemanticResourceAttributes.SERVICE_VERSION]: parsedData.version_label,
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: parsedData.deployment_id,
});
} catch (e) {
diag.debug(`AwsBeanstalkDetector failed: ${e.message}`);

View File

@ -22,7 +22,7 @@ import {
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';
@ -67,14 +67,14 @@ class AwsEc2Detector implements Detector {
const hostname = await this._fetchHost(token);
return new Resource({
[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,
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_EC2,
[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: accountId,
[SemanticResourceAttributes.CLOUD_REGION]: region,
[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SemanticResourceAttributes.HOST_ID]: instanceId,
[SemanticResourceAttributes.HOST_TYPE]: instanceType,
[SemanticResourceAttributes.HOST_NAME]: hostname,
});
}

View File

@ -23,7 +23,7 @@ import {
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as util from 'util';
import * as fs from 'fs';
@ -53,10 +53,10 @@ export class AwsEcsDetector implements Detector {
return !hostName && !containerId
? Resource.empty()
: new Resource({
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_ECS,
[ResourceAttributes.CONTAINER_NAME]: hostName || '',
[ResourceAttributes.CONTAINER_ID]: containerId || '',
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_ECS,
[SemanticResourceAttributes.CONTAINER_NAME]: hostName || '',
[SemanticResourceAttributes.CONTAINER_ID]: containerId || '',
});
}

View File

@ -22,7 +22,7 @@ import {
import {
CloudProviderValues,
CloudPlatformValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
import * as https from 'https';
import * as fs from 'fs';
@ -79,10 +79,10 @@ export class AwsEksDetector implements Detector {
return !containerId && !clusterName
? Resource.empty()
: new Resource({
[ResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[ResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_EKS,
[ResourceAttributes.K8S_CLUSTER_NAME]: clusterName || '',
[ResourceAttributes.CONTAINER_ID]: containerId || '',
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AWS,
[SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AWS_EKS,
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: clusterName || '',
[SemanticResourceAttributes.CONTAINER_ID]: containerId || '',
});
} catch (e) {
diag.warn('Process is not running on K8S', e);

View File

@ -21,7 +21,7 @@ import {
} from '@opentelemetry/resources';
import {
CloudProviderValues,
ResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
/**
@ -40,17 +40,17 @@ export class AwsLambdaDetector implements Detector {
const region = process.env.AWS_REGION;
const attributes = {
[ResourceAttributes.CLOUD_PROVIDER]: String(CloudProviderValues.AWS),
[SemanticResourceAttributes.CLOUD_PROVIDER]: String(CloudProviderValues.AWS),
};
if (region) {
attributes[ResourceAttributes.CLOUD_REGION] = region;
attributes[SemanticResourceAttributes.CLOUD_REGION] = region;
}
if (functionName) {
attributes[ResourceAttributes.FAAS_NAME] = functionName;
attributes[SemanticResourceAttributes.FAAS_NAME] = functionName;
}
if (functionVersion) {
attributes[ResourceAttributes.FAAS_VERSION] = functionVersion;
attributes[SemanticResourceAttributes.FAAS_VERSION] = functionVersion;
}
return new Resource(attributes);

View File

@ -26,7 +26,7 @@ import {
import { getEnv } from '@opentelemetry/core';
import {
CloudProviderValues,
ResourceAttributes as SemanticResourceAttributes,
SemanticResourceAttributes,
} from '@opentelemetry/semantic-conventions';
/**

View File

@ -18,11 +18,11 @@ npm install --save @opentelemetry/resources
## Usage
```typescript
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';
const resource = new Resource({
[ResourceAttributes.SERVICE_NAME]: 'api-service',
[SemanticResourceAttributes.SERVICE_NAME]: 'api-service',
});
const another_resource = new Resource({

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ResourceAttributes as SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SDK_INFO } from '@opentelemetry/core';
import { ResourceAttributes } from './types';
import { defaultServiceName } from './platform';

View File

@ -16,7 +16,7 @@
import { diag } from '@opentelemetry/api';
import { getEnv } from '@opentelemetry/core';
import { ResourceAttributes as SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import {
Detector,
Resource,

View File

@ -15,7 +15,7 @@
*/
import { diag } from '@opentelemetry/api';
import { ResourceAttributes as SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Detector, Resource, ResourceDetectionConfig } from '../../../';
import { ResourceAttributes } from '../../../types';

View File

@ -17,7 +17,7 @@
import * as assert from 'assert';
import { SDK_INFO } from '@opentelemetry/core';
import { Resource } from '../src';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
describe('Resource', () => {
const resource1 = new Resource({
@ -103,10 +103,10 @@ describe('Resource', () => {
describe('.default()', () => {
it('should return a default resource', () => {
const resource = Resource.default();
assert.strictEqual(resource.attributes[ResourceAttributes.TELEMETRY_SDK_NAME], SDK_INFO[ResourceAttributes.TELEMETRY_SDK_NAME]);
assert.strictEqual(resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE], SDK_INFO[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]);
assert.strictEqual(resource.attributes[ResourceAttributes.TELEMETRY_SDK_VERSION], SDK_INFO[ResourceAttributes.TELEMETRY_SDK_VERSION]);
assert.strictEqual(resource.attributes[ResourceAttributes.SERVICE_NAME], `unknown_service:${process.argv0}`);
assert.strictEqual(resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_NAME], SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_NAME]);
assert.strictEqual(resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE], SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]);
assert.strictEqual(resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_VERSION], SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_VERSION]);
assert.strictEqual(resource.attributes[SemanticResourceAttributes.SERVICE_NAME], `unknown_service:${process.argv0}`);
});
});
});

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { envDetector, Resource } from '../../src';
import {
assertK8sResource,
@ -35,9 +35,9 @@ describe('envDetector()', () => {
it('should return resource information from environment variable', async () => {
const resource: Resource = await envDetector.detect();
assertK8sResource(resource, {
[ResourceAttributes.K8S_POD_NAME]: 'pod-xyz-123',
[ResourceAttributes.K8S_CLUSTER_NAME]: 'c1',
[ResourceAttributes.K8S_NAMESPACE_NAME]: 'default',
[SemanticResourceAttributes.K8S_POD_NAME]: 'pod-xyz-123',
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: 'c1',
[SemanticResourceAttributes.K8S_NAMESPACE_NAME]: 'default',
});
});
});

View File

@ -15,7 +15,7 @@
*/
import { SDK_INFO } from '@opentelemetry/core';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../src/Resource';
import {
assertCloudResource,
@ -29,17 +29,17 @@ import {
describe('assertCloudResource', () => {
it('requires one cloud label', () => {
const resource = new Resource({
[ResourceAttributes.CLOUD_PROVIDER]: 'gcp',
[SemanticResourceAttributes.CLOUD_PROVIDER]: 'gcp',
});
assertCloudResource(resource, {});
});
it('validates optional attributes', () => {
const resource = new Resource({
[ResourceAttributes.CLOUD_PROVIDER]: 'gcp',
[ResourceAttributes.CLOUD_ACCOUNT_ID]: 'opentelemetry',
[ResourceAttributes.CLOUD_REGION]: 'us-central1',
[ResourceAttributes.CLOUD_AVAILABILITY_ZONE]: 'us-central1-a',
[SemanticResourceAttributes.CLOUD_PROVIDER]: 'gcp',
[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: 'opentelemetry',
[SemanticResourceAttributes.CLOUD_REGION]: 'us-central1',
[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: 'us-central1-a',
});
assertCloudResource(resource, {
provider: 'gcp',
@ -53,18 +53,18 @@ describe('assertCloudResource', () => {
describe('assertContainerResource', () => {
it('requires one container label', () => {
const resource = new Resource({
[ResourceAttributes.CONTAINER_NAME]: 'opentelemetry-autoconf',
[SemanticResourceAttributes.CONTAINER_NAME]: 'opentelemetry-autoconf',
});
assertContainerResource(resource, {});
});
it('validates optional attributes', () => {
const resource = new Resource({
[ResourceAttributes.CONTAINER_NAME]: 'opentelemetry-autoconf',
[ResourceAttributes.CONTAINER_ID]: 'abc',
[ResourceAttributes.CONTAINER_IMAGE_NAME]:
[SemanticResourceAttributes.CONTAINER_NAME]: 'opentelemetry-autoconf',
[SemanticResourceAttributes.CONTAINER_ID]: 'abc',
[SemanticResourceAttributes.CONTAINER_IMAGE_NAME]:
'gcr.io/opentelemetry/operator',
[ResourceAttributes.CONTAINER_IMAGE_TAG]: '0.1',
[SemanticResourceAttributes.CONTAINER_IMAGE_TAG]: '0.1',
});
assertContainerResource(resource, {
name: 'opentelemetry-autoconf',
@ -78,20 +78,20 @@ describe('assertContainerResource', () => {
describe('assertHostResource', () => {
it('requires one host label', () => {
const resource = new Resource({
[ResourceAttributes.HOST_ID]: 'opentelemetry-test-id',
[SemanticResourceAttributes.HOST_ID]: 'opentelemetry-test-id',
});
assertHostResource(resource, {});
});
it('validates optional attributes', () => {
const resource = new Resource({
[ResourceAttributes.HOST_ID]: 'opentelemetry-test-id',
[ResourceAttributes.HOST_NAME]: 'opentelemetry-test-name',
[ResourceAttributes.HOST_TYPE]: 'n1-standard-1',
[ResourceAttributes.HOST_IMAGE_NAME]:
[SemanticResourceAttributes.HOST_ID]: 'opentelemetry-test-id',
[SemanticResourceAttributes.HOST_NAME]: 'opentelemetry-test-name',
[SemanticResourceAttributes.HOST_TYPE]: 'n1-standard-1',
[SemanticResourceAttributes.HOST_IMAGE_NAME]:
'infra-ami-eks-worker-node-7d4ec78312, CentOS-8-x86_64-1905',
[ResourceAttributes.HOST_IMAGE_ID]: 'ami-07b06b442921831e5',
[ResourceAttributes.HOST_IMAGE_VERSION]: '0.1',
[SemanticResourceAttributes.HOST_IMAGE_ID]: 'ami-07b06b442921831e5',
[SemanticResourceAttributes.HOST_IMAGE_VERSION]: '0.1',
});
assertHostResource(resource, {
hostName: 'opentelemetry-test-hostname',
@ -108,17 +108,17 @@ describe('assertHostResource', () => {
describe('assertK8sResource', () => {
it('requires one k8s label', () => {
const resource = new Resource({
[ResourceAttributes.K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
});
assertK8sResource(resource, {});
});
it('validates optional attributes', () => {
const resource = new Resource({
[ResourceAttributes.K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
[ResourceAttributes.K8S_NAMESPACE_NAME]: 'default',
[ResourceAttributes.K8S_POD_NAME]: 'opentelemetry-pod-autoconf',
[ResourceAttributes.K8S_DEPLOYMENT_NAME]: 'opentelemetry',
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
[SemanticResourceAttributes.K8S_NAMESPACE_NAME]: 'default',
[SemanticResourceAttributes.K8S_POD_NAME]: 'opentelemetry-pod-autoconf',
[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME]: 'opentelemetry',
});
assertK8sResource(resource, {
clusterName: 'opentelemetry-cluster',
@ -132,18 +132,18 @@ describe('assertK8sResource', () => {
describe('assertTelemetrySDKResource', () => {
it('uses default validations', () => {
const resource = new Resource({
[ResourceAttributes.TELEMETRY_SDK_NAME]: SDK_INFO.NAME,
[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]: SDK_INFO.LANGUAGE,
[ResourceAttributes.TELEMETRY_SDK_VERSION]: SDK_INFO.VERSION,
[SemanticResourceAttributes.TELEMETRY_SDK_NAME]: SDK_INFO.NAME,
[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]: SDK_INFO.LANGUAGE,
[SemanticResourceAttributes.TELEMETRY_SDK_VERSION]: SDK_INFO.VERSION,
});
assertTelemetrySDKResource(resource, {});
});
it('validates optional attributes', () => {
const resource = new Resource({
[ResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[ResourceAttributes.TELEMETRY_SDK_LANGUAGE]: 'nodejs',
[ResourceAttributes.TELEMETRY_SDK_VERSION]: '0.1.0',
[SemanticResourceAttributes.TELEMETRY_SDK_NAME]: 'opentelemetry',
[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]: 'nodejs',
[SemanticResourceAttributes.TELEMETRY_SDK_VERSION]: '0.1.0',
});
assertTelemetrySDKResource(resource, {
name: 'opentelemetry',
@ -156,8 +156,8 @@ describe('assertTelemetrySDKResource', () => {
describe('assertServiceResource', () => {
it('validates required attributes', () => {
const resource = new Resource({
[ResourceAttributes.SERVICE_NAME]: 'shoppingcart',
[ResourceAttributes.SERVICE_INSTANCE_ID]:
[SemanticResourceAttributes.SERVICE_NAME]: 'shoppingcart',
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]:
'627cc493-f310-47de-96bd-71410b7dec09',
});
assertServiceResource(resource, {
@ -168,11 +168,11 @@ describe('assertServiceResource', () => {
it('validates optional attributes', () => {
const resource = new Resource({
[ResourceAttributes.SERVICE_NAME]: 'shoppingcart',
[ResourceAttributes.SERVICE_INSTANCE_ID]:
[SemanticResourceAttributes.SERVICE_NAME]: 'shoppingcart',
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]:
'627cc493-f310-47de-96bd-71410b7dec09',
[ResourceAttributes.SERVICE_NAMESPACE]: 'shop',
[ResourceAttributes.SERVICE_VERSION]: '0.1.0',
[SemanticResourceAttributes.SERVICE_NAMESPACE]: 'shop',
[SemanticResourceAttributes.SERVICE_VERSION]: '0.1.0',
});
assertServiceResource(resource, {
name: 'shoppingcart',

View File

@ -17,7 +17,7 @@
import { SDK_INFO } from '@opentelemetry/core';
import * as assert from 'assert';
import { Resource } from '../../src/Resource';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
/**
* Test utility method to validate a cloud resource
@ -37,22 +37,22 @@ export const assertCloudResource = (
assertHasOneLabel('CLOUD', resource);
if (validations.provider)
assert.strictEqual(
resource.attributes[ResourceAttributes.CLOUD_PROVIDER],
resource.attributes[SemanticResourceAttributes.CLOUD_PROVIDER],
validations.provider
);
if (validations.accountId)
assert.strictEqual(
resource.attributes[ResourceAttributes.CLOUD_ACCOUNT_ID],
resource.attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID],
validations.accountId
);
if (validations.region)
assert.strictEqual(
resource.attributes[ResourceAttributes.CLOUD_REGION],
resource.attributes[SemanticResourceAttributes.CLOUD_REGION],
validations.region
);
if (validations.zone)
assert.strictEqual(
resource.attributes[ResourceAttributes.CLOUD_AVAILABILITY_ZONE],
resource.attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE],
validations.zone
);
};
@ -75,22 +75,22 @@ export const assertContainerResource = (
assertHasOneLabel('CONTAINER', resource);
if (validations.name)
assert.strictEqual(
resource.attributes[ResourceAttributes.CONTAINER_NAME],
resource.attributes[SemanticResourceAttributes.CONTAINER_NAME],
validations.name
);
if (validations.id)
assert.strictEqual(
resource.attributes[ResourceAttributes.CONTAINER_ID],
resource.attributes[SemanticResourceAttributes.CONTAINER_ID],
validations.id
);
if (validations.imageName)
assert.strictEqual(
resource.attributes[ResourceAttributes.CONTAINER_IMAGE_NAME],
resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_NAME],
validations.imageName
);
if (validations.imageTag)
assert.strictEqual(
resource.attributes[ResourceAttributes.CONTAINER_IMAGE_TAG],
resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_TAG],
validations.imageTag
);
};
@ -116,32 +116,32 @@ export const assertHostResource = (
assertHasOneLabel('HOST', resource);
if (validations.id)
assert.strictEqual(
resource.attributes[ResourceAttributes.HOST_ID],
resource.attributes[SemanticResourceAttributes.HOST_ID],
validations.id
);
if (validations.name)
assert.strictEqual(
resource.attributes[ResourceAttributes.HOST_NAME],
resource.attributes[SemanticResourceAttributes.HOST_NAME],
validations.name
);
if (validations.hostType)
assert.strictEqual(
resource.attributes[ResourceAttributes.HOST_TYPE],
resource.attributes[SemanticResourceAttributes.HOST_TYPE],
validations.hostType
);
if (validations.imageName)
assert.strictEqual(
resource.attributes[ResourceAttributes.HOST_IMAGE_NAME],
resource.attributes[SemanticResourceAttributes.HOST_IMAGE_NAME],
validations.imageName
);
if (validations.imageId)
assert.strictEqual(
resource.attributes[ResourceAttributes.HOST_IMAGE_ID],
resource.attributes[SemanticResourceAttributes.HOST_IMAGE_ID],
validations.imageId
);
if (validations.imageVersion)
assert.strictEqual(
resource.attributes[ResourceAttributes.HOST_IMAGE_VERSION],
resource.attributes[SemanticResourceAttributes.HOST_IMAGE_VERSION],
validations.imageVersion
);
};
@ -164,22 +164,22 @@ export const assertK8sResource = (
assertHasOneLabel('K8S', resource);
if (validations.clusterName)
assert.strictEqual(
resource.attributes[ResourceAttributes.K8S_CLUSTER_NAME],
resource.attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME],
validations.clusterName
);
if (validations.namespaceName)
assert.strictEqual(
resource.attributes[ResourceAttributes.K8S_NAMESPACE_NAME],
resource.attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME],
validations.namespaceName
);
if (validations.podName)
assert.strictEqual(
resource.attributes[ResourceAttributes.K8S_POD_NAME],
resource.attributes[SemanticResourceAttributes.K8S_POD_NAME],
validations.podName
);
if (validations.deploymentName)
assert.strictEqual(
resource.attributes[ResourceAttributes.K8S_DEPLOYMENT_NAME],
resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME],
validations.deploymentName
);
};
@ -207,17 +207,17 @@ export const assertTelemetrySDKResource = (
if (validations.name)
assert.strictEqual(
resource.attributes[ResourceAttributes.TELEMETRY_SDK_NAME],
resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_NAME],
validations.name
);
if (validations.language)
assert.strictEqual(
resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE],
resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],
validations.language
);
if (validations.version)
assert.strictEqual(
resource.attributes[ResourceAttributes.TELEMETRY_SDK_VERSION],
resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_VERSION],
validations.version
);
};
@ -238,21 +238,21 @@ export const assertServiceResource = (
}
) => {
assert.strictEqual(
resource.attributes[ResourceAttributes.SERVICE_NAME],
resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
validations.name
);
assert.strictEqual(
resource.attributes[ResourceAttributes.SERVICE_INSTANCE_ID],
resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
validations.instanceId
);
if (validations.namespace)
assert.strictEqual(
resource.attributes[ResourceAttributes.SERVICE_NAMESPACE],
resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE],
validations.namespace
);
if (validations.version)
assert.strictEqual(
resource.attributes[ResourceAttributes.SERVICE_VERSION],
resource.attributes[SemanticResourceAttributes.SERVICE_VERSION],
validations.version
);
};
@ -273,24 +273,24 @@ export const assertProcessResource = (
}
) => {
assert.strictEqual(
resource.attributes[ResourceAttributes.PROCESS_PID],
resource.attributes[SemanticResourceAttributes.PROCESS_PID],
validations.pid
);
if (validations.name) {
assert.strictEqual(
resource.attributes[ResourceAttributes.PROCESS_EXECUTABLE_NAME],
resource.attributes[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME],
validations.name
);
}
if (validations.command) {
assert.strictEqual(
resource.attributes[ResourceAttributes.PROCESS_COMMAND],
resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND],
validations.command
);
}
if (validations.commandLine) {
assert.strictEqual(
resource.attributes[ResourceAttributes.PROCESS_COMMAND_LINE],
resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND_LINE],
validations.commandLine
);
}
@ -306,7 +306,7 @@ export const assertEmptyResource = (resource: Resource) => {
};
const assertHasOneLabel = (prefix: string, resource: Resource): void => {
const hasOne = Object.entries(ResourceAttributes).find(([key, value]) => {
const hasOne = Object.entries(SemanticResourceAttributes).find(([key, value]) => {
return (
key.startsWith(prefix) &&
Object.prototype.hasOwnProperty.call(resource.attributes, value)
@ -316,7 +316,7 @@ const assertHasOneLabel = (prefix: string, resource: Resource): void => {
assert.ok(
hasOne,
'Resource must have one of the following attributes: ' +
Object.entries(ResourceAttributes)
Object.entries(SemanticResourceAttributes)
.reduce((result, [key, value]) => {
if (key.startsWith(prefix)) {
result.push(value);

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Detector, Resource } from '../../src';
class SampleDetector implements Detector {
async detect(): Promise<Resource> {
return new Resource({
[ResourceAttributes.CLOUD_PROVIDER]: 'provider',
[ResourceAttributes.CLOUD_ACCOUNT_ID]: 'accountId',
[ResourceAttributes.CLOUD_REGION]: 'region',
[ResourceAttributes.CLOUD_AVAILABILITY_ZONE]: 'zone',
[ResourceAttributes.HOST_ID]: 'instanceId',
[ResourceAttributes.HOST_TYPE]: 'instanceType',
[SemanticResourceAttributes.CLOUD_PROVIDER]: 'provider',
[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: 'accountId',
[SemanticResourceAttributes.CLOUD_REGION]: 'region',
[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: 'zone',
[SemanticResourceAttributes.HOST_ID]: 'instanceId',
[SemanticResourceAttributes.HOST_TYPE]: 'instanceType',
});
}
}

View File

@ -15,7 +15,7 @@
*/
// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates//templates/SemanticAttributes.ts.j2
export const ResourceAttributes = {
export const SemanticResourceAttributes = {
/**
* Name of the cloud provider.
@ -159,24 +159,51 @@ export const ResourceAttributes = {
DEVICE_MODEL_NAME: 'device.model.name',
/**
* The name of the function being executed.
* The name of the single function that this runtime instance executes.
*
* Note: This is the name of the function as configured/deployed on the FaaS platform and is usually different from the name of the callback function (which may be stored in the [`code.namespace`/`code.function`](../../trace/semantic_conventions/span-general.md#source-code-attributes) span attributes).
*/
FAAS_NAME: 'faas.name',
/**
* The unique ID of the function being executed.
* The unique ID of the single function that this runtime instance executes.
*
* Note: For example, in AWS Lambda this field corresponds to the [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) value, in GCP to the URI of the resource, and in Azure to the [FunctionDirectory](https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function) field.
* Note: Depending on the cloud provider, use:
* **AWS Lambda:** The function [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
Take care not to use the &#34;invoked ARN&#34; directly but replace any
[alias suffix](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html) with the resolved function version, as the same runtime instance may be invokable with multiple
different aliases.
* **GCP:** The [URI of the resource](https://cloud.google.com/iam/docs/full-resource-names)
* **Azure:** The [Fully Qualified Resource ID](https://docs.microsoft.com/en-us/rest/api/resources/resources/get-by-id).
On some providers, it may not be possible to determine the full ID at startup,
which is why this field cannot be made required. For example, on AWS the account ID
part of the ARN is not available without calling another AWS API
which may be deemed too slow for a short-running lambda function.
As an alternative, consider setting `faas.id` as a span attribute instead.
*/
FAAS_ID: 'faas.id',
/**
* The version string of the function being executed as defined in [Version Attributes](../../resource/semantic_conventions/README.md#version-attributes).
* The immutable version of the function being executed.
*
* Note: Depending on the cloud provider and platform, use:
* **AWS Lambda:** The [function version](https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html)
(an integer represented as a decimal string).
* **Google Cloud Run:** The [revision](https://cloud.google.com/run/docs/managing/revisions)
(i.e., the function name plus the revision suffix).
* **Google Cloud Functions:** The value of the
[`K_REVISION` environment variable](https://cloud.google.com/functions/docs/env-var#runtime_environment_variables_set_automatically).
* **Azure Functions:** Not applicable. Do not set this attribute.
*/
FAAS_VERSION: 'faas.version',
/**
* The execution environment ID as a string.
* The execution environment ID as a string, that will be potentially reused for other invocations to the same function/function version.
*
* Note: * **AWS Lambda:** Use the (full) log stream name.
*/
FAAS_INSTANCE: 'faas.instance',

View File

@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './ResourceAttributes';
export * from './SemanticResourceAttributes';

View File

@ -17,6 +17,13 @@
// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates//templates/SemanticAttributes.ts.j2
export const SemanticAttributes = {
/**
* The full invoked ARN as provided on the `Context` passed to the function (`Lambda-Runtime-Invoked-Function-Arn` header on the `/runtime/invocation/next` applicable).
*
* Note: This may be different from `faas.id` if an alias is involved.
*/
AWS_LAMBDA_INVOKED_ARN: 'aws.lambda.invoked_arn',
/**
* An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers.
*/
@ -608,12 +615,16 @@ clear whether the exception will escape.
RPC_SYSTEM: 'rpc.system',
/**
* The full name of the service being called, including its package name, if applicable.
* The full (logical) name of the service being called, including its package name, if applicable.
*
* Note: This is the logical name of the service from the RPC interface perspective, which can be different from the name of any implementing class. The `code.namespace` attribute may be used to store the latter (despite the attribute name, it may include a class name; e.g., class with method actually executing the call on the server side, RPC client stub class on the client side).
*/
RPC_SERVICE: 'rpc.service',
/**
* The name of the method being called, must be equal to the $method part in the span name.
* The name of the (logical) method being called, must be equal to the $method part in the span name.
*
* Note: This is the logical name of the method from the RPC interface perspective, which can be different from the name of any implementing method/function. The `code.function` attribute may be used to store the latter (e.g., method actually executing the call on the server side, RPC client stub method on the client side).
*/
RPC_METHOD: 'rpc.method',
@ -627,11 +638,6 @@ clear whether the exception will escape.
*/
RPC_JSONRPC_VERSION: 'rpc.jsonrpc.version',
/**
* `method` property from request. Unlike `rpc.method`, this may not relate to the actual method being called. Useful for client-side traces since client does not know what will be called on the server.
*/
RPC_JSONRPC_METHOD: 'rpc.jsonrpc.method',
/**
* `id` property of request or response. Since protocol allows id to be int, string, `null` or missing (for notifications), value is expected to be cast to string for simplicity. Use empty string in case of `null` value. Omit entirely if this is a notification.
*/

View File

@ -18,7 +18,7 @@ import { context, ContextManager, trace } from '@opentelemetry/api';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { B3Propagator } from '@opentelemetry/propagator-b3';
import { Resource } from '@opentelemetry/resources';
import { ResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Span, Tracer } from '@opentelemetry/tracing';
import * as assert from 'assert';
import { WebTracerConfig } from '../src';
@ -132,7 +132,7 @@ describe('WebTracerProvider', () => {
assert.ok(span);
assert.ok(span.resource instanceof Resource);
assert.equal(
span.resource.attributes[ResourceAttributes.TELEMETRY_SDK_LANGUAGE],
span.resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],
'webjs'
);
});

View File

@ -4,7 +4,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="${SCRIPT_DIR}/../../"
# freeze the spec version to make SpanAttributess generation reproducible
SPEC_VERSION=v1.4.0
SPEC_VERSION=v1.5.0
GENERATOR_VERSION=0.3.1
cd ${SCRIPT_DIR}
@ -38,12 +38,10 @@ docker run --rm \
-f /source \
code \
--template /templates/SemanticAttributes.ts.j2 \
--output /output/ResourceAttributes.ts \
-Dclass=ResourceAttributes
--output /output/SemanticResourceAttributes.ts \
-Dclass=SemanticResourceAttributes
# Run the automatic linting fixing task to ensure it will pass eslint
cd "$ROOT_DIR/packages/opentelemetry-semantic-conventions"
npm run lint:fix
cd "$ROOT_DIR"
npm run lint:fix:changed