-
Notifications
You must be signed in to change notification settings - Fork 144
Ignore OTLP Export Env Var for Logs and Traces in AKS Auto-Attach Scenarios #1465
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
Closed
+130
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,4 +60,111 @@ describe("agent/AKSLoader", () => { | |||||||
| let loggerProvider = logs.getLoggerProvider() as any; | ||||||||
| assert.equal(loggerProvider.constructor.name, "LoggerProvider"); | ||||||||
| }); | ||||||||
|
|
||||||||
| describe("OTEL environment variable handling", () => { | ||||||||
| it("should remove OTEL_TRACES_EXPORTER and OTEL_LOGS_EXPORTER during initialization", () => { | ||||||||
| const env = { | ||||||||
| ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333", | ||||||||
| ["OTEL_TRACES_EXPORTER"]: "jaeger", | ||||||||
| ["OTEL_LOGS_EXPORTER"]: "console" | ||||||||
| }; | ||||||||
| process.env = env; | ||||||||
|
|
||||||||
| const agent = new AKSLoader(); | ||||||||
|
|
||||||||
| // Spy on the parent initialize method to check environment during call | ||||||||
| let envDuringParentCall: { traces?: string; logs?: string } = {}; | ||||||||
| const originalInitialize = Object.getPrototypeOf(Object.getPrototypeOf(agent)).initialize; | ||||||||
| const parentInitializeSpy = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').callsFake(function() { | ||||||||
| envDuringParentCall.traces = process.env.OTEL_TRACES_EXPORTER; | ||||||||
| envDuringParentCall.logs = process.env.OTEL_LOGS_EXPORTER; | ||||||||
| return originalInitialize.call(this); | ||||||||
| }); | ||||||||
|
|
||||||||
| agent.initialize(); | ||||||||
|
|
||||||||
| // Verify that environment variables were undefined during parent initialize call | ||||||||
| assert.strictEqual(envDuringParentCall.traces, undefined, "OTEL_TRACES_EXPORTER should be undefined during parent initialize"); | ||||||||
| assert.strictEqual(envDuringParentCall.logs, undefined, "OTEL_LOGS_EXPORTER should be undefined during parent initialize"); | ||||||||
|
|
||||||||
| // Verify parent initialize was called | ||||||||
| assert.ok(parentInitializeSpy.calledOnce, "Parent initialize should be called once"); | ||||||||
|
|
||||||||
| parentInitializeSpy.restore(); | ||||||||
| }); | ||||||||
|
|
||||||||
| it("should restore OTEL_TRACES_EXPORTER and OTEL_LOGS_EXPORTER after initialization", () => { | ||||||||
| const env = { | ||||||||
| ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333", | ||||||||
| ["OTEL_TRACES_EXPORTER"]: "jaeger", | ||||||||
| ["OTEL_LOGS_EXPORTER"]: "console" | ||||||||
| }; | ||||||||
| process.env = env; | ||||||||
|
|
||||||||
| const agent = new AKSLoader(); | ||||||||
| agent.initialize(); | ||||||||
|
|
||||||||
| // Verify environment variables are restored after initialization | ||||||||
| assert.strictEqual(process.env.OTEL_TRACES_EXPORTER, "jaeger", "OTEL_TRACES_EXPORTER should be restored"); | ||||||||
| assert.strictEqual(process.env.OTEL_LOGS_EXPORTER, "console", "OTEL_LOGS_EXPORTER should be restored"); | ||||||||
| }); | ||||||||
|
|
||||||||
| it("should handle cases where OTEL environment variables are not set", () => { | ||||||||
| const env = { | ||||||||
| ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333" | ||||||||
| // OTEL variables intentionally not set | ||||||||
| }; | ||||||||
| process.env = env; | ||||||||
|
|
||||||||
| const agent = new AKSLoader(); | ||||||||
| agent.initialize(); | ||||||||
|
|
||||||||
| // Verify that undefined variables remain undefined | ||||||||
| assert.strictEqual(process.env.OTEL_TRACES_EXPORTER, undefined, "OTEL_TRACES_EXPORTER should remain undefined"); | ||||||||
| assert.strictEqual(process.env.OTEL_LOGS_EXPORTER, undefined, "OTEL_LOGS_EXPORTER should remain undefined"); | ||||||||
| }); | ||||||||
|
|
||||||||
| it("should restore environment variables even if parent initialize throws", () => { | ||||||||
| const env = { | ||||||||
| ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333", | ||||||||
| ["OTEL_TRACES_EXPORTER"]: "jaeger", | ||||||||
| ["OTEL_LOGS_EXPORTER"]: "console" | ||||||||
| }; | ||||||||
| process.env = env; | ||||||||
|
|
||||||||
| const agent = new AKSLoader(); | ||||||||
|
|
||||||||
| // Stub parent initialize to throw an error | ||||||||
| const parentInitializeStub = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').throws(new Error("Test error")); | ||||||||
|
||||||||
| const parentInitializeStub = sandbox.stub(Object.getPrototypeOf(Object.getPrototypeOf(agent)), 'initialize').throws(new Error("Test error")); | |
| const parentPrototype = Object.getPrototypeOf(Object.getPrototypeOf(agent)); | |
| const parentInitializeStub = sandbox.stub(parentPrototype, 'initialize').throws(new Error("Test error")); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double
Object.getPrototypeOf()calls are difficult to read and maintain. Consider storing the parent class in a variable or using a more explicit approach to access the grandparent's initialize method.