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 29, 2024
2 parents 9f81a2d + 3ad9fdf commit 769de9e
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 129 deletions.
1 change: 1 addition & 0 deletions metapackages/auto-instrumentations-node/README.md
Expand Up @@ -65,6 +65,7 @@ By default, all SDK resource detectors are used, but you can use the environment
- `container`
- `alibaba`
- `aws`
- `azure`
- `gcp`
- `all` - enable all resource detectors
- `none` - disable resource detection
Expand Down
1 change: 1 addition & 0 deletions metapackages/auto-instrumentations-node/package.json
Expand Up @@ -89,6 +89,7 @@
"@opentelemetry/instrumentation-winston": "^0.37.0",
"@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9",
"@opentelemetry/resource-detector-aws": "^1.4.2",
"@opentelemetry/resource-detector-azure": "^0.2.6",
"@opentelemetry/resource-detector-container": "^0.3.9",
"@opentelemetry/resource-detector-gcp": "^0.29.9",
"@opentelemetry/resources": "^1.12.0",
Expand Down
12 changes: 11 additions & 1 deletion metapackages/auto-instrumentations-node/src/utils.ts
Expand Up @@ -73,6 +73,11 @@ import {
osDetectorSync,
processDetectorSync,
} from '@opentelemetry/resources';
import {
azureAppServiceDetector,
azureFunctionsDetector,
azureVmDetector,
} from '@opentelemetry/resource-detector-azure';

const RESOURCE_DETECTOR_CONTAINER = 'container';
const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
Expand All @@ -81,6 +86,7 @@ const RESOURCE_DETECTOR_OS = 'os';
const RESOURCE_DETECTOR_PROCESS = 'process';
const RESOURCE_DETECTOR_ALIBABA = 'alibaba';
const RESOURCE_DETECTOR_AWS = 'aws';
const RESOURCE_DETECTOR_AZURE = 'azure';
const RESOURCE_DETECTOR_GCP = 'gcp';

const InstrumentationMap = {
Expand Down Expand Up @@ -196,7 +202,7 @@ function getEnabledInstrumentationsFromEnv() {
export function getResourceDetectorsFromEnv(): Array<Detector | DetectorSync> {
const resourceDetectors = new Map<
string,
Detector | DetectorSync | Detector[]
Detector | DetectorSync | Detector[] | DetectorSync[]
>([
[RESOURCE_DETECTOR_CONTAINER, containerDetector],
[RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync],
Expand All @@ -215,6 +221,10 @@ export function getResourceDetectorsFromEnv(): Array<Detector | DetectorSync> {
awsLambdaDetector,
],
],
[
RESOURCE_DETECTOR_AZURE,
[azureAppServiceDetector, azureFunctionsDetector, azureVmDetector],
],
]);

const resourceDetectorsFromEnv =
Expand Down
4 changes: 2 additions & 2 deletions metapackages/auto-instrumentations-node/test/utils.test.ts
Expand Up @@ -114,13 +114,13 @@ describe('utils', () => {

describe('getResourceDetectorsFromEnv', () => {
it('should return all resource detectors by default', () => {
assert.equal(getResourceDetectorsFromEnv().length, 12);
assert.equal(getResourceDetectorsFromEnv().length, 15);
});

it('should return all resource detectors when OTEL_NODE_RESOURCE_DETECTORS contains "all"', () => {
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'all';

assert.equal(getResourceDetectorsFromEnv().length, 12);
assert.equal(getResourceDetectorsFromEnv().length, 15);

delete process.env.OTEL_NODE_RESOURCE_DETECTORS;
});
Expand Down
30 changes: 16 additions & 14 deletions package-lock.json

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

13 changes: 13 additions & 0 deletions plugins/node/instrumentation-cucumber/README.md
Expand Up @@ -43,6 +43,19 @@ Cucumber instrumentation has currently no options.
| Options | Type | Description |
| ------- | ---- | ----------- |

## 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 |
| ---------------- | -------------------------------------------------------------------------------- |
| `code.filepath` | The source code file name that identifies the code unit as uniquely as possible. |
| `code.function` | The method or function name, or equivalent. |
| `code.lineno` | The line number in `code.filepath` best representing the operation. |
| `code.namespace` | The "namespace" within which `code.function` is defined. |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-cucumber/package.json
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.51.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/node/instrumentation-cucumber#readme"
}
15 changes: 10 additions & 5 deletions plugins/node/instrumentation-cucumber/src/instrumentation.ts
Expand Up @@ -21,7 +21,12 @@ import {
InstrumentationNodeModuleFile,
isWrapped,
} from '@opentelemetry/instrumentation';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_CODE_FILEPATH,
SEMATTRS_CODE_FUNCTION,
SEMATTRS_CODE_LINENO,
SEMATTRS_CODE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';

import type * as cucumber from '@cucumber/cucumber';
import type * as messages from '@cucumber/messages';
Expand Down Expand Up @@ -174,10 +179,10 @@ export class CucumberInstrumentation extends InstrumentationBase {
{
kind: SpanKind.CLIENT,
attributes: {
[SemanticAttributes.CODE_FILEPATH]: gherkinDocument.uri,
[SemanticAttributes.CODE_LINENO]: scenario.location.line,
[SemanticAttributes.CODE_FUNCTION]: scenario.name,
[SemanticAttributes.CODE_NAMESPACE]: feature.name,
[SEMATTRS_CODE_FILEPATH]: gherkinDocument.uri,
[SEMATTRS_CODE_LINENO]: scenario.location.line,
[SEMATTRS_CODE_FUNCTION]: scenario.name,
[SEMATTRS_CODE_NAMESPACE]: feature.name,
[AttributeNames.FEATURE_TAGS]: CucumberInstrumentation.mapTags(
feature.tags
),
Expand Down
19 changes: 12 additions & 7 deletions plugins/node/instrumentation-cucumber/test/cucumber.test.ts
Expand Up @@ -21,9 +21,14 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_CODE_FILEPATH,
SEMATTRS_CODE_FUNCTION,
SEMATTRS_CODE_LINENO,
SEMATTRS_CODE_NAMESPACE,
SEMRESATTRS_SERVICE_NAME,
} from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

import * as path from 'path';
import * as assert from 'assert';
Expand All @@ -50,7 +55,7 @@ import { PassThrough } from 'stream';
describe('CucumberInstrumentation', () => {
const provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'CucumberInstrumentation',
[SEMRESATTRS_SERVICE_NAME]: 'CucumberInstrumentation',
}),
});
const memoryExporter = new InMemorySpanExporter();
Expand Down Expand Up @@ -165,10 +170,10 @@ describe('CucumberInstrumentation', () => {
assert(parent, 'Expected a parent span');

assert.deepEqual(parent.attributes, {
[SemanticAttributes.CODE_FILEPATH]: 'test/current.feature',
[SemanticAttributes.CODE_LINENO]: 7,
[SemanticAttributes.CODE_FUNCTION]: 'Button pushing',
[SemanticAttributes.CODE_NAMESPACE]: 'Basic',
[SEMATTRS_CODE_FILEPATH]: 'test/current.feature',
[SEMATTRS_CODE_LINENO]: 7,
[SEMATTRS_CODE_FUNCTION]: 'Button pushing',
[SEMATTRS_CODE_NAMESPACE]: 'Basic',
[AttributeNames.FEATURE_DESCRIPTION]:
' A very basic feature file with a single scenario',
[AttributeNames.FEATURE_LANGUAGE]: 'en',
Expand Down
13 changes: 13 additions & 0 deletions plugins/node/instrumentation-socket.io/README.md
Expand Up @@ -59,6 +59,19 @@ Few breaking changes were made during porting to the contrib repo:
The instrumentation's config `filterHttpTransport` option was removed to decouple this instrumentation from the http instrumentation.
if you do not want to trace the socket.io http requests, add the default socket.io route (`/socket.io/`) to the `HttpInstrumentationConfig.ignoreIncomingPaths` array

## 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 |
| ---------------------------- | ------------------------------------------------------------------------------------------------ |
| `messaging.destination` | The message destination name. This might be equal to the span name but is required nevertheless. |
| `messaging.destination_kind` | The kind of message destination. |
| `messaging.operation` | A string identifying the kind of message consumption. |
| `messaging.system` | A string identifying the messaging system. |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-socket.io/package.json
Expand Up @@ -59,7 +59,7 @@
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.51.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/node/instrumentation-socket.io#readme"
}
27 changes: 15 additions & 12 deletions plugins/node/instrumentation-socket.io/src/socket.io.ts
Expand Up @@ -28,9 +28,12 @@ import {
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import {
SemanticAttributes,
MessagingOperationValues,
MessagingDestinationKindValues,
SEMATTRS_MESSAGING_DESTINATION,
SEMATTRS_MESSAGING_DESTINATION_KIND,
SEMATTRS_MESSAGING_OPERATION,
SEMATTRS_MESSAGING_SYSTEM,
MESSAGINGOPERATIONVALUES_RECEIVE,
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
} from '@opentelemetry/semantic-conventions';
import { SocketIoInstrumentationConfig } from './types';
import { SocketIoInstrumentationAttributes } from './AttributeNames';
Expand Down Expand Up @@ -302,14 +305,14 @@ export class SocketIoInstrumentation extends InstrumentationBase {
? eventName
: `${namespace} ${eventName}`;
const span: Span = self.tracer.startSpan(
`${destination} ${MessagingOperationValues.RECEIVE}`,
`${destination} ${MESSAGINGOPERATIONVALUES_RECEIVE}`,
{
kind: SpanKind.CONSUMER,
attributes: {
[SemanticAttributes.MESSAGING_SYSTEM]: 'socket.io',
[SemanticAttributes.MESSAGING_DESTINATION]: namespace,
[SemanticAttributes.MESSAGING_OPERATION]:
MessagingOperationValues.RECEIVE,
[SEMATTRS_MESSAGING_SYSTEM]: 'socket.io',
[SEMATTRS_MESSAGING_DESTINATION]: namespace,
[SEMATTRS_MESSAGING_OPERATION]:
MESSAGINGOPERATIONVALUES_RECEIVE,
[SocketIoInstrumentationAttributes.SOCKET_IO_EVENT_NAME]:
eventName,
},
Expand Down Expand Up @@ -379,9 +382,9 @@ export class SocketIoInstrumentation extends InstrumentationBase {
const messagingSystem = 'socket.io';
const eventName = ev;
const attributes: any = {
[SemanticAttributes.MESSAGING_SYSTEM]: messagingSystem,
[SemanticAttributes.MESSAGING_DESTINATION_KIND]:
MessagingDestinationKindValues.TOPIC,
[SEMATTRS_MESSAGING_SYSTEM]: messagingSystem,
[SEMATTRS_MESSAGING_DESTINATION_KIND]:
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
[SocketIoInstrumentationAttributes.SOCKET_IO_EVENT_NAME]: eventName,
};

Expand All @@ -394,7 +397,7 @@ export class SocketIoInstrumentation extends InstrumentationBase {
if (namespace) {
attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE] =
namespace;
attributes[SemanticAttributes.MESSAGING_DESTINATION] = namespace;
attributes[SEMATTRS_MESSAGING_DESTINATION] = namespace;
}
const spanRooms = rooms.length ? `[${rooms.join()}]` : '';
const span = self.tracer.startSpan(`${namespace}${spanRooms} send`, {
Expand Down

0 comments on commit 769de9e

Please sign in to comment.