Skip to content

Commit 4d3f899

Browse files
authored
refactor(sdk-trace-web): update semconv usage to ATTR_ exports (#5672)
1 parent 6f72fb9 commit 4d3f899

File tree

6 files changed

+57
-11
lines changed

6 files changed

+57
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
2828

2929
### :house: Internal
3030

31+
* refactor(sdk-trace-web): update semconv usage to ATTR_ exports [#5672](https://github.com/open-telemetry/opentelemetry-js/pull/5672) @trentm
3132
* refactor(resources): update semconv usage to ATTR_ exports [#5666](https://github.com/open-telemetry/opentelemetry-js/pull/5666) @trentm
3233
* test(sdk-metrics): fix multiple problematic assertRejects() calls [#5611](https://github.com/open-telemetry/opentelemetry-js/pull/5611) @cjihrig
3334
* refactor: replace assertRejects() with assert.rejects() [#5614](https://github.com/open-telemetry/opentelemetry-js/pull/5614) @cjihrig

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opentelemetry-sdk-trace-web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@opentelemetry/api": ">=1.0.0 <1.10.0",
6060
"@opentelemetry/context-zone": "2.0.0",
6161
"@opentelemetry/resources": "2.0.0",
62+
"@opentelemetry/semantic-conventions": "^1.29.0",
6263
"@types/jquery": "3.5.32",
6364
"@types/mocha": "10.0.10",
6465
"@types/node": "18.6.5",
@@ -89,8 +90,7 @@
8990
},
9091
"dependencies": {
9192
"@opentelemetry/core": "2.0.0",
92-
"@opentelemetry/sdk-trace-base": "2.0.0",
93-
"@opentelemetry/semantic-conventions": "^1.29.0"
93+
"@opentelemetry/sdk-trace-base": "2.0.0"
9494
},
9595
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-web",
9696
"sideEffects": false
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* This file contains a copy of unstable semantic convention definitions
19+
* used by this package.
20+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
21+
*/
22+
23+
/**
24+
* Deprecated, use `http.response.header.<key>` instead.
25+
*
26+
* @example 3495
27+
*
28+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
29+
*
30+
* @deprecated Replaced by `http.response.header.<key>`.
31+
*/
32+
export const ATTR_HTTP_RESPONSE_CONTENT_LENGTH =
33+
'http.response_content_length' as const;
34+
35+
/**
36+
* Deprecated, use `http.response.body.size` instead.
37+
*
38+
* @example 5493
39+
*
40+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
41+
*
42+
* @deprecated Replace by `http.response.body.size`.
43+
*/
44+
export const ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED =
45+
'http.response_content_length_uncompressed' as const;

packages/opentelemetry-sdk-trace-web/src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import {
2727
urlMatches,
2828
} from '@opentelemetry/core';
2929
import {
30-
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH,
31-
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
32-
} from '@opentelemetry/semantic-conventions';
30+
ATTR_HTTP_RESPONSE_CONTENT_LENGTH,
31+
ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
32+
} from './semconv';
3333

3434
// Used to normalize relative URLs
3535
let urlNormalizingAnchor: HTMLAnchorElement | undefined;
@@ -113,14 +113,14 @@ export function addSpanNetworkEvents(
113113
// *old* HTTP semconv (v1.7.0).
114114
const encodedLength = resource[PTN.ENCODED_BODY_SIZE];
115115
if (encodedLength !== undefined) {
116-
span.setAttribute(SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
116+
span.setAttribute(ATTR_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
117117
}
118118

119119
const decodedLength = resource[PTN.DECODED_BODY_SIZE];
120120
// Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
121121
if (decodedLength !== undefined && encodedLength !== decodedLength) {
122122
span.setAttribute(
123-
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
123+
ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
124124
decodedLength
125125
);
126126
}

packages/opentelemetry-sdk-trace-web/test/WebTracerProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { context, ContextManager, trace } from '@opentelemetry/api';
1818
import { ZoneContextManager } from '@opentelemetry/context-zone';
19-
import { SEMRESATTRS_TELEMETRY_SDK_LANGUAGE } from '@opentelemetry/semantic-conventions';
19+
import { ATTR_TELEMETRY_SDK_LANGUAGE } from '@opentelemetry/semantic-conventions';
2020
import { Span } from '@opentelemetry/sdk-trace-base';
2121
import * as assert from 'assert';
2222
import { WebTracerConfig } from '../src';
@@ -96,7 +96,7 @@ describe('WebTracerProvider', function () {
9696
assert.ok(span);
9797
assert.ok(span.resource);
9898
assert.equal(
99-
span.resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
99+
span.resource.attributes[ATTR_TELEMETRY_SDK_LANGUAGE],
100100
'webjs'
101101
);
102102
});

0 commit comments

Comments
 (0)