-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds agent option to http transport (#439)
- Loading branch information
1 parent
0db501d
commit 98b3a68
Showing
5 changed files
with
56 additions
and
2 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 |
---|---|---|
@@ -1,14 +1,23 @@ | ||
import {Agent as HttpAgent} from 'http'; | ||
import {Agent as HttpsAgent} from 'https'; | ||
import {URL} from 'url'; | ||
|
||
import {JsonEncoder, Logger, model} from 'zipkin'; | ||
|
||
type Agent = HttpAgent | HttpsAgent; | ||
|
||
declare class HttpLogger implements Logger { | ||
constructor(options: { | ||
endpoint: string, | ||
httpInterval?: number, | ||
jsonEncoder?: JsonEncoder, | ||
httpTimeout?: number, | ||
timeout?: number, | ||
maxPayloadSize?: number, | ||
headers?: { [name: string]: any }, | ||
agent?: Agent | ((url: URL) => Agent), | ||
log?: Console | ||
}); | ||
|
||
logSpan(span: model.Span): void; | ||
} | ||
export {HttpLogger}; |
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
41 changes: 41 additions & 0 deletions
41
packages/zipkin-transport-http/test-types/HttpLogger.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,41 @@ | ||
import { expect } from 'chai'; | ||
|
||
import {Agent as HttpAgent } from 'http'; | ||
import {Agent as HttpsAgent} from 'https'; | ||
import {jsonEncoder} from 'zipkin'; | ||
|
||
import { HttpLogger } from 'zipkin-transport-http'; | ||
|
||
describe('HttpLogger', () => { | ||
it('should have correct type', () => { | ||
const options = { | ||
endpoint: 'testEndpoint', | ||
httpInterval: 1000, | ||
jsonEncoder: jsonEncoder.JSON_V1, | ||
timeout: 0, | ||
maxPayloadSize: 0, | ||
headers: {}, | ||
agent: new HttpAgent(), | ||
log: console | ||
}; | ||
const httpLogger: HttpLogger = new HttpLogger(options); | ||
|
||
expect(httpLogger.logSpan).to.be.a('function'); | ||
}); | ||
|
||
it('should accept Http(s) Agent or function which returns Agent', () => { | ||
const agents = [new HttpAgent(), new HttpsAgent(), () => new HttpAgent(), () => new HttpsAgent(), | ||
(url: URL) => new HttpAgent(), (url: URL) => new HttpsAgent(), null, undefined]; | ||
|
||
agents.forEach(agent => { | ||
const options = { | ||
endpoint: 'testEndpoint', | ||
agent | ||
}; | ||
|
||
const httpLogger: HttpLogger = new HttpLogger(options); | ||
|
||
expect(httpLogger).to.have.property('agent', agent || null); | ||
}); | ||
}); | ||
}); |