Skip to content

Commit

Permalink
Merge branch 'main' into instrumentation-sequelize
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Sep 10, 2024
2 parents bbca381 + e87ff9d commit 8bfac99
Show file tree
Hide file tree
Showing 24 changed files with 343 additions and 1,424 deletions.
17 changes: 8 additions & 9 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
components:
detectors/node/opentelemetry-resource-detector-alibaba-cloud:
- legendecas
detectors/node/opentelemetry-resource-detector-aws:
- carolabadeer
detectors/node/opentelemetry-resource-detector-aws: []
# Unmaintained
detectors/node/opentelemetry-resource-detector-azure:
- jacksonweber
- hectorhdzg
Expand All @@ -16,8 +16,8 @@ components:
# Unmaintained
detectors/node/opentelemetry-resource-detector-instana:
- kirrg001
incubator/opentelemetry-sampler-aws-xray:
- carolabadeer
incubator/opentelemetry-sampler-aws-xray: []
# Unmaintained
metapackages/auto-configuration-propagators:
- pichlermarc
metapackages/auto-instrumentations-node:
Expand All @@ -35,8 +35,8 @@ components:
- jamiedanielson
packages/opentelemetry-host-metrics:
- legendecas
packages/opentelemetry-id-generator-aws-xray:
- carolabadeer
packages/opentelemetry-id-generator-aws-xray: []
# Unmaintained
packages/opentelemetry-propagation-utils:
- dyladan
- pichlermarc
Expand Down Expand Up @@ -69,10 +69,9 @@ components:
- mottibec
plugins/node/instrumentation-tedious: []
# Unmaintained
plugins/node/opentelemetry-instrumentation-aws-lambda:
- carolabadeer
plugins/node/opentelemetry-instrumentation-aws-lambda: []
# Unmaintained
plugins/node/opentelemetry-instrumentation-aws-sdk:
- carolabadeer
- blumamir
plugins/node/opentelemetry-instrumentation-bunyan:
- seemk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/close-stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ jobs:
close-pr-message: 'This issue was closed because no owner or sponsor has been found after 14 days'
stale-pr-label: pkg-status:unmaintained:autoclose-scheduled
only-labels: pkg-status:unmaintained
exempt-pr-labels: bug,has:sponsor,type:semconv-update,dependencies,autorelease:pending
exempt-pr-labels: 'bug,has:sponsor,type:semconv-update,dependencies,autorelease: pending'
remove-stale-when-updated: false
8 changes: 4 additions & 4 deletions detectors/node/opentelemetry-resource-detector-aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
[![NPM Published Version][npm-img]][npm-url]
[![Apache License][license-image]][license-image]

[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @carolabadeer
[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): N/A

Resource detector for Amazon Web Services.

## Status

| Maturity | [Component Owner](../../.github/component_owners.yml) | Compatibility |
| ----------------------------------------- | ----------------------------------------------------- | --------------------- |
| [Stable](../../../CONTRIBUTING.md#stable) | @carolabadeer | API 1.0+<br/>SDK 1.0+ |
| Maturity | [Component Owner](../../.github/component_owners.yml) | Compatibility |
|-------------------------------------------------------|-------------------------------------------------------|-----------------------|
| [Unmaintained](../../../CONTRIBUTING.md#unmaintained) | N/A | API 1.0+<br/>SDK 1.0+ |

## Installation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Detector, Resource, IResource } from '@opentelemetry/resources';
import {
DetectorSync,
Resource,
IResource,
ResourceAttributes,
} from '@opentelemetry/resources';
import { diag } from '@opentelemetry/api';
import {
SEMRESATTRS_PROCESS_PID,
SEMRESATTRS_SERVICE_INSTANCE_ID,
} from '@opentelemetry/semantic-conventions';
import * as http from 'http';

class InstanaAgentDetector implements Detector {
class InstanaAgentDetector implements DetectorSync {
readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost';
readonly INSTANA_AGENT_DEFAULT_PORT = 42699;

async detect(): Promise<IResource> {
detect(): IResource {
return new Resource({}, this._getAttributes());
}

private async _getAttributes(): Promise<ResourceAttributes> {
const host =
process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST;
const port = Number(
process.env.INSTANA_AGENT_PORT || this.INSTANA_AGENT_DEFAULT_PORT
);

const data = await this._retryHandler(host, port, 0);
try {
const data = await this._retryHandler(host, port, 0);

return new Resource({
[SEMRESATTRS_PROCESS_PID]: data.pid,
[SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid,
});
return {
[SEMRESATTRS_PROCESS_PID]: data.pid,
[SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid,
};
} catch {
return {};
}
}

private timeout(ms: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import * as nock from 'nock';
import * as assert from 'assert';
import { Resource } from '@opentelemetry/resources';
import { instanaAgentDetector } from '../src';

describe('[UNIT] instanaAgentDetector', () => {
Expand Down Expand Up @@ -54,7 +53,8 @@ describe('[UNIT] instanaAgentDetector', () => {
.put('/com.instana.plugin.nodejs.discovery')
.reply(200, () => mockedReply);

const resource: Resource = await instanaAgentDetector.detect();
const resource = instanaAgentDetector.detect();
await resource.waitForAsyncAttributes?.();

scope.done();

Expand All @@ -80,7 +80,8 @@ describe('[UNIT] instanaAgentDetector', () => {
.put('/com.instana.plugin.nodejs.discovery')
.reply(200, () => mockedReply);

const resource: Resource = await instanaAgentDetector.detect();
const resource = instanaAgentDetector.detect();
await resource.waitForAsyncAttributes?.();

scope.done();

Expand All @@ -90,28 +91,24 @@ describe('[UNIT] instanaAgentDetector', () => {
});
});

it('agent throws error', async () => {
const expectedError = new Error('Instana Agent returned status code 500');
it('agent returns empty resource if request error', async () => {
const scope = nock('http://localhost:42699')
.persist()
.put('/com.instana.plugin.nodejs.discovery')
.reply(500, () => new Error());

try {
await instanaAgentDetector.detect();
assert.ok(false, 'Expected to throw');
} catch (err) {
assert.deepStrictEqual(err, expectedError);
}
const resource = instanaAgentDetector.detect();
await resource.waitForAsyncAttributes?.();

assert.deepStrictEqual(resource.attributes, {});

scope.done();
});

it('agent timeout', async () => {
it('agent return empty resource if timeout', async () => {
process.env.INSTANA_AGENT_PORT = '56002';
process.env.INSTANA_AGENT_HOST = 'instanaagent';
process.env.INSTANA_AGENT_TIMEOUT_MS = '200';
const expectedError = new Error('Instana Agent request timed out.');

nock(
`http://${process.env.INSTANA_AGENT_HOST}:${process.env.INSTANA_AGENT_PORT}`
Expand All @@ -121,28 +118,23 @@ describe('[UNIT] instanaAgentDetector', () => {
.delay(500)
.reply(200, {});

try {
await instanaAgentDetector.detect();
assert.ok(false, 'Expected to throw');
} catch (err) {
console.log(err);
assert.deepStrictEqual(err, expectedError);
}
const resource = instanaAgentDetector.detect();
await resource.waitForAsyncAttributes?.();

assert.deepStrictEqual(resource.attributes, {});
});
});

describe('when agent is not running', () => {
it('should not return agent resource', async () => {
it('should return empty resource', async () => {
process.env.INSTANA_AGENT_PORT = '1111';
process.env.INSTANA_AGENT_TIMEOUT_MS = '100';
process.env.INSTANA_RETRY_TIMEOUT_MS = '100';

try {
await instanaAgentDetector.detect();
assert.ok(false, 'Expected to throw');
} catch (err: any) {
assert.equal(err.code, 'ECONNREFUSED');
}
const resource = instanaAgentDetector.detect();
await resource.waitForAsyncAttributes?.();

assert.deepStrictEqual(resource.attributes, {});
});
});
});
2 changes: 1 addition & 1 deletion incubator/opentelemetry-sampler-aws-xray/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> This component is still in development and has not been released as an npm package.
component owner: @carolabadeer
component owner: N/A

This module provides the remote/centralized sampler for AWS X-Ray.

Expand Down
2 changes: 1 addition & 1 deletion metapackages/auto-configuration-propagators/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PropagatorFactoryFunction = () => TextMapPropagator;

const propagatorMap = new Map<string, PropagatorFactoryFunction>([
['tracecontext', () => new W3CTraceContextPropagator()],
['baggage', () => new W3CTraceContextPropagator()],
['baggage', () => new W3CBaggagePropagator()],
[
'b3',
() => new B3Propagator({ injectEncoding: B3InjectEncoding.SINGLE_HEADER }),
Expand Down
2 changes: 1 addition & 1 deletion metapackages/auto-instrumentations-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"ts-loader": "9.5.1",
"ts-mocha": "10.0.0",
"typescript": "4.4.4",
"webpack": "5.89.0",
"webpack": "5.94.0",
"webpack-cli": "5.1.4",
"webpack-merge": "5.10.0"
},
Expand Down
Loading

0 comments on commit 8bfac99

Please sign in to comment.