Skip to content

Commit

Permalink
Merge branch 'main' into fix/host-metrics-bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
Netail committed Apr 2, 2024
2 parents 60e0933 + 35e6607 commit 65aabe7
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 50 deletions.
1 change: 1 addition & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ components:
plugins/node/opentelemetry-instrumentation-runtime-node:
- d4nyll
plugins/node/opentelemetry-instrumentation-pg:
- maryliag
- rauno56
plugins/node/opentelemetry-instrumentation-pino:
- seemk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-alibaba-cloud#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ import {
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
CloudPlatformValues,
CloudProviderValues,
SemanticResourceAttributes,
CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
SEMRESATTRS_CLOUD_ACCOUNT_ID,
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
SEMRESATTRS_CLOUD_PLATFORM,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_REGION,
SEMRESATTRS_HOST_ID,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_HOST_TYPE,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';

Expand Down Expand Up @@ -61,16 +68,14 @@ class AlibabaCloudEcsDetector implements Detector {
const hostname = await this._fetchHost();

return new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]:
CloudProviderValues.ALIBABA_CLOUD,
[SemanticResourceAttributes.CLOUD_PLATFORM]:
CloudPlatformValues.ALIBABA_CLOUD_ECS,
[SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: accountId,
[SemanticResourceAttributes.CLOUD_REGION]: region,
[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SemanticResourceAttributes.HOST_ID]: instanceId,
[SemanticResourceAttributes.HOST_TYPE]: instanceType,
[SemanticResourceAttributes.HOST_NAME]: hostname,
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
[SEMRESATTRS_CLOUD_REGION]: region,
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone,
[SEMRESATTRS_HOST_ID]: instanceId,
[SEMRESATTRS_HOST_TYPE]: instanceType,
[SEMRESATTRS_HOST_NAME]: hostname,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as nock from 'nock';
import * as assert from 'assert';
import { Resource } from '@opentelemetry/resources';
import { CloudProviderValues } from '@opentelemetry/semantic-conventions';
import { CLOUDPROVIDERVALUES_ALIBABA_CLOUD } from '@opentelemetry/semantic-conventions';
import { alibabaCloudEcsDetector } from '../../src';
import {
assertCloudResource,
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('alibabaCloudEcsDetector', () => {
assert.ok(resource);

assertCloudResource(resource, {
provider: CloudProviderValues.ALIBABA_CLOUD,
provider: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
accountId: 'my-owner-account-id',
region: 'my-region-id',
zone: 'my-zone-id',
Expand Down
12 changes: 6 additions & 6 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 @@ -67,7 +67,7 @@
"dependencies": {
"@opentelemetry/core": "^1.8.0",
"@opentelemetry/instrumentation": "^0.49.1",
"@opentelemetry/semantic-conventions": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"@types/koa": "2.14.0",
"@types/koa__router": "12.0.3"
},
Expand Down
4 changes: 2 additions & 2 deletions plugins/node/opentelemetry-instrumentation-koa/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { KoaContext, KoaLayerType, KoaInstrumentationConfig } from './types';
import { KoaMiddleware } from './internal-types';
import { AttributeNames } from './enums/AttributeNames';
import { Attributes } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';

export const getMiddlewareMetadata = (
context: KoaContext,
Expand All @@ -33,7 +33,7 @@ export const getMiddlewareMetadata = (
attributes: {
[AttributeNames.KOA_NAME]: layerPath?.toString(),
[AttributeNames.KOA_TYPE]: KoaLayerType.ROUTER,
[SemanticAttributes.HTTP_ROUTE]: layerPath?.toString(),
[SEMATTRS_HTTP_ROUTE]: layerPath?.toString(),
},
name: context._matchedRouteName || `router - ${layerPath}`,
};
Expand Down
23 changes: 12 additions & 11 deletions plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_EXCEPTION_MESSAGE,
SEMATTRS_HTTP_METHOD,
SEMATTRS_HTTP_ROUTE,
} from '@opentelemetry/semantic-conventions';

import { KoaInstrumentation } from '../src';
const plugin = new KoaInstrumentation();
Expand Down Expand Up @@ -175,7 +179,7 @@ describe('Koa Instrumentation', () => {
);

assert.strictEqual(
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
'/post/:id'
);

Expand Down Expand Up @@ -226,7 +230,7 @@ describe('Koa Instrumentation', () => {
);

assert.strictEqual(
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
'/^\\/post/'
);

Expand Down Expand Up @@ -273,7 +277,7 @@ describe('Koa Instrumentation', () => {
);

assert.strictEqual(
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
'/post/:id'
);

Expand Down Expand Up @@ -322,7 +326,7 @@ describe('Koa Instrumentation', () => {
);

assert.strictEqual(
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
'/:first/post/:id'
);

Expand Down Expand Up @@ -369,7 +373,7 @@ describe('Koa Instrumentation', () => {
);

assert.strictEqual(
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
'/:first/post/:id'
);

Expand Down Expand Up @@ -570,7 +574,7 @@ describe('Koa Instrumentation', () => {
assert.ok(exceptionEvent, 'There should be an exception event recorded');
assert.deepStrictEqual(exceptionEvent.name, 'exception');
assert.deepStrictEqual(
exceptionEvent.attributes![SemanticAttributes.EXCEPTION_MESSAGE],
exceptionEvent.attributes![SEMATTRS_EXCEPTION_MESSAGE],
'I failed!'
);
});
Expand All @@ -591,10 +595,7 @@ describe('Koa Instrumentation', () => {
);

const requestHook = sinon.spy((span: Span, info: KoaRequestInfo) => {
span.setAttribute(
SemanticAttributes.HTTP_METHOD,
info.context.request.method
);
span.setAttribute(SEMATTRS_HTTP_METHOD, info.context.request.method);

throw Error('error thrown in requestHook');
});
Expand Down
11 changes: 11 additions & 0 deletions plugins/web/opentelemetry-instrumentation-document-load/README.md
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

0 comments on commit 65aabe7

Please sign in to comment.