Skip to content

Commit

Permalink
Merge branch 'main' into shim-opentracing-semconv
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Jun 3, 2024
2 parents fc832c2 + 04dc781 commit f002387
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
* feat(context-zone*): support zone.js 0.12.x [#4376](https://github.com/open-telemetry/opentelemetry-js/pull/4736) @maldago
* refactor(core): Use tree-shakeable string constants for semconv [#4739](https://github.com/open-telemetry/opentelemetry-js/pull/4739) @JohannesHuster
* refactor(shim-opentracing): Use tree-shakeable string constants for semconv [#4746](https://github.com/open-telemetry/opentelemetry-js/pull/4746) @JohannesHuster
* refactor(sdk-trace-web): Use tree-shakeable string constants for semconv [#4747](https://github.com/open-telemetry/opentelemetry-js/pull/4747) @JohannesHuster
* refactor(sdk-trace-node): Use tree-shakeable string constants for semconv [#4748](https://github.com/open-telemetry/opentelemetry-js/pull/4748) @JohannesHuster
* refactor(sdk-trace-base): Use tree-shakeable string constants for semconv [#4749](https://github.com/open-telemetry/opentelemetry-js/pull/4749) @JohannesHuster

### :bug: (Bug Fix)

Expand Down
82 changes: 41 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"karma-spec-reporter": "0.0.36",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"linkinator": "6.0.4",
"linkinator": "6.0.5",
"markdownlint-cli2": "0.13.0",
"prettier": "3.0.3",
"process": "0.11.10",
Expand Down
21 changes: 12 additions & 9 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import {
sanitizeAttributes,
} from '@opentelemetry/core';
import { IResource } from '@opentelemetry/resources';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_EXCEPTION_MESSAGE,
SEMATTRS_EXCEPTION_STACKTRACE,
SEMATTRS_EXCEPTION_TYPE,
} from '@opentelemetry/semantic-conventions';
import { ExceptionEventName } from './enums';
import { ReadableSpan } from './export/ReadableSpan';
import { SpanProcessor } from './SpanProcessor';
Expand Down Expand Up @@ -299,26 +303,25 @@ export class Span implements APISpan, ReadableSpan {
recordException(exception: Exception, time?: TimeInput): void {
const attributes: SpanAttributes = {};
if (typeof exception === 'string') {
attributes[SemanticAttributes.EXCEPTION_MESSAGE] = exception;
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception;
} else if (exception) {
if (exception.code) {
attributes[SemanticAttributes.EXCEPTION_TYPE] =
exception.code.toString();
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.code.toString();
} else if (exception.name) {
attributes[SemanticAttributes.EXCEPTION_TYPE] = exception.name;
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.name;
}
if (exception.message) {
attributes[SemanticAttributes.EXCEPTION_MESSAGE] = exception.message;
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception.message;
}
if (exception.stack) {
attributes[SemanticAttributes.EXCEPTION_STACKTRACE] = exception.stack;
attributes[SEMATTRS_EXCEPTION_STACKTRACE] = exception.stack;
}
}

// these are minimum requirements from spec
if (
attributes[SemanticAttributes.EXCEPTION_TYPE] ||
attributes[SemanticAttributes.EXCEPTION_MESSAGE]
attributes[SEMATTRS_EXCEPTION_TYPE] ||
attributes[SEMATTRS_EXCEPTION_MESSAGE]
) {
this.addEvent(ExceptionEventName, attributes, time);
} else {
Expand Down
15 changes: 9 additions & 6 deletions packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ import {
hrTimeToNanoseconds,
otperformance as performance,
} from '@opentelemetry/core';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_EXCEPTION_MESSAGE,
SEMATTRS_EXCEPTION_STACKTRACE,
SEMATTRS_EXCEPTION_TYPE,
} from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import * as sinon from 'sinon';
import { BasicTracerProvider, Span, SpanProcessor } from '../../src';
Expand Down Expand Up @@ -1250,11 +1254,10 @@ describe('Span', () => {

assert.ok(event.attributes);

const type = event.attributes[SemanticAttributes.EXCEPTION_TYPE];
const message =
event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];
const type = event.attributes[SEMATTRS_EXCEPTION_TYPE];
const message = event.attributes[SEMATTRS_EXCEPTION_MESSAGE];
const stacktrace = String(
event.attributes[SemanticAttributes.EXCEPTION_STACKTRACE]
event.attributes[SEMATTRS_EXCEPTION_STACKTRACE]
);
assert.strictEqual(type, 'Error');
assert.strictEqual(message, 'boom');
Expand Down Expand Up @@ -1294,7 +1297,7 @@ describe('Span', () => {
span.recordException({ code: 12 });
const event = span.events[0];
assert.deepStrictEqual(event.attributes, {
[SemanticAttributes.EXCEPTION_TYPE]: '12',
[SEMATTRS_EXCEPTION_TYPE]: '12',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
SpanExporter,
} from '@opentelemetry/sdk-trace-base';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SEMRESATTRS_TELEMETRY_SDK_LANGUAGE } from '@opentelemetry/semantic-conventions';

import { NodeTracerProvider } from '../src/NodeTracerProvider';

Expand Down Expand Up @@ -152,9 +152,7 @@ describe('NodeTracerProvider', () => {
assert.ok(span);
assert.ok(span.resource instanceof Resource);
assert.equal(
span.resource.attributes[
SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE
],
span.resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
'nodejs'
);
});
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-sdk-trace-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
timeInputToHrTime,
urlMatches,
} from '@opentelemetry/core';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH,
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
} from '@opentelemetry/semantic-conventions';

// Used to normalize relative URLs
let urlNormalizingAnchor: HTMLAnchorElement | undefined;
Expand Down Expand Up @@ -110,16 +113,13 @@ export function addSpanNetworkEvents(
addSpanNetworkEvent(span, PTN.RESPONSE_END, resource);
const encodedLength = resource[PTN.ENCODED_BODY_SIZE];
if (encodedLength !== undefined) {
span.setAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
encodedLength
);
span.setAttribute(SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
}
const decodedLength = resource[PTN.DECODED_BODY_SIZE];
// Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
if (decodedLength !== undefined && encodedLength !== decodedLength) {
span.setAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
decodedLength
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SEMRESATTRS_TELEMETRY_SDK_LANGUAGE } from '@opentelemetry/semantic-conventions';
import { Span, Tracer } from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
import { WebTracerConfig } from '../src';
Expand Down Expand Up @@ -130,9 +130,7 @@ describe('WebTracerProvider', () => {
assert.ok(span);
assert.ok(span.resource instanceof Resource);
assert.equal(
span.resource.attributes[
SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE
],
span.resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
'webjs'
);
});
Expand Down
2 changes: 1 addition & 1 deletion selenium-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"babel-loader": "8.3.0",
"babel-polyfill": "6.26.0",
"browserstack-local": "1.4.8",
"chromedriver": "125.0.2",
"chromedriver": "125.0.3",
"dotenv": "16.0.0",
"fast-safe-stringify": "2.1.1",
"geckodriver": "3.0.1",
Expand Down

0 comments on commit f002387

Please sign in to comment.