Skip to content

Commit

Permalink
Merge branch 'main' into remove-semver
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Oct 9, 2021
2 parents 4460b12 + 8d43324 commit 62d7697
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 29 deletions.
18 changes: 10 additions & 8 deletions packages/opentelemetry-exporter-zipkin/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -55,7 +55,7 @@ export function toZipkinSpan(
span.attributes,
span.status,
statusCodeTagName,
statusDescriptionTagName,
statusErrorTagName,
span.resource
),
annotations: span.events.length
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as assert from 'assert';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import {
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
toZipkinSpan,
_toZipkinAnnotations,
_toZipkinTags,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('transform', () => {
span,
'my-service',
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
defaultStatusErrorTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: 'SERVER',
Expand All @@ -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',
Expand All @@ -125,7 +124,7 @@ describe('transform', () => {
span,
'my-service',
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
defaultStatusErrorTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: 'SERVER',
Expand All @@ -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',
Expand Down Expand Up @@ -174,7 +172,7 @@ describe('transform', () => {
span,
'my-service',
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
defaultStatusErrorTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: item.zipkin,
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -255,7 +251,7 @@ describe('transform', () => {
span.attributes,
span.status,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
Resource.empty().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
Expand Down Expand Up @@ -292,7 +288,7 @@ describe('transform', () => {
span.attributes,
span.status,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
Resource.empty().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
Expand All @@ -304,7 +300,7 @@ describe('transform', () => {
key1: 'value1',
key2: 'value2',
[defaultStatusCodeTagName]: 'ERROR',
[defaultStatusDescriptionTagName]: status.message,
[defaultStatusErrorTagName]: status.message,
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-zipkin/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down Expand Up @@ -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',

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1014,3 +1053,13 @@ export enum RpcGrpcStatusCodeValues {
UNAUTHENTICATED = 16,
}




export enum MessageTypeValues {
/** sent. */
SENT = 'SENT',
/** received. */
RECEIVED = 'RECEIVED',
}

4 changes: 2 additions & 2 deletions scripts/semconv/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down

0 comments on commit 62d7697

Please sign in to comment.