-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(opentelemetry-sdk-node): skeleton for experimental function to start SDK #6145
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
Changes from 7 commits
75c2aab
7f7defb
e3b3b57
182726d
05daae0
ce92b4f
20290e0
6e6a656
e8d8809
8bac153
679766e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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 { | ||
| ConfigFactory, | ||
| createConfigFactory, | ||
| } from '@opentelemetry/configuration'; | ||
| import { SDKOptions } from './types'; | ||
| import { diag, DiagConsoleLogger } from '@opentelemetry/api'; | ||
| import { setupContextManager } from './utils'; | ||
|
|
||
| /** | ||
| * Experimental function to start the OpenTelemetry Node SDK | ||
| * @param sdkOptions | ||
|
maryliag marked this conversation as resolved.
|
||
| */ | ||
| export const startNodeSDK = (sdkOptions: Partial<SDKOptions> = {}) => { | ||
|
maryliag marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should make the return type explicit, something that also makes clear that shutdown is always
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not exported through
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, there is a reason... I forgot 😎 |
||
| const configFactory: ConfigFactory = createConfigFactory(); | ||
| const config = configFactory.getConfigModel(); | ||
|
|
||
| if (config.disabled) { | ||
| diag.info('OpenTelemetry SDK is disabled'); | ||
| return NOOP_SDK; | ||
| } | ||
| if (config.log_level != null) { | ||
| diag.setLogger(new DiagConsoleLogger(), { logLevel: config.log_level }); | ||
| } | ||
|
|
||
| setupContextManager(sdkOptions?.contextManager); | ||
|
|
||
| const shutdownFn = async () => { | ||
| const promises: Promise<unknown>[] = []; | ||
| await Promise.all(promises); | ||
| }; | ||
| return { shutdown: shutdownFn }; | ||
| }; | ||
|
|
||
| const NOOP_SDK = { | ||
| shutdown: () => {}, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,7 @@ export interface NodeSDKConfiguration { | |
| spanLimits: SpanLimits; | ||
| idGenerator: IdGenerator; | ||
| } | ||
|
|
||
| export interface SDKOptions { | ||
| contextManager: ContextManager | null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my experience, people add things based on what they see is already there. So a Since the only option for Node.js is really the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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 assert from 'assert'; | ||
| import { startNodeSDK } from '../src/start'; | ||
| import { context, diag } from '@opentelemetry/api'; | ||
| import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks'; | ||
| import * as Sinon from 'sinon'; | ||
|
|
||
| describe('startNodeSDK', () => { | ||
|
maryliag marked this conversation as resolved.
Outdated
|
||
| const _origEnvVariables = { ...process.env }; | ||
|
|
||
| afterEach(function () { | ||
| for (const key of Object.keys(process.env)) { | ||
| delete process.env[key]; | ||
| } | ||
| for (const [key, value] of Object.entries(_origEnvVariables)) { | ||
| process.env[key] = value; | ||
| } | ||
| Sinon.restore(); | ||
| }); | ||
|
|
||
| it('should return NOOP_SDK when disabled is true', () => { | ||
| const info = Sinon.spy(diag, 'info'); | ||
| process.env.OTEL_SDK_DISABLED = 'true'; | ||
| const sdk = startNodeSDK({}); | ||
|
|
||
| Sinon.assert.calledWith(info, 'OpenTelemetry SDK is disabled'); | ||
|
|
||
| sdk.shutdown(); | ||
| }); | ||
|
|
||
| it('should return NOOP_SDK when disabled is true', () => { | ||
| process.env.OTEL_EXPERIMENTAL_CONFIG_FILE = | ||
| 'test/fixtures/kitchen-sink.yaml'; | ||
| const sdk = startNodeSDK({}); | ||
|
|
||
| assertDefaultContextManagerRegistered(); | ||
|
|
||
| sdk.shutdown(); | ||
| }); | ||
| }); | ||
|
|
||
| function assertDefaultContextManagerRegistered() { | ||
| assert.ok( | ||
| context['_getContextManager']().constructor.name === | ||
| AsyncLocalStorageContextManager.name | ||
| ); | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.