Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(instr-document-load): use exported strings for semconv #2039

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ registerInstrumentations({

See [examples/tracer-web](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/tracer-web) for a short example.

## Semantic Conventions

This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)

Attributes collected:

| Attribute | Short Description | Notes |
| ----------------- | ------------------------------------------------------------------------------ | ------------------------------- |
| `http.url` | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]` | Key: `SEMATTRS_HTTP_URL` |
| `http.user_agent` | Value of the HTTP User-Agent header sent by the client | Key: `SEMATTRS_HTTP_USER_AGENT` |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@opentelemetry/instrumentation": "^0.49.1",
"@opentelemetry/sdk-trace-base": "^1.0.0",
"@opentelemetry/sdk-trace-web": "^1.15.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-document-load#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ import {
} from './types';
import { AttributeNames } from './enums/AttributeNames';
import { VERSION } from './version';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_HTTP_URL,
SEMATTRS_HTTP_USER_AGENT,
} from '@opentelemetry/semantic-conventions';
import {
addSpanPerformancePaintEvents,
getPerformanceNavigationEntries,
Expand Down Expand Up @@ -115,7 +118,7 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
entries
);
if (fetchSpan) {
fetchSpan.setAttribute(SemanticAttributes.HTTP_URL, location.href);
fetchSpan.setAttribute(SEMATTRS_HTTP_URL, location.href);
context.with(trace.setSpan(context.active(), fetchSpan), () => {
addSpanNetworkEvents(fetchSpan, entries);
this._addCustomAttributesOnSpan(
Expand All @@ -127,11 +130,8 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
}
});

rootSpan.setAttribute(SemanticAttributes.HTTP_URL, location.href);
rootSpan.setAttribute(
SemanticAttributes.HTTP_USER_AGENT,
navigator.userAgent
);
rootSpan.setAttribute(SEMATTRS_HTTP_URL, location.href);
rootSpan.setAttribute(SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);

this._addResourcesSpans(rootSpan);

Expand Down Expand Up @@ -196,7 +196,7 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
parentSpan
);
if (span) {
span.setAttribute(SemanticAttributes.HTTP_URL, resource.name);
span.setAttribute(SEMATTRS_HTTP_URL, resource.name);
addSpanNetworkEvents(span, resource);
this._addCustomAttributesOnResourceSpan(
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import {
import chai from 'chai/chai.js';
import * as sinon from 'sinon';
import { DocumentLoadInstrumentation } from '../src';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH,
SEMATTRS_HTTP_URL,
} from '@opentelemetry/semantic-conventions';
import { EventNames } from '../src/enums/EventNames';

const { assert } = chai as typeof import('chai');
Expand Down Expand Up @@ -347,7 +350,7 @@ describe('DocumentLoad Instrumentation', () => {
assert.strictEqual(rootSpan.name, 'documentFetch');
assert.ok(
(rootSpan.attributes[
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH
] as number) > 0
);
assert.strictEqual(fetchSpan.name, 'documentLoad');
Expand Down Expand Up @@ -448,11 +451,11 @@ describe('DocumentLoad Instrumentation', () => {
const srEvents2 = spanResource2.events;

assert.strictEqual(
spanResource1.attributes[SemanticAttributes.HTTP_URL],
spanResource1.attributes[SEMATTRS_HTTP_URL],
'http://localhost:8090/bundle.js'
);
assert.strictEqual(
spanResource2.attributes[SemanticAttributes.HTTP_URL],
spanResource2.attributes[SEMATTRS_HTTP_URL],
'http://localhost:8090/sockjs-node/info?t=1572620894466'
);

Expand Down Expand Up @@ -484,7 +487,7 @@ describe('DocumentLoad Instrumentation', () => {
const srEvents1 = spanResource1.events;

assert.strictEqual(
spanResource1.attributes[SemanticAttributes.HTTP_URL],
spanResource1.attributes[SEMATTRS_HTTP_URL],
'http://localhost:8090/bundle.js'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import { nodeResolve as nodeResolveRollup } from '@rollup/plugin-node-resolve';
import commonjsRollup from '@rollup/plugin-commonjs';
import { esbuildPlugin } from '@web/dev-server-esbuild';
import { fromRollup } from '@web/dev-server-rollup';
import { chromeLauncher } from '@web/test-runner';

const nodeResolve = fromRollup(nodeResolveRollup);
const commonjs = fromRollup(commonjsRollup);

export default {
files: ['test/**/*.test.ts'],
nodeResolve: true,
browsers: [chromeLauncher({ launchOptions: { args: ['--no-sandbox'] } })],
plugins: [
esbuildPlugin({ ts: true }),
nodeResolve({ browser: true, preferBuiltins: false }),
Expand Down