From 0c7f1c3ae9b8fcc0b7943c074319ef6c0265cb12 Mon Sep 17 00:00:00 2001 From: Weyert de Boer Date: Sat, 9 Oct 2021 14:45:43 +0100 Subject: [PATCH 1/2] feat: upgrade semantic-conventions to latest v1.7.0 spec (#2528) Co-authored-by: Weyert de Boer --- .../src/trace/SemanticAttributes.ts | 53 ++++++++++++++++++- scripts/semconv/generate.sh | 4 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts b/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts index eb7260c0738..48fecf29bed 100644 --- a/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts +++ b/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts @@ -372,7 +372,9 @@ clear whether the exception will escape. HTTP_TARGET: 'http.target', /** - * The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. + * The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). An empty Host header should also be reported, see note. + * + * Note: When the header is present but empty the attribute SHOULD be set to the empty string. Note that this is a valid situation that is expected in certain cases, according the aforementioned [section of RFC 7230](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is not set the attribute MUST NOT be set. */ HTTP_HOST: 'http.host', @@ -433,7 +435,17 @@ clear whether the exception will escape. /** * The IP address of the original client behind all proxies, if known (e.g. from [X-Forwarded-For](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For)). * - * Note: This is not necessarily the same as `net.peer.ip`, which would identify the network-level peer, which may be a proxy. + * Note: This is not necessarily the same as `net.peer.ip`, which would +identify the network-level peer, which may be a proxy. + +This attribute should be set when a source of information different +from the one used for `net.peer.ip`, is available even if that other +source just confirms the same value as `net.peer.ip`. +Rationale: For `net.peer.ip`, one typically does not know if it +comes from a proxy, reverse proxy, or the actual client. Setting +`http.client_ip` when it's the same as `net.peer.ip` means that +one is at least somewhat confident that the address is not that of +the closest proxy. */ HTTP_CLIENT_IP: 'http.client_ip', @@ -607,6 +619,11 @@ clear whether the exception will escape. */ MESSAGING_OPERATION: 'messaging.operation', + /** + * The identifier for the consumer receiving a message. For Kafka, set it to `{messaging.kafka.consumer_group} - {messaging.kafka.client_id}`, if both are present, or only `messaging.kafka.consumer_group`. For brokers, such as RabbitMQ and Artemis, set it to the `client_id` of the client consuming the message. + */ + MESSAGING_CONSUMER_ID: 'messaging.consumer_id', + /** * RabbitMQ message routing key. */ @@ -682,6 +699,28 @@ clear whether the exception will escape. * `error.message` property of response if it is an error response. */ RPC_JSONRPC_ERROR_MESSAGE: 'rpc.jsonrpc.error_message', + + /** + * Whether this is a received or sent message. + */ + MESSAGE_TYPE: 'message.type', + + /** + * MUST be calculated as two different counters starting from `1` one for sent messages and one for received message. + * + * Note: This way we guarantee that the values will be consistent between different implementations. + */ + MESSAGE_ID: 'message.id', + + /** + * Compressed size of the message in bytes. + */ + MESSAGE_COMPRESSED_SIZE: 'message.compressed_size', + + /** + * Uncompressed size of the message in bytes. + */ + MESSAGE_UNCOMPRESSED_SIZE: 'message.uncompressed_size', } // Enum definitions @@ -1014,3 +1053,13 @@ export enum RpcGrpcStatusCodeValues { UNAUTHENTICATED = 16, } + + + +export enum MessageTypeValues { + /** sent. */ + SENT = 'SENT', + /** received. */ + RECEIVED = 'RECEIVED', +} + diff --git a/scripts/semconv/generate.sh b/scripts/semconv/generate.sh index 89718f52e1b..dbd99464eac 100755 --- a/scripts/semconv/generate.sh +++ b/scripts/semconv/generate.sh @@ -4,8 +4,8 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ROOT_DIR="${SCRIPT_DIR}/../../" # freeze the spec version to make SpanAttributess generation reproducible -SPEC_VERSION=v1.6.1 -GENERATOR_VERSION=0.5.0 +SPEC_VERSION=v1.7.0 +GENERATOR_VERSION=0.7.0 cd ${SCRIPT_DIR} From 8d433248711804f2e06e32e7b0cbe9957494978f Mon Sep 17 00:00:00 2001 From: t2t2 Date: Sat, 9 Oct 2021 16:57:36 +0300 Subject: [PATCH 2/2] fix(exporter-zipkin): correct status tags names (#2519) Co-authored-by: Valentin Marchaud --- .../src/transform.ts | 18 +++++++++-------- .../src/zipkin.ts | 4 ++-- .../test/common/transform.test.ts | 20 ++++++++----------- .../test/helper.ts | 2 +- .../test/node/zipkin.test.ts | 4 ++-- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index 64e4b48bbf6..9ffd48ecce7 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -29,8 +29,8 @@ const ZIPKIN_SPAN_KIND_MAPPING = { [api.SpanKind.INTERNAL]: undefined, }; -export const defaultStatusCodeTagName = 'ot.status_code'; -export const defaultStatusDescriptionTagName = 'ot.status_description'; +export const defaultStatusCodeTagName = 'otel.status_code'; +export const defaultStatusErrorTagName = 'error'; /** * Translate OpenTelemetry ReadableSpan to ZipkinSpan format @@ -40,7 +40,7 @@ export function toZipkinSpan( span: ReadableSpan, serviceName: string, statusCodeTagName: string, - statusDescriptionTagName: string + statusErrorTagName: string ): zipkinTypes.Span { const zipkinSpan: zipkinTypes.Span = { traceId: span.spanContext().traceId, @@ -55,7 +55,7 @@ export function toZipkinSpan( span.attributes, span.status, statusCodeTagName, - statusDescriptionTagName, + statusErrorTagName, span.resource ), annotations: span.events.length @@ -71,16 +71,18 @@ export function _toZipkinTags( attributes: api.SpanAttributes, status: api.SpanStatus, statusCodeTagName: string, - statusDescriptionTagName: string, + statusErrorTagName: string, resource: Resource ): zipkinTypes.Tags { const tags: { [key: string]: string } = {}; for (const key of Object.keys(attributes)) { tags[key] = String(attributes[key]); } - tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]); - if (status.message) { - tags[statusDescriptionTagName] = status.message; + if (status.code !== api.SpanStatusCode.UNSET) { + tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]); + } + if (status.code === api.SpanStatusCode.ERROR && status.message) { + tags[statusErrorTagName] = status.message; } Object.keys(resource.attributes).forEach( diff --git a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts index ef43cff0f89..614d728cb5b 100644 --- a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts +++ b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts @@ -22,7 +22,7 @@ import * as zipkinTypes from './types'; import { toZipkinSpan, defaultStatusCodeTagName, - defaultStatusDescriptionTagName, + defaultStatusErrorTagName, } from './transform'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import { prepareGetHeaders } from './utils'; @@ -47,7 +47,7 @@ export class ZipkinExporter implements SpanExporter { this._serviceName = config.serviceName; this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName; this._statusDescriptionTagName = - config.statusDescriptionTagName || defaultStatusDescriptionTagName; + config.statusDescriptionTagName || defaultStatusErrorTagName; this._isShutdown = false; if (typeof config.getExportRequestHeaders === 'function') { this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders); diff --git a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts index ca8d37aa752..3c7b5a5ddb2 100644 --- a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts @@ -26,7 +26,7 @@ import * as assert from 'assert'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import { defaultStatusCodeTagName, - defaultStatusDescriptionTagName, + defaultStatusErrorTagName, toZipkinSpan, _toZipkinAnnotations, _toZipkinTags, @@ -79,7 +79,7 @@ describe('transform', () => { span, 'my-service', defaultStatusCodeTagName, - defaultStatusDescriptionTagName + defaultStatusErrorTagName ); assert.deepStrictEqual(zipkinSpan, { kind: 'SERVER', @@ -101,7 +101,6 @@ describe('transform', () => { tags: { key1: 'value1', key2: 'value2', - [defaultStatusCodeTagName]: 'UNSET', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', @@ -125,7 +124,7 @@ describe('transform', () => { span, 'my-service', defaultStatusCodeTagName, - defaultStatusDescriptionTagName + defaultStatusErrorTagName ); assert.deepStrictEqual(zipkinSpan, { kind: 'SERVER', @@ -140,7 +139,6 @@ describe('transform', () => { name: span.name, parentId: undefined, tags: { - [defaultStatusCodeTagName]: 'UNSET', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', @@ -174,7 +172,7 @@ describe('transform', () => { span, 'my-service', defaultStatusCodeTagName, - defaultStatusDescriptionTagName + defaultStatusErrorTagName ); assert.deepStrictEqual(zipkinSpan, { kind: item.zipkin, @@ -189,7 +187,6 @@ describe('transform', () => { name: span.name, parentId: undefined, tags: { - [defaultStatusCodeTagName]: 'UNSET', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', @@ -220,14 +217,13 @@ describe('transform', () => { span.attributes, span.status, defaultStatusCodeTagName, - defaultStatusDescriptionTagName, + defaultStatusErrorTagName, DUMMY_RESOURCE ); assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [defaultStatusCodeTagName]: 'UNSET', cost: '112.12', service: 'ui', version: '1', @@ -255,7 +251,7 @@ describe('transform', () => { span.attributes, span.status, defaultStatusCodeTagName, - defaultStatusDescriptionTagName, + defaultStatusErrorTagName, Resource.empty().merge( new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', @@ -292,7 +288,7 @@ describe('transform', () => { span.attributes, span.status, defaultStatusCodeTagName, - defaultStatusDescriptionTagName, + defaultStatusErrorTagName, Resource.empty().merge( new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', @@ -304,7 +300,7 @@ describe('transform', () => { key1: 'value1', key2: 'value2', [defaultStatusCodeTagName]: 'ERROR', - [defaultStatusDescriptionTagName]: status.message, + [defaultStatusErrorTagName]: status.message, [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', }); }); diff --git a/packages/opentelemetry-exporter-zipkin/test/helper.ts b/packages/opentelemetry-exporter-zipkin/test/helper.ts index b6896313296..c2e13dcdd8d 100644 --- a/packages/opentelemetry-exporter-zipkin/test/helper.ts +++ b/packages/opentelemetry-exporter-zipkin/test/helper.ts @@ -71,7 +71,7 @@ export function ensureSpanIsCorrect(span: Span) { localEndpoint: { serviceName: 'OpenTelemetry Service' }, tags: { component: 'foo', - 'ot.status_code': 'OK', + 'otel.status_code': 'OK', service: 'ui', version: '1', cost: '112.12', diff --git a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts index 8749917fe91..d78b46159c7 100644 --- a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts @@ -215,7 +215,7 @@ describe('Zipkin Exporter - node', () => { tags: { key1: 'value1', key2: 'value2', - 'ot.status_code': 'OK', + 'otel.status_code': 'OK', }, timestamp: startTime * MICROS_PER_SECS, traceId: span1.spanContext().traceId, @@ -230,7 +230,7 @@ describe('Zipkin Exporter - node', () => { }, name: span2.name, tags: { - 'ot.status_code': 'OK', + 'otel.status_code': 'OK', }, timestamp: hrTimeToMicroseconds([startTime, 0]), traceId: span2.spanContext().traceId,