-
Notifications
You must be signed in to change notification settings - Fork 395
fix: [OTLP] detect http/https protocol from parsedUrl.protocol #9028
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5ea87b7
detect http/https protocol from prasedUrl.protocol
ida613 4b10d55
privatize the attribute this.transport
ida613 e9d3ddf
fix ci failures
ida613 6d0218f
fall back on https
ida613 b0236ec
Update packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_ba…
ida613 b465d1f
added telemetry test cases
ida613 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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('assert') | ||
| const http = require('http') | ||
| const http = require('node:http') | ||
| const https = require('node:https') | ||
|
|
||
| const { describe, it, beforeEach, afterEach } = require('mocha') | ||
| const sinon = require('sinon') | ||
|
|
@@ -844,6 +845,18 @@ describe('OpenTelemetry Traces', () => { | |
| }) | ||
|
|
||
| describe('Telemetry Metrics', () => { | ||
| it('sets protocol:http tag for http:// endpoint', () => { | ||
| const exporter = new OtlpHttpTraceExporter('http://collector.example/v1/traces', {}, 1000, {}) | ||
|
|
||
| assert.ok(exporter.telemetryTags.includes('protocol:http')) | ||
|
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. Nit: calling setUrl here with https afterwards would be great. Everything would be tested in that case :) Because that was the last functionality that was missing with my earlier comment |
||
| }) | ||
|
|
||
| it('sets protocol:https tag for https:// endpoint', () => { | ||
| const exporter = new OtlpHttpTraceExporter('https://collector.example/v1/traces', {}, 1000, {}) | ||
|
|
||
| assert.ok(exporter.telemetryTags.includes('protocol:https')) | ||
| }) | ||
|
|
||
| it('tracks telemetry metrics for exported traces', () => { | ||
| const telemetryMetrics = { | ||
| manager: { namespace: sinon.stub().returns({ count: sinon.stub().returns({ inc: sinon.spy() }) }) }, | ||
|
|
@@ -887,5 +900,39 @@ describe('OpenTelemetry Traces', () => { | |
|
|
||
| assert.strictEqual(exporter.options.path, '/v1/traces?token=abc') | ||
| }) | ||
|
|
||
| it('selects http transport for http:// URLs', () => { | ||
| const exporter = new OtlpHttpTraceExporter('http://collector.example/v1/traces', {}, 1000, {}) | ||
| const mockReq = { write: () => {}, end: () => {}, on: () => mockReq, once: () => mockReq } | ||
| const httpStub = sinon.stub(http, 'request').returns(mockReq) | ||
| sinon.stub(https, 'request').returns(mockReq) | ||
|
|
||
| exporter.sendPayload(Buffer.from('{}'), () => {}) | ||
|
|
||
| assert.ok(httpStub.calledOnce, 'http.request should have been called') | ||
| }) | ||
|
|
||
| it('selects https transport for https:// URLs', () => { | ||
| const exporter = new OtlpHttpTraceExporter('https://collector.example/v1/traces', {}, 1000, {}) | ||
| const mockReq = { write: () => {}, end: () => {}, on: () => mockReq, once: () => mockReq } | ||
| sinon.stub(http, 'request').returns(mockReq) | ||
| const httpsStub = sinon.stub(https, 'request').returns(mockReq) | ||
|
|
||
| exporter.sendPayload(Buffer.from('{}'), () => {}) | ||
|
|
||
| assert.ok(httpsStub.calledOnce, 'https.request should have been called') | ||
| }) | ||
|
|
||
| it('switches transport when setUrl is called with a different scheme', () => { | ||
| const exporter = new OtlpHttpTraceExporter('http://collector.example/v1/traces', {}, 1000, {}) | ||
| const mockReq = { write: () => {}, end: () => {}, on: () => mockReq, once: () => mockReq } | ||
| sinon.stub(http, 'request').returns(mockReq) | ||
| const httpsStub = sinon.stub(https, 'request').returns(mockReq) | ||
|
|
||
| exporter.setUrl('https://secure-collector.example/v1/traces') | ||
| exporter.sendPayload(Buffer.from('{}'), () => {}) | ||
|
|
||
| assert.ok(httpsStub.calledOnce, 'https.request should have been called after switching to https') | ||
| }) | ||
| }) | ||
| }) | ||
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.