Skip to content

Commit a06c9ae

Browse files
authored
Merge branch 'main' into metrics-ff/metric-name
2 parents bdc81da + faca317 commit a06c9ae

10 files changed

Lines changed: 95 additions & 33 deletions

File tree

experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,15 @@ export class FetchInstrumentation extends InstrumentationBase<
331331
): void {
332332
try {
333333
const resClone = response.clone();
334+
const resClone4Hook = response.clone();
334335
const body = resClone.body;
335336
if (body) {
336337
const reader = body.getReader();
337338
const read = (): void => {
338339
reader.read().then(
339340
({ done }) => {
340341
if (done) {
341-
endSpanOnSuccess(span, response);
342+
endSpanOnSuccess(span, resClone4Hook);
342343
} else {
343344
read();
344345
}

experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,22 @@ describe('fetch', () => {
683683

684684
prepare(url, applyCustomAttributes);
685685
});
686+
687+
it('get response body from callback arguments response', done => {
688+
const applyCustomAttributes: FetchCustomAttributeFunction = async (
689+
span,
690+
request,
691+
response
692+
) => {
693+
if(response instanceof Response ){
694+
const rsp = await response.json();
695+
assert.deepStrictEqual(rsp.args, {});
696+
done();
697+
}
698+
};
699+
700+
prepare(url, applyCustomAttributes);
701+
});
686702
});
687703

688704
describe('when url is ignored', () => {

packages/opentelemetry-core/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"@opentelemetry/api": "^1.0.2",
6161
"@types/mocha": "8.2.3",
6262
"@types/node": "14.17.11",
63-
"@types/semver": "7.3.8",
6463
"@types/sinon": "10.0.2",
6564
"@types/webpack-env": "1.16.2",
6665
"codecov": "3.8.3",
@@ -84,7 +83,6 @@
8483
"@opentelemetry/api": "^1.0.2"
8584
},
8685
"dependencies": {
87-
"@opentelemetry/semantic-conventions": "1.0.0",
88-
"semver": "^7.3.5"
86+
"@opentelemetry/semantic-conventions": "1.0.0"
8987
}
9088
}

packages/opentelemetry-exporter-zipkin/src/transform.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const ZIPKIN_SPAN_KIND_MAPPING = {
2929
[api.SpanKind.INTERNAL]: undefined,
3030
};
3131

32-
export const defaultStatusCodeTagName = 'ot.status_code';
33-
export const defaultStatusDescriptionTagName = 'ot.status_description';
32+
export const defaultStatusCodeTagName = 'otel.status_code';
33+
export const defaultStatusErrorTagName = 'error';
3434

3535
/**
3636
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
@@ -40,7 +40,7 @@ export function toZipkinSpan(
4040
span: ReadableSpan,
4141
serviceName: string,
4242
statusCodeTagName: string,
43-
statusDescriptionTagName: string
43+
statusErrorTagName: string
4444
): zipkinTypes.Span {
4545
const zipkinSpan: zipkinTypes.Span = {
4646
traceId: span.spanContext().traceId,
@@ -55,7 +55,7 @@ export function toZipkinSpan(
5555
span.attributes,
5656
span.status,
5757
statusCodeTagName,
58-
statusDescriptionTagName,
58+
statusErrorTagName,
5959
span.resource
6060
),
6161
annotations: span.events.length
@@ -71,16 +71,18 @@ export function _toZipkinTags(
7171
attributes: api.SpanAttributes,
7272
status: api.SpanStatus,
7373
statusCodeTagName: string,
74-
statusDescriptionTagName: string,
74+
statusErrorTagName: string,
7575
resource: Resource
7676
): zipkinTypes.Tags {
7777
const tags: { [key: string]: string } = {};
7878
for (const key of Object.keys(attributes)) {
7979
tags[key] = String(attributes[key]);
8080
}
81-
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
82-
if (status.message) {
83-
tags[statusDescriptionTagName] = status.message;
81+
if (status.code !== api.SpanStatusCode.UNSET) {
82+
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
83+
}
84+
if (status.code === api.SpanStatusCode.ERROR && status.message) {
85+
tags[statusErrorTagName] = status.message;
8486
}
8587

8688
Object.keys(resource.attributes).forEach(

packages/opentelemetry-exporter-zipkin/src/zipkin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as zipkinTypes from './types';
2222
import {
2323
toZipkinSpan,
2424
defaultStatusCodeTagName,
25-
defaultStatusDescriptionTagName,
25+
defaultStatusErrorTagName,
2626
} from './transform';
2727
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
2828
import { prepareGetHeaders } from './utils';
@@ -47,7 +47,7 @@ export class ZipkinExporter implements SpanExporter {
4747
this._serviceName = config.serviceName;
4848
this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName;
4949
this._statusDescriptionTagName =
50-
config.statusDescriptionTagName || defaultStatusDescriptionTagName;
50+
config.statusDescriptionTagName || defaultStatusErrorTagName;
5151
this._isShutdown = false;
5252
if (typeof config.getExportRequestHeaders === 'function') {
5353
this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders);

packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as assert from 'assert';
2626
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
2727
import {
2828
defaultStatusCodeTagName,
29-
defaultStatusDescriptionTagName,
29+
defaultStatusErrorTagName,
3030
toZipkinSpan,
3131
_toZipkinAnnotations,
3232
_toZipkinTags,
@@ -79,7 +79,7 @@ describe('transform', () => {
7979
span,
8080
'my-service',
8181
defaultStatusCodeTagName,
82-
defaultStatusDescriptionTagName
82+
defaultStatusErrorTagName
8383
);
8484
assert.deepStrictEqual(zipkinSpan, {
8585
kind: 'SERVER',
@@ -101,7 +101,6 @@ describe('transform', () => {
101101
tags: {
102102
key1: 'value1',
103103
key2: 'value2',
104-
[defaultStatusCodeTagName]: 'UNSET',
105104
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
106105
'telemetry.sdk.language': language,
107106
'telemetry.sdk.name': 'opentelemetry',
@@ -125,7 +124,7 @@ describe('transform', () => {
125124
span,
126125
'my-service',
127126
defaultStatusCodeTagName,
128-
defaultStatusDescriptionTagName
127+
defaultStatusErrorTagName
129128
);
130129
assert.deepStrictEqual(zipkinSpan, {
131130
kind: 'SERVER',
@@ -140,7 +139,6 @@ describe('transform', () => {
140139
name: span.name,
141140
parentId: undefined,
142141
tags: {
143-
[defaultStatusCodeTagName]: 'UNSET',
144142
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
145143
'telemetry.sdk.language': language,
146144
'telemetry.sdk.name': 'opentelemetry',
@@ -174,7 +172,7 @@ describe('transform', () => {
174172
span,
175173
'my-service',
176174
defaultStatusCodeTagName,
177-
defaultStatusDescriptionTagName
175+
defaultStatusErrorTagName
178176
);
179177
assert.deepStrictEqual(zipkinSpan, {
180178
kind: item.zipkin,
@@ -189,7 +187,6 @@ describe('transform', () => {
189187
name: span.name,
190188
parentId: undefined,
191189
tags: {
192-
[defaultStatusCodeTagName]: 'UNSET',
193190
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
194191
'telemetry.sdk.language': language,
195192
'telemetry.sdk.name': 'opentelemetry',
@@ -220,14 +217,13 @@ describe('transform', () => {
220217
span.attributes,
221218
span.status,
222219
defaultStatusCodeTagName,
223-
defaultStatusDescriptionTagName,
220+
defaultStatusErrorTagName,
224221
DUMMY_RESOURCE
225222
);
226223

227224
assert.deepStrictEqual(tags, {
228225
key1: 'value1',
229226
key2: 'value2',
230-
[defaultStatusCodeTagName]: 'UNSET',
231227
cost: '112.12',
232228
service: 'ui',
233229
version: '1',
@@ -255,7 +251,7 @@ describe('transform', () => {
255251
span.attributes,
256252
span.status,
257253
defaultStatusCodeTagName,
258-
defaultStatusDescriptionTagName,
254+
defaultStatusErrorTagName,
259255
Resource.empty().merge(
260256
new Resource({
261257
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
@@ -292,7 +288,7 @@ describe('transform', () => {
292288
span.attributes,
293289
span.status,
294290
defaultStatusCodeTagName,
295-
defaultStatusDescriptionTagName,
291+
defaultStatusErrorTagName,
296292
Resource.empty().merge(
297293
new Resource({
298294
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
@@ -304,7 +300,7 @@ describe('transform', () => {
304300
key1: 'value1',
305301
key2: 'value2',
306302
[defaultStatusCodeTagName]: 'ERROR',
307-
[defaultStatusDescriptionTagName]: status.message,
303+
[defaultStatusErrorTagName]: status.message,
308304
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
309305
});
310306
});

packages/opentelemetry-exporter-zipkin/test/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function ensureSpanIsCorrect(span: Span) {
7171
localEndpoint: { serviceName: 'OpenTelemetry Service' },
7272
tags: {
7373
component: 'foo',
74-
'ot.status_code': 'OK',
74+
'otel.status_code': 'OK',
7575
service: 'ui',
7676
version: '1',
7777
cost: '112.12',

packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('Zipkin Exporter - node', () => {
215215
tags: {
216216
key1: 'value1',
217217
key2: 'value2',
218-
'ot.status_code': 'OK',
218+
'otel.status_code': 'OK',
219219
},
220220
timestamp: startTime * MICROS_PER_SECS,
221221
traceId: span1.spanContext().traceId,
@@ -230,7 +230,7 @@ describe('Zipkin Exporter - node', () => {
230230
},
231231
name: span2.name,
232232
tags: {
233-
'ot.status_code': 'OK',
233+
'otel.status_code': 'OK',
234234
},
235235
timestamp: hrTimeToMicroseconds([startTime, 0]),
236236
traceId: span2.spanContext().traceId,

packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ clear whether the exception will escape.
372372
HTTP_TARGET: 'http.target',
373373

374374
/**
375-
* 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.
375+
* 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.
376+
*
377+
* 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.
376378
*/
377379
HTTP_HOST: 'http.host',
378380

@@ -433,7 +435,17 @@ clear whether the exception will escape.
433435
/**
434436
* 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)).
435437
*
436-
* Note: This is not necessarily the same as `net.peer.ip`, which would identify the network-level peer, which may be a proxy.
438+
* Note: This is not necessarily the same as `net.peer.ip`, which would
439+
identify the network-level peer, which may be a proxy.
440+
441+
This attribute should be set when a source of information different
442+
from the one used for `net.peer.ip`, is available even if that other
443+
source just confirms the same value as `net.peer.ip`.
444+
Rationale: For `net.peer.ip`, one typically does not know if it
445+
comes from a proxy, reverse proxy, or the actual client. Setting
446+
`http.client_ip` when it&#39;s the same as `net.peer.ip` means that
447+
one is at least somewhat confident that the address is not that of
448+
the closest proxy.
437449
*/
438450
HTTP_CLIENT_IP: 'http.client_ip',
439451

@@ -607,6 +619,11 @@ clear whether the exception will escape.
607619
*/
608620
MESSAGING_OPERATION: 'messaging.operation',
609621

622+
/**
623+
* 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.
624+
*/
625+
MESSAGING_CONSUMER_ID: 'messaging.consumer_id',
626+
610627
/**
611628
* RabbitMQ message routing key.
612629
*/
@@ -682,6 +699,28 @@ clear whether the exception will escape.
682699
* `error.message` property of response if it is an error response.
683700
*/
684701
RPC_JSONRPC_ERROR_MESSAGE: 'rpc.jsonrpc.error_message',
702+
703+
/**
704+
* Whether this is a received or sent message.
705+
*/
706+
MESSAGE_TYPE: 'message.type',
707+
708+
/**
709+
* MUST be calculated as two different counters starting from `1` one for sent messages and one for received message.
710+
*
711+
* Note: This way we guarantee that the values will be consistent between different implementations.
712+
*/
713+
MESSAGE_ID: 'message.id',
714+
715+
/**
716+
* Compressed size of the message in bytes.
717+
*/
718+
MESSAGE_COMPRESSED_SIZE: 'message.compressed_size',
719+
720+
/**
721+
* Uncompressed size of the message in bytes.
722+
*/
723+
MESSAGE_UNCOMPRESSED_SIZE: 'message.uncompressed_size',
685724
}
686725

687726
// Enum definitions
@@ -1014,3 +1053,13 @@ export enum RpcGrpcStatusCodeValues {
10141053
UNAUTHENTICATED = 16,
10151054
}
10161055

1056+
1057+
1058+
1059+
export enum MessageTypeValues {
1060+
/** sent. */
1061+
SENT = 'SENT',
1062+
/** received. */
1063+
RECEIVED = 'RECEIVED',
1064+
}
1065+

scripts/semconv/generate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44
ROOT_DIR="${SCRIPT_DIR}/../../"
55

66
# freeze the spec version to make SpanAttributess generation reproducible
7-
SPEC_VERSION=v1.6.1
8-
GENERATOR_VERSION=0.5.0
7+
SPEC_VERSION=v1.7.0
8+
GENERATOR_VERSION=0.7.0
99

1010
cd ${SCRIPT_DIR}
1111

0 commit comments

Comments
 (0)