forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auto-instrumentations-node): Add "@opentelemetry/auto-instrument…
…ations-node/register" for an agent-like experience (open-telemetry#1400) * feat(auto-instrumentation-agent): added intrumentation-agent package * feat(auto-instrumentation-agent): added api peer dependency * feat(auto-instrumentation-agent): updated test * feat(auto-instrumentation-agent): updated release please config * feat(auto-instrumentation-agent): updated .release-please-manifest * feat(auto-instrumentation-agent): updated test timeout * feat(auto-instrumentation-agent): removed timeout, added pretest script * feat(auto-instrumentation-agent): moved agent to auto-instrumentations-node * feat(auto-instrumentation-agent): reverted release please config * feat(auto-instrumentation-agent): updated README.md * feat(auto-instrumentation-agent): added env variable for resource detector configuration * feat(auto-instrumentation-agent): removed no-process-exit * feat(auto-instrumentation-agent): removed pretest script * feat(auto-instrumentation-agent): fixed lint issues * feat(auto-instrumentation-agent): updated register test * feat(auto-instrumentation-agent): fixed typo in test * feat(auto-instrumentation-agent): using env instead of export * feat(auto-instrumentation-agent): updated eslint.config.js * feat(auto-instrumentation-agent): updated test * feat(auto-instrumentation-agent): using language specific env var name * feat(auto-instrumentation-agent): updated README.md * feat(auto-instrumentation-agent): updated dependencies * feat(auto-instrumentation-agent): fixed detector test * feat(auto-instrumentation-agent): added comment to test app * feat(auto-instrumentation-agent): small refactor * feat(auto-instrumentation-agent): updated log messages * feat(auto-instrumentation-agent): added missing aws detectors * feat(auto-instrumentation-agent): updated tests * feat(auto-instrumentation-agent): updated getResourceDetectorsFromEnv() * feat(auto-instrumentation-agent): revert unnecessary changes * feat(auto-instrumentation-agent): added reference to supported instrumentations * feat(auto-instrumentation-agent): added reference to env var spec * feat(auto-instrumentation-agent): added reference node documentation * feat(auto-instrumentation-agent): added note for unsupported config * feat(auto-instrumentation-agent): added note to the debug section * feat(auto-instrumentation-agent): moved opentelemetry/api to regular dependency * feat(auto-instrumentation-agent): fixed lint issue * feat(auto-instrumentation-agent): re-added peer dep * feat(auto-instrumentation-agent): re-added api dev dep * feat(auto-instrumentation-agent): fixed lint issue * feat(auto-instrumentation-agent): fixed lint issue * feat(auto-instrumentation-agent): updated README.md * feat(auto-instrumentation-agent): added exporters reference in README.md * feat(auto-instrumentation-agent): updated debug notes * feat(auto-instrumentation-agent): updated installation section to include the api dependency * feat(auto-instrumentation-agent): reordered aws resource detectors * feat(auto-instrumentation-agent): removed process.exit(0) * feat(auto-instrumentation-agent): reordered aws resource detectors * feat(auto-instrumentation-agent): replaced type any with actual types * feat(auto-instrumentation-agent): updated utils test * feat(auto-instrumentation-agent): updated register test * feat(auto-instrumentation-agent): updated README.md * feat(auto-instrumentation-agent): updated shutdown logs * feat(auto-instrumentation-agent): fixed sinon issue
- Loading branch information
1 parent
b5b951e
commit 2d8e2b8
Showing
7 changed files
with
343 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as opentelemetry from '@opentelemetry/sdk-node'; | ||
import { diag, DiagConsoleLogger } from '@opentelemetry/api'; | ||
import { | ||
getNodeAutoInstrumentations, | ||
getResourceDetectorsFromEnv, | ||
} from './utils'; | ||
|
||
diag.setLogger( | ||
new DiagConsoleLogger(), | ||
opentelemetry.core.getEnv().OTEL_LOG_LEVEL | ||
); | ||
|
||
const sdk = new opentelemetry.NodeSDK({ | ||
instrumentations: getNodeAutoInstrumentations(), | ||
resourceDetectors: getResourceDetectorsFromEnv(), | ||
}); | ||
|
||
try { | ||
sdk.start(); | ||
diag.info('OpenTelemetry automatic instrumentation started successfully'); | ||
} catch (error) { | ||
diag.error( | ||
'Error initializing OpenTelemetry SDK. Your application is not instrumented and will not produce telemetry', | ||
error | ||
); | ||
} | ||
|
||
process.on('SIGTERM', () => { | ||
sdk | ||
.shutdown() | ||
.then(() => diag.debug('OpenTelemetry SDK terminated')) | ||
.catch(error => diag.error('Error terminating OpenTelemetry SDK', error)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
metapackages/auto-instrumentations-node/test/register.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { promisify } from 'util'; | ||
import * as childProcess from 'child_process'; | ||
import * as assert from 'assert'; | ||
|
||
const exec = promisify(childProcess.exec); | ||
|
||
describe('Register', function () { | ||
this.timeout(5000); | ||
it('can load auto instrumentation from command line', async () => { | ||
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'none'; | ||
process.env.OTEL_TRACES_EXPORTER = 'console'; | ||
|
||
const { stdout } = await exec( | ||
'node --require ./build/src/register.js ./test/test-app/app.js' | ||
); | ||
|
||
assert.ok( | ||
stdout.includes( | ||
'OpenTelemetry automatic instrumentation started successfully' | ||
) | ||
); | ||
|
||
//Check a span has been generated for the GET request done in app.js | ||
assert.ok(stdout.includes("name: 'GET'")); | ||
|
||
delete process.env.OTEL_NODE_RESOURCE_DETECTORS; | ||
delete process.env.OTEL_TRACES_EXPORTER; | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
metapackages/auto-instrumentations-node/test/test-app/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
//Used in register.test.ts to mimic a JS app. | ||
const http = require('http'); | ||
|
||
const options = { | ||
hostname: 'example.com', | ||
port: 80, | ||
path: '/', | ||
method: 'GET' | ||
}; | ||
|
||
const req = http.request(options); | ||
|
||
req.end(); |
Oops, something went wrong.