-
Notifications
You must be signed in to change notification settings - Fork 407
fix(agentless): use proxy for otlp export #10176
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
Merged
+107
−0
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
100 changes: 100 additions & 0 deletions
100
packages/dd-trace/test/opentelemetry/otlp/otlp_http_exporter_base.spec.js
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('node:assert/strict') | ||
| const { describe, it, afterEach, beforeEach } = require('mocha') | ||
|
|
||
| require('../../setup/core') | ||
|
|
||
| const OtlpHttpExporterBase = require('../../../src/opentelemetry/otlp/otlp_http_exporter_base') | ||
| const { version: tracerVersion } = require('../../../../../package.json') | ||
|
|
||
| const proxyEnvironmentNames = [ | ||
| 'ALL_PROXY', | ||
| 'HTTPS_PROXY', | ||
| 'HTTP_PROXY', | ||
| 'NO_PROXY', | ||
| 'all_proxy', | ||
| 'https_proxy', | ||
| 'http_proxy', | ||
| 'no_proxy', | ||
| ] | ||
|
|
||
| describe('OtlpHttpExporterBase', () => { | ||
| let originalEnvironment | ||
|
|
||
| beforeEach(() => { | ||
| originalEnvironment = new Map() | ||
| for (const name of proxyEnvironmentNames) { | ||
| originalEnvironment.set(name, process.env[name]) | ||
| delete process.env[name] | ||
| } | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| for (const [name, value] of originalEnvironment) { | ||
| if (value === undefined) { | ||
| delete process.env[name] | ||
| } else { | ||
| process.env[name] = value | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| it('sends a User-Agent header identifying the tracer version', () => { | ||
| const exporter = new OtlpHttpExporterBase('https://intake.example/path', undefined, 1000, 'http/protobuf', 'traces') | ||
|
|
||
| assert.strictEqual(exporter.options.headers['User-Agent'], `dd-trace-js/${tracerVersion}`) | ||
| }) | ||
|
|
||
| it('does not set an agent for an HTTPS endpoint when no proxy is configured', () => { | ||
| const exporter = new OtlpHttpExporterBase('https://intake.example/path', undefined, 1000, 'http/protobuf', 'traces') | ||
|
|
||
| assert.strictEqual(exporter.options.agent, undefined) | ||
| }) | ||
|
|
||
| it('does not set an agent for an HTTP endpoint even when a proxy is configured', () => { | ||
| process.env.https_proxy = 'http://127.0.0.1:9999' | ||
|
|
||
| const exporter = new OtlpHttpExporterBase('http://intake.example/path', undefined, 1000, 'http/protobuf', 'traces') | ||
|
|
||
| assert.strictEqual(exporter.options.agent, undefined) | ||
| }) | ||
|
|
||
| it('routes an HTTPS endpoint through the configured proxy agent', () => { | ||
| process.env.https_proxy = 'http://127.0.0.1:9999' | ||
|
|
||
| const exporter = new OtlpHttpExporterBase('https://intake.example/path', undefined, 1000, 'http/protobuf', 'traces') | ||
|
|
||
| assert.ok(exporter.options.agent) | ||
| assert.strictEqual(exporter.options.agent.proxy.hostname, '127.0.0.1') | ||
| assert.strictEqual(exporter.options.agent.proxy.port, '9999') | ||
| }) | ||
|
|
||
| describe('setUrl', () => { | ||
| it('picks up a proxy agent when re-targeted to an HTTPS endpoint', () => { | ||
| const exporter = new OtlpHttpExporterBase( | ||
| 'http://intake.example/path', undefined, 1000, 'http/protobuf', 'traces' | ||
| ) | ||
| assert.strictEqual(exporter.options.agent, undefined) | ||
|
|
||
| process.env.https_proxy = 'http://127.0.0.1:9999' | ||
| exporter.setUrl('https://intake.example/other-path') | ||
|
|
||
| assert.ok(exporter.options.agent) | ||
| assert.strictEqual(exporter.options.agent.proxy.hostname, '127.0.0.1') | ||
| assert.strictEqual(exporter.options.agent.proxy.port, '9999') | ||
| }) | ||
|
|
||
| it('clears the agent when re-targeted from HTTPS to HTTP', () => { | ||
| process.env.https_proxy = 'http://127.0.0.1:9999' | ||
| const exporter = new OtlpHttpExporterBase( | ||
| 'https://intake.example/path', undefined, 1000, 'http/protobuf', 'traces' | ||
| ) | ||
| assert.ok(exporter.options.agent) | ||
|
|
||
| exporter.setUrl('http://intake.example/other-path') | ||
|
|
||
| assert.strictEqual(exporter.options.agent, undefined) | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.